diff --git a/bin/amphtml-update.py b/bin/amphtml-update.py index 192e03bdab8..7278f958004 100755 --- a/bin/amphtml-update.py +++ b/bin/amphtml-update.py @@ -359,7 +359,7 @@ def ParseRules(repo_directory, out_dir): 'amp-wordpress-embed': ['1.0'], } - bento_spec_names = [] + bento_spec_names = {} for (field_desc, field_val) in rules.ListFields(): if 'tags' == field_desc.name: @@ -392,8 +392,10 @@ def ParseRules(repo_directory, out_dir): if gotten_tag_spec is not None: if 'extension_spec' in gotten_tag_spec['tag_spec'] and 'bento_supported_version' in gotten_tag_spec['tag_spec']['extension_spec']: if '' != tag_spec.spec_name: - bento_spec_names.append( gotten_tag_spec['tag_spec']['extension_spec']['name'] ) + # In case some other extension requires bento extension, we need to know the spec name of the bento extension. + bento_spec_names[ gotten_tag_spec['tag_spec']['extension_spec']['name'] ] = tag_spec.spec_name + # Remove bento spec version from the list of versions. version = gotten_tag_spec['tag_spec']['extension_spec']['version'] bento_version = gotten_tag_spec['tag_spec']['extension_spec']['bento_supported_version'] @@ -433,15 +435,14 @@ def ParseRules(repo_directory, out_dir): # Remove any tags that requires bento_spec_names.keys() for tag_name, tag_list in allowed_tags.items(): for tag in tag_list: - if 'requires_extension' not in tag['tag_spec'] or 'spec_name' not in tag['tag_spec']: + if 'requires_extension' not in tag['tag_spec'] or 'requires_condition' not in tag['tag_spec']: continue - + requires_condition = tag['tag_spec']['requires_condition'][0] requires_extension = tag['tag_spec']['requires_extension'][0] - if requires_extension not in bento_spec_names: continue - - tag_list.remove( tag ) + if bento_spec_names[requires_extension] == requires_condition: + tag_list.remove( tag ) # Separate extension scripts from non-extension scripts and gather the versions extension_scripts = collections.defaultdict(list) @@ -485,6 +486,7 @@ def ParseRules(repo_directory, out_dir): for tag_name, tags in allowed_tags.items(): for tag in tags: tag['tag_spec'].pop('satisfies_condition', None) # We don't need it anymore. + tag['tag_spec'].pop('requires_condition', None) # We don't need it anymore. requires = tag['tag_spec'].pop('requires', []) if 'requires_extension' not in tag['tag_spec']: @@ -729,6 +731,11 @@ def GetTagRules(tag_spec): for requires_extension in tag_spec.requires_extension: requires_extension_list.add(requires_extension) + requires_condition_list = set() + if hasattr(tag_spec, 'requires_condition') and len( tag_spec.requires_condition ) != 0: + for requires_condition in tag_spec.requires_condition: + requires_condition_list.add(requires_condition) + if hasattr(tag_spec, 'requires') and len( tag_spec.requires ) != 0: tag_rules['requires'] = [ requires for requires in tag_spec.requires ] @@ -742,6 +749,9 @@ def GetTagRules(tag_spec): if len( requires_extension_list ) > 0: tag_rules['requires_extension'] = list( requires_extension_list ) + if len( requires_condition_list ) > 0: + tag_rules['requires_condition'] = list( requires_condition_list ) + if hasattr(tag_spec, 'reference_points') and len( tag_spec.reference_points ) != 0: tag_reference_points = {} for reference_point_spec in tag_spec.reference_points: