Skip to content

Commit 61b5845

Browse files
Googlerbanaag
authored andcommitted
Migrate from cfg = "host" to cfg = "exec"
PiperOrigin-RevId: 488423550
1 parent 795d3c3 commit 61b5845

31 files changed

+90
-134
lines changed

validator/cpp/engine/embed_data.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ embed_data = rule(
3939
),
4040
"header_generator": attr.label(
4141
executable = True,
42-
cfg = "host",
42+
cfg = "exec",
4343
allow_files = True,
4444
default = Label(
4545
"//cpp/engine/scripts:filecontents_to_cpp_header",

validator/cpp/engine/parse-layout-sizes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace amp::validator::parse_layout_sizes {
99

1010
// WARNING: This code is still in development and not ready to be used.
1111

12-
// This is a single representation for the CssSizes object.
12+
// This is a single represenation for the CssSizes object.
1313
// It consists of at least a valid size and a possible media condition.
1414
// See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#Attributes
1515
struct CssSize {

validator/cpp/engine/parse-srcset_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ TEST(ParseSrcsetTest, LeadingAndTrailingCommasAndCommasInUrl) {
150150
EqCandidates({{"example.com/,/,/,/,50w", "1x"}}));
151151
}
152152

153-
TEST(ParseSrcsetTest, NoWhitespace) {
153+
TEST(ParseSrcsetTest, NoWhitepsace) {
154154
SrcsetParsingResult result = ParseSourceSet("image 100w,image 50w");
155155
EXPECT_TRUE(result.success);
156156
EXPECT_THAT(result.srcset_images,

validator/cpp/engine/testing-utils.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ const std::map<std::string, TestCase>& TestCases() {
9797
"external/amphtml-extensions/*/*/test/*.html",
9898
&html_files)) << "Test cases file pattern not found.";
9999

100-
CHECK(!html_files.empty()) << "Validator test cases are empty. Will not proceed.";
101-
102100
std::sort(html_files.begin(), html_files.end());
103101
for (const std::string& html_file : html_files) {
104102
if (html_file.find("/js_only/") != std::string::npos) continue;

validator/cpp/engine/utf8-util_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ TEST(Utf8UtilTest, Utf16StrLen) {
1414
// It's 34 bytes long and 22 utf-8 characters long. Javascript uses UTF16
1515
// strings and string lengths.
1616
// The chars in Iñtërnâtiônàlizætiøn vary between 1 and 2 byte lengths, all
17-
// javascript 1-char lengths. The ⚡ is a 3-byte length character, with a
17+
// javascript 1-char lenghts. The ⚡ is a 3-byte length character, with a
1818
// 1-char javascript length. Finally the 💩 is a 4-byte length character with
1919
// a 2-char javascript length.
2020
EXPECT_EQ(Utf16StrLen("Iñtërnâtiônàlizætiøn☃💩"), 23);

validator/cpp/engine/validator-internal.cc

Lines changed: 41 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -311,62 +311,42 @@ ScriptTag ParseScriptTag(htmlparser::Node* node) {
311311
}
312312
}
313313

314-
if (src.empty()) {
315-
return script_tag;
316-
}
317-
318-
std::string src_str{src};
319314
// Determine if this has a valid AMP domain and separate the path from the
320315
// attribute 'src'. Consumes the domain making src just the path.
321316
if (absl::ConsumePrefix(&src, kAmpProjectDomain)) {
322317
script_tag.is_amp_domain = true;
323-
script_tag.path = src_str;
324-
} else {
325-
script_tag.is_amp_domain = false;
326-
htmlparser::URL url(src_str);
327-
// Error cases, early exit:
328-
if (!url.is_valid()) return script_tag;
329-
if (!url.has_protocol()) return script_tag;
330-
if (url.protocol() != "https" && url.protocol() != "http")
331-
return script_tag;
332-
if (url.hostname().empty()) return script_tag;
333-
334-
src = url.path_params_fragment().data();
335-
// Trim the "/" prefix as this is what kExtensionPathRe expects.
336-
if (!src.empty() && src[0] == '/') src = src.substr(1);
337-
std::string src_str{src};
338-
script_tag.path = src_str;
339-
}
340-
341-
// Only look at script tags that have attribute 'async'.
342-
if (has_async_attr) {
343-
// Determine if this is the AMP Runtime.
344-
if (!script_tag.is_extension &&
345-
RE2::FullMatch(src, *kRuntimeScriptPathRe)) {
346-
script_tag.is_runtime = true;
347-
script_tag.has_valid_path = true;
348-
}
349-
350-
// For AMP Extensions, validate path and extract name and version.
351-
if (script_tag.is_extension &&
352-
RE2::FullMatch(src, *kExtensionPathRe, &script_tag.extension_name,
353-
&script_tag.extension_version)) {
354-
script_tag.has_valid_path = true;
355-
}
356-
357-
// Determine the release version (LTS, module, standard, etc).
358-
if ((has_module_attr && RE2::FullMatch(src, *kModuleLtsScriptPathRe)) ||
359-
(has_nomodule_attr && RE2::FullMatch(src, *kLtsScriptPathRe))) {
360-
script_tag.release_version = ScriptReleaseVersion::MODULE_NOMODULE_LTS;
361-
} else if ((has_module_attr &&
362-
RE2::FullMatch(src, *kModuleScriptPathRe)) ||
363-
(has_nomodule_attr &&
364-
RE2::FullMatch(src, *kStandardScriptPathRe))) {
365-
script_tag.release_version = ScriptReleaseVersion::MODULE_NOMODULE;
366-
} else if (RE2::FullMatch(src, *kLtsScriptPathRe)) {
367-
script_tag.release_version = ScriptReleaseVersion::LTS;
368-
} else if (RE2::FullMatch(src, *kStandardScriptPathRe)) {
369-
script_tag.release_version = ScriptReleaseVersion::STANDARD;
318+
script_tag.path = std::string(src);
319+
320+
// Only look at script tags that have attribute 'async'.
321+
if (has_async_attr) {
322+
// Determine if this is the AMP Runtime.
323+
if (!script_tag.is_extension &&
324+
RE2::FullMatch(src, *kRuntimeScriptPathRe)) {
325+
script_tag.is_runtime = true;
326+
script_tag.has_valid_path = true;
327+
}
328+
329+
// For AMP Extensions, validate path and extract name and version.
330+
if (script_tag.is_extension &&
331+
RE2::FullMatch(src, *kExtensionPathRe, &script_tag.extension_name,
332+
&script_tag.extension_version)) {
333+
script_tag.has_valid_path = true;
334+
}
335+
336+
// Determine the release version (LTS, module, standard, etc).
337+
if ((has_module_attr && RE2::FullMatch(src, *kModuleLtsScriptPathRe)) ||
338+
(has_nomodule_attr && RE2::FullMatch(src, *kLtsScriptPathRe))) {
339+
script_tag.release_version = ScriptReleaseVersion::MODULE_NOMODULE_LTS;
340+
} else if ((has_module_attr &&
341+
RE2::FullMatch(src, *kModuleScriptPathRe)) ||
342+
(has_nomodule_attr &&
343+
RE2::FullMatch(src, *kStandardScriptPathRe))) {
344+
script_tag.release_version = ScriptReleaseVersion::MODULE_NOMODULE;
345+
} else if (RE2::FullMatch(src, *kLtsScriptPathRe)) {
346+
script_tag.release_version = ScriptReleaseVersion::LTS;
347+
} else if (RE2::FullMatch(src, *kStandardScriptPathRe)) {
348+
script_tag.release_version = ScriptReleaseVersion::STANDARD;
349+
}
370350
}
371351
}
372352
return script_tag;
@@ -1192,7 +1172,7 @@ class ParsedTagSpec {
11921172

11931173
// Whether or not the tag should be recorded via
11941174
// Context->RecordTagspecValidated if it was validated
1195-
// successfully. For performance, this is only done for tags that
1175+
// successfullly. For performance, this is only done for tags that
11961176
// are mandatory, unique, or possibly required by some other tag.
11971177
RecordValidated ShouldRecordTagspecValidated() const {
11981178
return should_record_tagspec_validated_;
@@ -1284,7 +1264,7 @@ std::string TagSpecUrl(const TagSpec& spec) {
12841264
return StrCat(extension_spec_url_prefix, spec.extension_spec().name());
12851265
if (spec.requires_extension_size() > 0)
12861266
// Return the first |requires_extension|, which should be the most
1287-
// representative.
1267+
// representitive.
12881268
return StrCat(extension_spec_url_prefix, spec.requires_extension(0));
12891269

12901270
return "";
@@ -2834,11 +2814,11 @@ class InvalidRuleVisitor : public htmlparser::css::RuleVisitor {
28342814
class InvalidDeclVisitor : public htmlparser::css::RuleVisitor {
28352815
public:
28362816
InvalidDeclVisitor(const ParsedDocCssSpec& css_spec, Context* context,
2837-
const std::string& tag_descriptive_name,
2817+
const std::string& tag_decriptive_name,
28382818
ValidationResult* result)
28392819
: css_spec_(css_spec),
28402820
context_(context),
2841-
tag_descriptive_name_(tag_descriptive_name),
2821+
tag_descriptive_name_(tag_decriptive_name),
28422822
result_(result) {}
28432823

28442824
void VisitDeclaration(
@@ -3996,14 +3976,8 @@ void ValidateAmpScriptSrcAttr(const ParsedHtmlTag& tag,
39963976
const TagSpec& tag_spec, const Context& context,
39973977
ValidationResult* result) {
39983978
if (!tag.IsAmpDomain()) {
3999-
bool is_amp_format =
4000-
c_find(context.type_identifiers(), TypeIdentifier::kAmp) !=
4001-
context.type_identifiers().end();
4002-
if (!is_amp_format || context.is_transformed()) {
4003-
context.AddError(ValidationError::DISALLOWED_AMP_DOMAIN,
4004-
context.line_col(),
4005-
/*params=*/{}, /*spec_url=*/"", result);
4006-
}
3979+
context.AddError(ValidationError::DISALLOWED_AMP_DOMAIN, context.line_col(),
3980+
/*params=*/{}, /*spec_url=*/"", result);
40073981
}
40083982

40093983
if (tag.IsExtensionScript() && tag_spec.has_extension_spec()) {
@@ -5686,7 +5660,9 @@ class ParsedValidatorRulesProvider {
56865660
class Validator {
56875661
public:
56885662
Validator(const ParsedValidatorRules* rules, int max_errors = -1)
5689-
: rules_(rules), max_errors_(max_errors), context_(rules_, max_errors_) {}
5663+
: rules_(rules),
5664+
max_errors_(max_errors),
5665+
context_(rules_, max_errors_) {}
56905666

56915667
ValidationResult Validate(const htmlparser::Document& doc) {
56925668
doc_metadata_ = doc.Metadata();

validator/cpp/engine/validator_test.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,8 @@ TEST(ValidatorTest, TestCssLengthAmpEmail) {
481481
":13:2 The author stylesheet specified in tag 'style amp-custom' "
482482
"is too long - document contains 75001 bytes whereas the "
483483
"limit is 75000 "
484-
"bytes. (see https://amp.dev/documentation/guides-and-tutorials/email/learn/"
485-
"spec/amphtml#maximum-size)");
484+
"bytes. (see https://amp.dev/documentation/guides-and-tutorials/learn/"
485+
"spec/amphtml/#maximum-size)");
486486
EXPECT_EQ(expected_output, output) << "test case " << test_case_name;
487487
}
488488

@@ -527,7 +527,7 @@ TEST(ValidatorTest, TestCssLengthAmpEmail) {
527527
":19:6 The author stylesheet specified in tag 'style amp-custom' "
528528
"and the combined inline styles is too large - document contains 75010 "
529529
"bytes whereas the limit is 75000 bytes. (see https://amp.dev/"
530-
"documentation/guides-and-tutorials/email/learn/spec/amphtml#maximum-size)");
530+
"documentation/guides-and-tutorials/learn/spec/amphtml/#maximum-size)");
531531
EXPECT_EQ(expected_output, output) << "test case " << test_case_name;
532532
}
533533

@@ -555,7 +555,7 @@ TEST(ValidatorTest, TestCssLengthAmpEmail) {
555555
":7519:6 The author stylesheet specified in tag 'style amp-custom' "
556556
"and the combined inline styles is too large - document contains 75014 "
557557
"bytes whereas the limit is 75000 bytes. (see https://amp.dev/"
558-
"documentation/guides-and-tutorials/email/learn/spec/amphtml#maximum-size)");
558+
"documentation/guides-and-tutorials/learn/spec/amphtml/#maximum-size)");
559559
EXPECT_EQ(expected_output, output) << "test case " << test_case_name;
560560
}
561561

@@ -601,8 +601,8 @@ TEST(ValidatorTest, TestCssLengthAmpEmail) {
601601
test_case_name,
602602
":17:2 The inline style specified in tag 'div' is too long - it "
603603
"contains 1001 bytes whereas the limit is 1000 bytes. (see "
604-
"https://amp.dev/documentation/guides-and-tutorials/email/learn/spec/"
605-
"amphtml#maximum-size)");
604+
"https://amp.dev/documentation/guides-and-tutorials/learn/spec/"
605+
"amphtml/#maximum-size)");
606606
EXPECT_EQ(expected_output, output) << "test case " << test_case_name;
607607
}
608608
}
@@ -649,8 +649,8 @@ TEST(ValidatorTest, TestCssLengthAmpEmailStrict) {
649649
":13:2 The author stylesheet specified in tag 'style amp-custom' "
650650
"is too long - document contains 75001 bytes whereas the "
651651
"limit is 75000 "
652-
"bytes. (see https://amp.dev/documentation/guides-and-tutorials/email/learn/"
653-
"spec/amphtml#maximum-size)");
652+
"bytes. (see https://amp.dev/documentation/guides-and-tutorials/learn/"
653+
"spec/amphtml/#maximum-size)");
654654
EXPECT_EQ(expected_output, output) << "test case " << test_case_name;
655655
}
656656

@@ -681,7 +681,7 @@ TEST(ValidatorTest, TestCssLengthAmpEmailStrict) {
681681
":19:6 The author stylesheet specified in tag 'style amp-custom' "
682682
"and the combined inline styles is too large - document contains 75010 "
683683
"bytes whereas the limit is 75000 bytes. (see https://amp.dev/"
684-
"documentation/guides-and-tutorials/email/learn/spec/amphtml#maximum-size)");
684+
"documentation/guides-and-tutorials/learn/spec/amphtml/#maximum-size)");
685685
EXPECT_EQ(expected_output, output) << "test case " << test_case_name;
686686
}
687687

@@ -701,7 +701,7 @@ TEST(ValidatorTest, TestCssLengthAmpEmailStrict) {
701701
":3769:6 The author stylesheet specified in tag 'style amp-custom' "
702702
"and the combined inline styles is too large - document contains 75014 "
703703
"bytes whereas the limit is 75000 bytes. (see https://amp.dev/"
704-
"documentation/guides-and-tutorials/email/learn/spec/amphtml#maximum-size)");
704+
"documentation/guides-and-tutorials/learn/spec/amphtml/#maximum-size)");
705705
EXPECT_EQ(expected_output, output) << "test case " << test_case_name;
706706
}
707707

@@ -734,8 +734,8 @@ TEST(ValidatorTest, TestCssLengthAmpEmailStrict) {
734734
StrCat("FAIL\n", test_case_name,
735735
":17:2 The inline style specified in tag 'div' is too long - it "
736736
"contains 1001 bytes whereas the limit is 1000 bytes. (see "
737-
"https://amp.dev/documentation/guides-and-tutorials/email/learn/spec/"
738-
"amphtml#maximum-size)");
737+
"https://amp.dev/documentation/guides-and-tutorials/learn/spec/"
738+
"amphtml/#maximum-size)");
739739
EXPECT_EQ(expected_output, output) << "test case " << test_case_name;
740740
}
741741
}

validator/cpp/engine/wasm/BUILD

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Wraps AMP Validator into a WebAssembly library,
22
# which can be used by javascript files.
33

4-
load("@bazel_skylib//rules:build_test.bzl", "build_test")
54
load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary")
65
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_binary", "closure_js_library")
76

@@ -73,8 +72,3 @@ closure_js_binary(
7372
":validator_js_lib",
7473
],
7574
)
76-
77-
build_test(
78-
name = "validator_js_test",
79-
targets = [":validator_js_bin"],
80-
)

validator/cpp/engine/wasm/validator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function digitizeValidationErrorFields(error) {
8383
/**
8484
* When transforming validation errors and validation results from jspb to plain
8585
* objects, the protobuf base64 string is also attached to the output.
86-
* Hence when a plain object needs to be transformed back to protobuf,
86+
* Hence when a plain object neeeds to be transformed back to protobuf,
8787
* the attached base64 could be directly used.
8888
*/
8989
const PB_BASE64 = '_PB_BASE64';

validator/cpp/htmlparser/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ cc_test(
7171
)
7272

7373
# Similar to go lang's defer statement. Defers the execution of statement
74-
# until in which it is declared goes out of scope.
74+
# until in which it is decalred goes out of scope.
7575
cc_library(
7676
name = "defer",
7777
hdrs = [
@@ -80,7 +80,7 @@ cc_library(
8080
copts = ["-std=c++17"],
8181
)
8282

83-
# Helper library declares various doctype constants and a utility function to
83+
# Helper library decalres various doctype constants and a utility function to
8484
# parse doctype string and extract various components in it.
8585
cc_library(
8686
name = "doctype",

validator/cpp/htmlparser/allocator.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
// is naturally aligned if the address used to identify it has an 8-byte
6363
// alignment.
6464
//
65-
// Following data structure contains members totaling 13 bytes, but it's actual
65+
// Following data struture contains members totaling 13 bytes, but it's actual
6666
// size is 24 bytes due to 8 byte alignment.
6767
//
6868
// Alignment is always equal to the largest sized element in the structure.
@@ -201,10 +201,10 @@ class Allocator {
201201
Allocator& operator=(const Allocator&) = delete;
202202

203203
// Allocates memory of same size required to construct object of type T.
204-
// Returns nullptr if allocation failed.
204+
// Returns nullptr if alloction failed.
205205
void* Allocate() {
206206
// Checks if remaining bytes in block are less than object size, or
207-
// remaining bytes after alignment is less than object size.
207+
// reamining bytes after alignment is less than object size.
208208
// Add a new block.
209209
if (object_size_ > remaining_ || !AlignFreeAddress()) {
210210
if (!NewBlock()) return nullptr;
@@ -338,7 +338,7 @@ class Allocator {
338338
}
339339

340340
// If the block's address is not aligned, moves the pointer to the address
341-
// that is multiple of alignment_.
341+
// that is multiple of aligment_.
342342
bool AlignFreeAddress() {
343343
// Checks how many bytes to skip to be at the correct alignment.
344344
if (const std::size_t skip =

validator/cpp/htmlparser/css/parse-css-urls.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void Preprocess(vector<char32_t>* codepoints) {
4747
out.push_back('\n');
4848
last_codepoint_was_cr = true;
4949
break;
50-
case '\f': // also known as form feed (FF)
50+
case '\f': // also knwon as form feed (FF)
5151
out.push_back('\n');
5252
last_codepoint_was_cr = false;
5353
break;

validator/cpp/htmlparser/css/parse-css.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const std::string& Token::StringValue() const {
8585
}
8686

8787
std::string Token::ToString() const {
88-
// The following are overridden in their class: AT_KEYWORD, CLOSE_CURLY,
88+
// The following are overriden in their class: AT_KEYWORD, CLOSE_CURLY,
8989
// CLOSE_PAREN, CLOSE_SQUARE, DELIM, DIMENSION, FUNCTION_TOKEN, IDENT,
9090
// NUMBER, OPEN_CURLY, OPEN_PAREN, OPEN_SQUARE, PERCENTAGE, STRING, URL
9191
switch (Type()) {
@@ -343,7 +343,7 @@ bool Whitespace(char32_t code) {
343343
char32_t kMaximumallowedcodepoint = 0x10ffff;
344344

345345
// A MarkedPosition object saves position information from the tokenizer
346-
// provided as |line| and |col| to the constructor and can later write that
346+
// rovided as |line| and |col| to the constructor and can later write that
347347
// position back to a Token object.
348348
class MarkedPosition {
349349
public:
@@ -2471,7 +2471,7 @@ CombinatorType::Code CombinatorTypeForToken(const Token& token) {
24712471
if (IsDelim(token, "+")) return CombinatorType::ADJACENT_SIBLING;
24722472
if (IsDelim(token, "~")) return CombinatorType::GENERAL_SIBLING;
24732473
// CombinatorTypeForToken is only ever called if the token has one of these
2474-
// delimiters, so reaching this point is impossible.
2474+
// delimitors, so reaching this point is impossible.
24752475
CHECK(false) << absl::StrCat(
24762476
"not a combinator token - type=", TokenType::Code_Name(token.Type()),
24772477
" value=", token.StringValue());

validator/cpp/htmlparser/css/parse-css.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ class Selector : public Token {
741741
virtual void Accept(SelectorVisitor* visitor) const = 0;
742742
};
743743

744-
// This node models type selectors and universal selectors.
744+
// This node models type selectors and universial selectors.
745745
// http://www.w3.org/TR/css3-selectors/#type-selectors
746746
// http://www.w3.org/TR/css3-selectors/#universal-selector
747747
class TypeSelector : public Selector {

0 commit comments

Comments
 (0)