Skip to content

Commit

Permalink
Sync for validator/cpp/engine (ampproject#33777)
Browse files Browse the repository at this point in the history
* Implementation of multiple tagspecs for a single extension, each with a unique set of version identifiers.

The motivation for this is that Bento AMP components will be using a new version 1.0. With this, we have the opportunity to move forward requirements that these newer version components are actually used in the document, a requirement we have allowed older components to ignore for legacy reasons.

`ExtensionSpec`s are expanded during setup to fill in several fields in the `TagSpec`. One of these is the unique `TagSpec.spec_name` identifier. Multiple extension `TagSpec`s with the same extension name (ie: amp-analytics v1.0 and v0.1) collide on unique `spec_name`.

This change extending the logic for the `ExtensionSpec` -> `TagSpec `generation to include a new field `version_name` which is an optional string that gets added into the `spec_name` and `descriptive_name` for the extension `TagSpec`.

PiperOrigin-RevId: 366894452

* Revert changes from `main` to `master`

Co-authored-by: Greg Grothaus <[email protected]>
  • Loading branch information
2 people authored and rochapablo committed Aug 30, 2021
1 parent d0fe0c1 commit f7cac69
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions validator/cpp/engine/validator-internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4797,8 +4797,12 @@ void ParsedValidatorRules::ExpandExtensionSpec(ValidatorRules* rules) const {
TagSpec* tagspec = rules->mutable_tags(ii);
if (!tagspec->has_extension_spec()) continue;
const ExtensionSpec& extension_spec = tagspec->extension_spec();
std::string base_spec_name = extension_spec.name();
if (extension_spec.has_version_name())
base_spec_name =
StrCat(extension_spec.name(), " ", extension_spec.version_name());
if (!tagspec->has_spec_name())
tagspec->set_spec_name(extension_spec.name() + " extension script");
tagspec->set_spec_name(StrCat(base_spec_name, " extension script"));
if (!tagspec->has_descriptive_name())
tagspec->set_descriptive_name(tagspec->spec_name());
tagspec->set_mandatory_parent("HEAD");
Expand Down Expand Up @@ -4826,13 +4830,11 @@ void ParsedValidatorRules::ExpandExtensionSpec(ValidatorRules* rules) const {

// Expand module script tagspec.
TagSpec module_tagspec = basic_tagspec;
ExpandModuleExtensionSpec(&module_tagspec,
tagspec->extension_spec().name());
ExpandModuleExtensionSpec(&module_tagspec, base_spec_name);
new_tagspecs.push_back(module_tagspec);
// Expand nomodule script tagspec.
TagSpec nomodule_tagspec = basic_tagspec;
ExpandNomoduleExtensionSpec(&nomodule_tagspec,
tagspec->extension_spec().name());
ExpandNomoduleExtensionSpec(&nomodule_tagspec, base_spec_name);
new_tagspecs.push_back(nomodule_tagspec);
}
}
Expand Down

0 comments on commit f7cac69

Please sign in to comment.