| OLD | NEW | 
 | (Empty) | 
|    1 #!/usr/bin/env python |  | 
|    2 # Copyright 2016 The Chromium Authors. All rights reserved. |  | 
|    3 # Use of this source code is governed by a BSD-style license that can be |  | 
|    4 # found in the LICENSE file. |  | 
|    5  |  | 
|    6 """Creates an .isolate given a list of files. |  | 
|    7  |  | 
|    8 """ |  | 
|    9  |  | 
|   10 import argparse |  | 
|   11 import os |  | 
|   12 import pprint |  | 
|   13 import re |  | 
|   14 import sys |  | 
|   15  |  | 
|   16  |  | 
|   17 _UNIVERSAL_BLACKLIST = ( |  | 
|   18     r'.*OWNERS',  # Should never be included. |  | 
|   19 ) |  | 
|   20  |  | 
|   21 _ANDROID_BLACKLIST = ( |  | 
|   22     r'.*\.crx',  # Chrome extension zip files. |  | 
|   23     r'.*external_extensions\.json',  # Chrome external extensions config file. |  | 
|   24     r'.*\.so',  # Libraries packed into .apk. |  | 
|   25     r'.*\.mojom\.js',  # Some test_support targets include python deps. |  | 
|   26     r'.*Mojo.*manifest\.json',  # Some source_set()s pull these in. |  | 
|   27     r'.*jni_generator_tests',  # Exists just to test the compile, not to be run. |  | 
|   28 ) |  | 
|   29  |  | 
|   30 _DEVICE_BLACKLIST = ( |  | 
|   31     r'.*\.py',  # Some test_support targets include python deps. |  | 
|   32 ) |  | 
|   33  |  | 
|   34 _ASSERT_WHITELIST = ( |  | 
|   35     r'.*\.pak', |  | 
|   36     r'.*/',  # Assume directories are always included on purpose. |  | 
|   37 ) |  | 
|   38  |  | 
|   39  |  | 
|   40 def _IsExecutable(path): |  | 
|   41   return os.path.isfile(path) and os.access(path, os.X_OK) |  | 
|   42  |  | 
|   43  |  | 
|   44 def _MatchesAny(path, patterns): |  | 
|   45   return any(re.match(p, path) for p in patterns) |  | 
|   46  |  | 
|   47  |  | 
|   48 def main(): |  | 
|   49   parser = argparse.ArgumentParser(description=__doc__) |  | 
|   50   parser.add_argument('--command', |  | 
|   51                       help='The command to put in the .isolate (optional)') |  | 
|   52   parser.add_argument('--runtime-deps-file', required=True, |  | 
|   53                       help='Input .runtime_deps file.') |  | 
|   54   parser.add_argument('--output-directory', required=True, |  | 
|   55                       help='Location of the ninja output directory') |  | 
|   56   parser.add_argument('--out-file', help='Write to file rather than stdout.') |  | 
|   57   parser.add_argument('--apply-android-filters', action='store_true', |  | 
|   58                       help='Filter files not required for Android.') |  | 
|   59   parser.add_argument('--apply-device-filters', action='store_true', |  | 
|   60                       help='Filter files not required in *.device.isolate.') |  | 
|   61   parser.add_argument('--assert-no-odd-data', action='store_true', |  | 
|   62                       help='Fail if any data deps exist (after filtering) ' |  | 
|   63                            'that are not a part of the _ASSERT_WHITELIST. Use ' |  | 
|   64                            'this to prevent unexpected runtime_deps from ' |  | 
|   65                            'creeping in') |  | 
|   66   options = parser.parse_args() |  | 
|   67  |  | 
|   68   deps = [] |  | 
|   69   with open(options.runtime_deps_file) as deps_file: |  | 
|   70     for path in deps_file: |  | 
|   71       if path.startswith('./'): |  | 
|   72         path = path[2:] |  | 
|   73       deps.append(path.rstrip()) |  | 
|   74  |  | 
|   75   deps = (d for d in deps if not _MatchesAny(d, _UNIVERSAL_BLACKLIST)) |  | 
|   76  |  | 
|   77   if options.apply_android_filters: |  | 
|   78     deps = (d for d in deps if not _MatchesAny(d, _ANDROID_BLACKLIST)) |  | 
|   79  |  | 
|   80   if options.apply_device_filters: |  | 
|   81     deps = (d for d in deps if not _MatchesAny(d, _DEVICE_BLACKLIST)) |  | 
|   82     # Breakpad tests have a helper exe, which is packaged in the _dist. |  | 
|   83     deps = (d for d in deps if not _IsExecutable(d)) |  | 
|   84  |  | 
|   85   # Make them relative to out-file. |  | 
|   86   if options.out_file: |  | 
|   87     subdir = os.path.relpath(options.output_directory, |  | 
|   88                              os.path.dirname(options.out_file)) |  | 
|   89     deps = (os.path.join(subdir, d) for d in deps) |  | 
|   90  |  | 
|   91   deps = sorted(deps) |  | 
|   92  |  | 
|   93   if options.assert_no_odd_data: |  | 
|   94     odd_files = [d for d in deps if not _MatchesAny(d, _ASSERT_WHITELIST)] |  | 
|   95     assert not odd_files, ('Found possibly undesired file in runtime_deps: %s' % |  | 
|   96                            odd_files) |  | 
|   97  |  | 
|   98   isolate_dict = { |  | 
|   99       'variables': { |  | 
|  100           'files': deps, |  | 
|  101       } |  | 
|  102   } |  | 
|  103   if options.command: |  | 
|  104     isolate_dict['variables']['command'] = [options.command] |  | 
|  105  |  | 
|  106   isolate_data = pprint.pformat(isolate_dict) |  | 
|  107   if options.out_file: |  | 
|  108     with open(options.out_file, 'w') as f: |  | 
|  109       f.write(isolate_data + '\n') |  | 
|  110   else: |  | 
|  111     print isolate_data |  | 
|  112  |  | 
|  113  |  | 
|  114 if __name__ == '__main__': |  | 
|  115   sys.exit(main()) |  | 
|  116  |  | 
| OLD | NEW |