1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 import os 6 7 import tracing_project 8 9 10 FILE_GROUPS = ["tracing_css_files", 11 "tracing_js_html_files", 12 "tracing_img_files"] 13 14 15 def GetFileGroupFromFileName(filename): 16 extension = os.path.splitext(filename)[1] 17 return { 18 '.css': 'tracing_css_files', 19 '.html': 'tracing_js_html_files', 20 '.js': 'tracing_js_html_files', 21 '.png': 'tracing_img_files' 22 }[extension] 23 24 25 def CheckListedFilesSorted(src_file, group_name, listed_files): 26 sorted_files = sorted(listed_files) 27 if sorted_files != listed_files: 28 mismatch = '' 29 for i in range(len(listed_files)): 30 if listed_files[i] != sorted_files[i]: 31 mismatch = listed_files[i] 32 break 33 what_is = ' ' + '\n '.join(listed_files) 34 what_should_be = ' ' + '\n '.join(sorted_files) 35 return '''In group {0} from file {1}, filenames aren't sorted. 36 37 First mismatch: 38 {2} 39 40 Current listing: 41 {3} 42 43 Correct listing: 44 {4}\n\n'''.format(group_name, src_file, mismatch, what_is, what_should_be) 45 else: 46 return '' 47 48 49 def GetKnownFiles(): 50 project = tracing_project.TracingProject() 51 52 vulcanizer = project.CreateVulcanizer() 53 m = vulcanizer.loader.LoadModule( 54 module_name='tracing.ui.extras.about_tracing.about_tracing') 55 absolute_filenames = m.GetAllDependentFilenamesRecursive( 56 include_raw_scripts=False) 57 58 return list(set([os.path.relpath(f, project.tracing_root_path) 59 for f in absolute_filenames])) 60 61 62 def CheckCommon(file_name, listed_files): 63 known_files = GetKnownFiles() 64 u = set(listed_files).union(set(known_files)) 65 i = set(listed_files).intersection(set(known_files)) 66 diff = list(u - i) 67 68 if len(diff) == 0: 69 return '' 70 71 error = 'Entries in ' + file_name + ' do not match files on disk:\n' 72 in_file_only = list(set(listed_files) - set(known_files)) 73 in_known_only = list(set(known_files) - set(listed_files)) 74 75 if len(in_file_only) > 0: 76 error += ' In file only:\n ' + '\n '.join(sorted(in_file_only)) 77 if len(in_known_only) > 0: 78 if len(in_file_only) > 0: 79 error += '\n\n' 80 error += ' On disk only:\n ' + '\n '.join(sorted(in_known_only)) 81 82 if in_file_only: 83 error += ( 84 '\n\n' 85 ' Note: only files actually used in about:tracing should\n' 86 ' be listed in the build files. Try running \n' 87 ' tracing/bin/update_gyp_and_gn\n' 88 ' to update the files automatically.') 89 90 return error 91