| Index: tools/polymer/generate_compiled_resources_gn.py
 | 
| diff --git a/tools/polymer/generate_compiled_resources_gn.py b/tools/polymer/generate_compiled_resources_gn.py
 | 
| new file mode 100755
 | 
| index 0000000000000000000000000000000000000000..7a3e4d646d93905d08793d1b9b265617633f5262
 | 
| --- /dev/null
 | 
| +++ b/tools/polymer/generate_compiled_resources_gn.py
 | 
| @@ -0,0 +1,93 @@
 | 
| +#!/usr/bin/env python
 | 
| +# Copyright 2016 The Chromium Authors. All rights reserved.
 | 
| +# Use of this source code is governed by a BSD-style license that can be
 | 
| +# found in the LICENSE file.
 | 
| +
 | 
| +from bs4 import BeautifulSoup
 | 
| +from datetime import date
 | 
| +import os.path as path
 | 
| +from subprocess import call
 | 
| +import sys
 | 
| +
 | 
| +
 | 
| +_SRC = path.join(path.dirname(path.abspath(__file__)), '..', '..')
 | 
| +_COMPILE_JS = path.join(
 | 
| +    _SRC, 'third_party', 'closure_compiler', 'compile_js2.gypi')
 | 
| +_POLYMERS = ['polymer%s.html' % p for p in '', '-mini', '-micro']
 | 
| +_WEB_ANIMATIONS_BASE = 'web-animations.html'
 | 
| +_WEB_ANIMATIONS_TARGET = 'web_animations.js'
 | 
| +_COMPILED_RESOURCES_TEMPLATE = '''
 | 
| +# Copyright %d The Chromium Authors. All rights reserved.
 | 
| +# Use of this source code is governed by a BSD-style license that can be
 | 
| +# found in the LICENSE file.
 | 
| +#
 | 
| +# NOTE: Created with %s, please do not edit.
 | 
| +
 | 
| +import("//third_party/closure_compiler/compile_js2.gni")
 | 
| +
 | 
| +%s
 | 
| +
 | 
| +'''.strip()
 | 
| +
 | 
| +
 | 
| +def main(created_by, html_files):
 | 
| +  targets = ''
 | 
| +
 | 
| +  def _target_name(target_file):
 | 
| +    assert target_file.endswith('.html')
 | 
| +    return path.basename(target_file)[:-len('.html')] + '-extracted'
 | 
| +
 | 
| +  for html_file in sorted(html_files, key=_target_name):
 | 
| +    html_base = path.basename(html_file)
 | 
| +    if html_base in _POLYMERS:
 | 
| +      continue
 | 
| +
 | 
| +    parsed = BeautifulSoup(open(html_file), 'html.parser')
 | 
| +    imports = set(i.get('href') for i in parsed.find_all('link', rel='import'))
 | 
| +
 | 
| +    html_dir = path.dirname(html_file)
 | 
| +    dependencies = []
 | 
| +    externs = []
 | 
| +
 | 
| +    for html_import in sorted(imports):
 | 
| +      import_dir, import_base = path.split(html_import.encode('ascii'))
 | 
| +      if import_base in _POLYMERS:
 | 
| +        continue
 | 
| +
 | 
| +      if import_base == _WEB_ANIMATIONS_BASE:
 | 
| +        externs.append(_WEB_ANIMATIONS_TARGET)
 | 
| +        continue
 | 
| +
 | 
| +      target = _target_name(import_base)
 | 
| +      if not path.isfile(path.join(html_dir, import_dir, target + '.js')):
 | 
| +        continue
 | 
| +
 | 
| +      target = ':compile_' + target
 | 
| +
 | 
| +      dependencies.append(import_dir + target)
 | 
| +
 | 
| +    targets += '\ncompile_js("compile_%s-extracted") {' % html_base[:-5]
 | 
| +    targets += '\nsource_files = ["%s-extracted.js"]' % html_base[:-5]
 | 
| +    if dependencies:
 | 
| +      targets += "\ndeps = ["
 | 
| +      targets += '\n        "%s",' % '",\n        "'.join(dependencies)
 | 
| +      targets += '\n      ]'
 | 
| +    if externs:
 | 
| +      targets += "\nexterns = ["
 | 
| +      targets += '\n        "%s",' % '",\n        "'.join(externs)
 | 
| +      targets += '\n      ]'
 | 
| +    targets += "\n}"
 | 
| +      
 | 
| +
 | 
| +  targets = targets.strip()
 | 
| +
 | 
| +  if targets:
 | 
| +    current_year = date.today().year
 | 
| +    build_gn_path = path.join(html_dir, 'BUILD.gn')
 | 
| +    print build_gn_path
 | 
| +    with open(build_gn_path, 'w') as build_gn:
 | 
| +      build_gn.write(_COMPILED_RESOURCES_TEMPLATE % (current_year, created_by, targets))
 | 
| +    call(['gn', 'format', build_gn_path])
 | 
| +
 | 
| +if __name__ == '__main__':
 | 
| +  main(path.basename(sys.argv[0]), sys.argv[1:])
 | 
| 
 |