1# Copyright (c) 2014 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 5import sys 6import os 7import re 8 9from tvcm import project as project_module 10 11 12def _FindAllFilesRecursive(source_paths): 13 assert isinstance(source_paths, list) 14 all_filenames = set() 15 for source_path in source_paths: 16 for dirpath, _, filenames in os.walk(source_path): 17 for f in filenames: 18 if f.startswith('.'): 19 continue 20 x = os.path.abspath(os.path.join(dirpath, f)) 21 all_filenames.add(x) 22 return all_filenames 23 24def _IsFilenameATest(loader, x): # pylint: disable=unused-argument 25 if x.endswith('_test.js'): 26 return True 27 28 if x.endswith('_test.html'): 29 return True 30 31 if x.endswith('_unittest.js'): 32 return True 33 34 if x.endswith('_unittest.html'): 35 return True 36 37 # TODO(nduca): Add content test? 38 return False 39 40 41class TracingProject(project_module.Project): 42 tracing_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) 43 tracing_root_path = os.path.abspath(os.path.join(tracing_path, 'tracing')) 44 tracing_src_path = os.path.abspath(os.path.join(tracing_root_path, 'tracing')) 45 extras_path = os.path.join(tracing_src_path, 'extras') 46 47 tracing_third_party_path = os.path.abspath(os.path.join( 48 tracing_root_path, 'third_party')) 49 50 jszip_path = os.path.abspath(os.path.join(tracing_third_party_path, 'jszip')) 51 52 glmatrix_path = os.path.abspath(os.path.join( 53 tracing_third_party_path, 'gl-matrix', 'dist')) 54 55 ui_path = os.path.abspath(os.path.join(tracing_src_path, 'ui')) 56 d3_path = os.path.abspath(os.path.join(tracing_third_party_path, 'd3')) 57 chai_path = os.path.abspath(os.path.join(tracing_third_party_path, 'chai')) 58 mocha_path = os.path.abspath(os.path.join(tracing_third_party_path, 'mocha')) 59 parse5_path = os.path.abspath(os.path.join( 60 tracing_third_party_path, 'vinn', 'third_party', 'parse5')) 61 62 test_data_path = os.path.join(tracing_root_path, 'test_data') 63 skp_data_path = os.path.join(tracing_root_path, 'skp_data') 64 65 rjsmin_path = os.path.abspath(os.path.join( 66 tracing_third_party_path, 'tvcm', 'third_party', 'rjsmin')) 67 rcssmin_path = os.path.abspath(os.path.join( 68 tracing_third_party_path, 'tvcm', 'third_party', 'rcssmin')) 69 70 def __init__(self, *args, **kwargs): 71 super(TracingProject, self).__init__(*args, **kwargs) 72 self.source_paths.append(self.tracing_src_path) 73 self.source_paths.append(self.tracing_root_path) 74 self.source_paths.append(self.tracing_third_party_path) 75 self.source_paths.append(self.jszip_path) 76 self.source_paths.append(self.glmatrix_path) 77 self.source_paths.append(self.d3_path) 78 self.source_paths.append(self.chai_path) 79 self.source_paths.append(self.mocha_path) 80 81 82 def IsD8CompatibleFile(self, filename): 83 return not filename.startswith(self.ui_path) 84 85 def FindAllTestModuleResources(self): 86 all_filenames = _FindAllFilesRecursive([self.tracing_src_path]) 87 test_module_filenames = [x for x in all_filenames if 88 _IsFilenameATest(self.loader, x)] 89 test_module_filenames.sort() 90 91 # Find the equivalent resources. 92 return [self.loader.FindResourceGivenAbsolutePath(x) 93 for x in test_module_filenames] 94 95 def FindAllD8TestModuleResources(self): 96 all_test_module_resources = self.FindAllTestModuleResources() 97 return [x for x in all_test_module_resources 98 if self.IsD8CompatibleFile(x.absolute_path)] 99 100 def GetConfigNames(self): 101 config_files = [ 102 os.path.join(self.extras_path, x) for x in os.listdir(self.extras_path) 103 if x.endswith('_config.html') 104 ] 105 106 config_files = [x for x in config_files if os.path.isfile(x)] 107 108 config_basenames = [os.path.basename(x) for x in config_files] 109 config_names = [re.match('(.+)_config.html$', x).group(1) 110 for x in config_basenames] 111 return config_names 112 113 def GetDefaultConfigName(self): 114 assert 'full' in self.GetConfigNames() 115 return 'full' 116 117 def AddConfigNameOptionToParser(self, parser): 118 choices = self.GetConfigNames() 119 parser.add_option( 120 '--config', dest='config_name', 121 type='choice', choices=choices, 122 default=self.GetDefaultConfigName(), 123 help='Picks a browser config. Valid choices: %s' % ', '.join(choices)) 124 return choices 125 126 def GetModuleNameForConfigName(self, config_name): 127 return 'extras.%s_config' % config_name 128 129 @classmethod 130 def IsIgnoredFile(cls, affected_file): 131 if affected_file.LocalPath().endswith('.png'): 132 return True 133 134 if affected_file.LocalPath().endswith('.svg'): 135 return True 136 137 if affected_file.LocalPath().endswith('.skp'): 138 return True 139 140 if (affected_file.LocalPath().endswith('.gypi') or 141 affected_file.LocalPath().endswith('.gyp') or 142 affected_file.LocalPath().endswith('.gn')): 143 return True 144 145 if TracingProject.IsThirdParty(affected_file): 146 return True 147 148 # Is test data? 149 if affected_file.AbsoluteLocalPath().startswith(cls.test_data_path): 150 return True 151 152 if (affected_file.LocalPath().startswith('.gitignore') or 153 affected_file.LocalPath().startswith('codereview.settings') or 154 affected_file.LocalPath().startswith('tracing/.allow-devtools-save') or 155 affected_file.LocalPath().startswith('tracing/AUTHORS') or 156 affected_file.LocalPath().startswith('tracing/LICENSE') or 157 affected_file.LocalPath().startswith('tracing/OWNERS') or 158 affected_file.LocalPath().startswith('tracing/bower.json') or 159 affected_file.LocalPath().startswith('tracing/.gitignore') or 160 affected_file.LocalPath().startswith('tracing/.bowerrc') or 161 affected_file.LocalPath().startswith('tracing/README.md') or 162 affected_file.LocalPath().startswith( 163 'tracing/examples/string_convert.js')): 164 return True 165 166 return False 167 168 @staticmethod 169 def IsThirdParty(affected_file): 170 return affected_file.LocalPath().startswith('tracing/third_party') 171