# Copyright 2014 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. import os import re from py_vulcanize import js_utils from py_vulcanize import module from py_vulcanize import parse_html_deps from py_vulcanize import style_sheet def IsHTMLResourceTheModuleGivenConflictingResourceNames( js_resource, html_resource): # pylint: disable=unused-argument return 'polymer-element' in html_resource.contents class HTMLModule(module.Module): @property def _module_dir_name(self): return os.path.dirname(self.resource.absolute_path) def Parse(self, excluded_scripts): try: parser_results = parse_html_deps.HTMLModuleParser().Parse(self.contents) except Exception as ex: raise Exception('While parsing %s: %s' % (self.name, str(ex))) self.dependency_metadata = Parse(self.loader, self.name, self._module_dir_name, self.IsThirdPartyComponent(), parser_results, excluded_scripts) self._parser_results = parser_results self.scripts = parser_results.scripts def Load(self, excluded_scripts): super(HTMLModule, self).Load(excluded_scripts=excluded_scripts) reachable_names = set([m.name for m in self.all_dependent_modules_recursive]) if 'tr.exportTo' in self.contents: if 'tracing.base.base' not in reachable_names: raise Exception('%s: Does not have a dependency on base' % os.path.relpath(self.resource.absolute_path)) for script in self.scripts: if script.is_external: if excluded_scripts and any(re.match(pattern, script.src) for pattern in excluded_scripts): continue resource = _HRefToResource(self.loader, self.name, self._module_dir_name, script.src, tag_for_err_msg='