Skip to content

Commit

Permalink
Escape "authors" and replace newlines with spaces
Browse files Browse the repository at this point in the history
This pretties up the output description strings quite a bit.

Bug: 1291994
Change-Id: I1b12eeea4bf2638406bde728b21c8e9a35fd0111

Cq-Include-Trybots: luci.chromium.try:linux-rust-x64-dbg,linux-rust-x64-rel,android-rust-arm64-rel,android-rust-arm64-dbg,android-rust-arm32-rel
Change-Id: I1b12eeea4bf2638406bde728b21c8e9a35fd0111
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4358571
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1120184}
  • Loading branch information
chbaker0 authored and Chromium LUCI CQ committed Mar 21, 2023
1 parent b325d18 commit 42a40ac
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 19 deletions.
8 changes: 4 additions & 4 deletions build/rust/std/rules/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ cargo_crate("cc") {
cargo_pkg_version = "1.0.78"
cargo_pkg_authors = "Alex Crichton <alex@alexcrichton.com>"
cargo_pkg_name = "cc"
cargo_pkg_description = "A build-time dependency for Cargo build scripts to assist in invoking the nativeC compiler to compile native C code into a static archive to be linked into Rustcode."
cargo_pkg_description = "A build-time dependency for Cargo build scripts to assist in invoking the native C compiler to compile native C code into a static archive to be linked into Rust code."
library_configs -= [ "//build/config/compiler:chromium_code" ]
library_configs += [ "//build/config/compiler:no_chromium_code" ]
executable_configs -= [ "//build/config/compiler:chromium_code" ]
Expand All @@ -124,7 +124,7 @@ cargo_crate("cfg_if") {
cargo_pkg_version = "1.0.0"
cargo_pkg_authors = "Alex Crichton <alex@alexcrichton.com>"
cargo_pkg_name = "cfg-if"
cargo_pkg_description = "A macro to ergonomically define an item depending on a large number of #[cfg]parameters. Structured like an if-else chain, the first matching branch is theitem that gets emitted."
cargo_pkg_description = "A macro to ergonomically define an item depending on a large number of #[cfg] parameters. Structured like an if-else chain, the first matching branch is the item that gets emitted."
library_configs -= [ "//build/config/compiler:chromium_code" ]
library_configs += [ "//build/config/compiler:no_chromium_code" ]
executable_configs -= [ "//build/config/compiler:chromium_code" ]
Expand Down Expand Up @@ -155,7 +155,7 @@ cargo_crate("compiler_builtins") {
cargo_pkg_version = "0.1.87"
cargo_pkg_authors = "Jorge Aparicio <japaricious@gmail.com>"
cargo_pkg_name = "compiler_builtins"
cargo_pkg_description = "Compiler intrinsics used by the Rust compiler. Also available for other targetsif necessary!"
cargo_pkg_description = "Compiler intrinsics used by the Rust compiler. Also available for other targets if necessary!"
library_configs -= [ "//build/config/compiler:chromium_code" ]
library_configs += [ "//build/config/compiler:no_chromium_code" ]
executable_configs -= [ "//build/config/compiler:chromium_code" ]
Expand Down Expand Up @@ -751,7 +751,7 @@ cargo_crate("unicode_width") {
cargo_pkg_authors =
"kwantam <kwantam@gmail.com>, Manish Goregaokar <manishsmail@gmail.com>"
cargo_pkg_name = "unicode-width"
cargo_pkg_description = "Determine displayed width of `char` and `str` typesaccording to Unicode Standard Annex #11 rules."
cargo_pkg_description = "Determine displayed width of `char` and `str` types according to Unicode Standard Annex #11 rules."
library_configs -= [ "//build/config/compiler:chromium_code" ]
library_configs += [ "//build/config/compiler:no_chromium_code" ]
executable_configs -= [ "//build/config/compiler:chromium_code" ]
Expand Down
2 changes: 1 addition & 1 deletion third_party/rust/cfg_if/v1/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cargo_crate("lib") {
cargo_pkg_version = "1.0.0"
cargo_pkg_authors = "Alex Crichton <alex@alexcrichton.com>"
cargo_pkg_name = "cfg-if"
cargo_pkg_description = "A macro to ergonomically define an item depending on a large number of #[cfg]parameters. Structured like an if-else chain, the first matching branch is theitem that gets emitted."
cargo_pkg_description = "A macro to ergonomically define an item depending on a large number of #[cfg] parameters. Structured like an if-else chain, the first matching branch is the item that gets emitted."
library_configs -= [ "//build/config/compiler:chromium_code" ]
library_configs += [ "//build/config/compiler:no_chromium_code" ]
executable_configs -= [ "//build/config/compiler:chromium_code" ]
Expand Down
2 changes: 1 addition & 1 deletion third_party/rust/env_logger/v0_9/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cargo_crate("lib") {
cargo_pkg_version = "0.9.0"
cargo_pkg_authors = "The Rust Project Developers"
cargo_pkg_name = "env_logger"
cargo_pkg_description = "A logging implementation for `log` which is configured via an environmentvariable."
cargo_pkg_description = "A logging implementation for `log` which is configured via an environment variable."
library_configs -= [ "//build/config/compiler:chromium_code" ]
library_configs += [ "//build/config/compiler:no_chromium_code" ]
executable_configs -= [ "//build/config/compiler:chromium_code" ]
Expand Down
2 changes: 1 addition & 1 deletion third_party/rust/indexmap/v1/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cargo_crate("lib") {
cargo_pkg_version = "1.8.1"
cargo_pkg_authors = "bluss, Josh Stone <cuviper@gmail.com>"
cargo_pkg_name = "indexmap"
cargo_pkg_description = "A hash table with consistent order and fast iteration.The indexmap is a hash table where the iteration order of the key-valuepairs is independent of the hash values of the keys. It has the usualhash table functionality, it preserves insertion order except afterremovals, and it allows lookup of its elements by either hash table keyor numerical index. A corresponding hash set type is also provided.This crate was initially published under the name ordermap, but it was renamed toindexmap."
cargo_pkg_description = "A hash table with consistent order and fast iteration. The indexmap is a hash table where the iteration order of the key-value pairs is independent of the hash values of the keys. It has the usual hash table functionality, it preserves insertion order except after removals, and it allows lookup of its elements by either hash table key or numerical index. A corresponding hash set type is also provided. This crate was initially published under the name ordermap, but it was renamed to indexmap."
library_configs -= [ "//build/config/compiler:chromium_code" ]
library_configs += [ "//build/config/compiler:no_chromium_code" ]
executable_configs -= [ "//build/config/compiler:chromium_code" ]
Expand Down
4 changes: 2 additions & 2 deletions third_party/rust/regex/v1/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cargo_crate("lib") {
cargo_pkg_version = "1.6.0"
cargo_pkg_authors = "The Rust Project Developers"
cargo_pkg_name = "regex"
cargo_pkg_description = "An implementation of regular expressions for Rust. This implementation usesfinite automata and guarantees linear time matching on all inputs."
cargo_pkg_description = "An implementation of regular expressions for Rust. This implementation uses finite automata and guarantees linear time matching on all inputs."
library_configs -= [ "//build/config/compiler:chromium_code" ]
library_configs += [ "//build/config/compiler:no_chromium_code" ]
executable_configs -= [ "//build/config/compiler:chromium_code" ]
Expand Down Expand Up @@ -67,7 +67,7 @@ cargo_crate("buildrs_support") {
cargo_pkg_version = "1.6.0"
cargo_pkg_authors = "The Rust Project Developers"
cargo_pkg_name = "regex"
cargo_pkg_description = "An implementation of regular expressions for Rust. This implementation usesfinite automata and guarantees linear time matching on all inputs."
cargo_pkg_description = "An implementation of regular expressions for Rust. This implementation uses finite automata and guarantees linear time matching on all inputs."
library_configs -= [ "//build/config/compiler:chromium_code" ]
library_configs += [ "//build/config/compiler:no_chromium_code" ]
executable_configs -= [ "//build/config/compiler:chromium_code" ]
Expand Down
2 changes: 1 addition & 1 deletion third_party/rust/rstest/v0_12/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cargo_crate("lib") {
cargo_pkg_version = "0.12.0"
cargo_pkg_authors = "Michele d'Amico <michele.damico@gmail.com>"
cargo_pkg_name = "rstest"
cargo_pkg_description = "Rust fixture based test framework. It use procedural macroto implement fixtures and table based tests."
cargo_pkg_description = "Rust fixture based test framework. It use procedural macro to implement fixtures and table based tests."
library_configs -= [ "//build/config/compiler:chromium_code" ]
library_configs += [ "//build/config/compiler:no_chromium_code" ]
executable_configs -= [ "//build/config/compiler:chromium_code" ]
Expand Down
2 changes: 1 addition & 1 deletion third_party/rust/strsim/v0_10/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cargo_crate("lib") {
cargo_pkg_version = "0.10.0"
cargo_pkg_authors = "Danny Guo <danny@dannyguo.com>"
cargo_pkg_name = "strsim"
cargo_pkg_description = "Implementations of string similarity metrics. Includes Hamming, Levenshtein,OSA, Damerau-Levenshtein, Jaro, Jaro-Winkler, and Sørensen-Dice."
cargo_pkg_description = "Implementations of string similarity metrics. Includes Hamming, Levenshtein, OSA, Damerau-Levenshtein, Jaro, Jaro-Winkler, and Sørensen-Dice."
library_configs -= [ "//build/config/compiler:chromium_code" ]
library_configs += [ "//build/config/compiler:no_chromium_code" ]
executable_configs -= [ "//build/config/compiler:chromium_code" ]
Expand Down
2 changes: 1 addition & 1 deletion third_party/rust/toml/v0_5/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cargo_crate("lib") {
cargo_pkg_version = "0.5.9"
cargo_pkg_authors = "Alex Crichton <alex@alexcrichton.com>"
cargo_pkg_name = "toml"
cargo_pkg_description = "A native Rust encoder and decoder of TOML-formatted files and streams. Providesimplementations of the standard Serialize/Deserialize traits for TOML data tofacilitate deserializing and serializing Rust structures."
cargo_pkg_description = "A native Rust encoder and decoder of TOML-formatted files and streams. Provides implementations of the standard Serialize/Deserialize traits for TOML data to facilitate deserializing and serializing Rust structures."
library_configs -= [ "//build/config/compiler:chromium_code" ]
library_configs += [ "//build/config/compiler:no_chromium_code" ]
executable_configs -= [ "//build/config/compiler:chromium_code" ]
Expand Down
2 changes: 1 addition & 1 deletion third_party/rust/unicode_width/v0_1/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cargo_crate("lib") {
cargo_pkg_authors =
"kwantam <kwantam@gmail.com>, Manish Goregaokar <manishsmail@gmail.com>"
cargo_pkg_name = "unicode-width"
cargo_pkg_description = "Determine displayed width of `char` and `str` typesaccording to Unicode Standard Annex #11 rules."
cargo_pkg_description = "Determine displayed width of `char` and `str` types according to Unicode Standard Annex #11 rules."
library_configs -= [ "//build/config/compiler:chromium_code" ]
library_configs += [ "//build/config/compiler:no_chromium_code" ]
executable_configs -= [ "//build/config/compiler:chromium_code" ]
Expand Down
13 changes: 10 additions & 3 deletions tools/crates/gnrt/gn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,16 @@ fn write_concrete<W: Write>(
writeln!(writer, "edition = \"{}\"", details.edition)?;
writeln!(writer, "cargo_pkg_version = \"{}\"", details.cargo_pkg_version)?;
if let Some(authors) = &details.cargo_pkg_authors {
writeln!(writer, "cargo_pkg_authors = \"{authors}\"")?;
write!(writer, "cargo_pkg_authors = \"")?;
write!(Escaper(&mut writer), "{authors}")?;
writeln!(writer, "\"")?;
}
writeln!(writer, "cargo_pkg_name = \"{}\"", details.cargo_pkg_name)?;
if let Some(description) = &details.cargo_pkg_description {
// Remove the trailing newline, which unattractively comes out as a
// trailing space. Escaper can't do this because, as a Write
// implementation, it does not know where the end of input will be.
let description = description.trim_end();
write!(writer, "cargo_pkg_description = \"")?;
write!(Escaper(&mut writer), "{description}")?;
writeln!(writer, "\"")?;
Expand Down Expand Up @@ -692,8 +698,9 @@ impl<W: Write> Write for Escaper<W> {
c @ ('"' | '\\') => write!(self.0, "\\{c}"),
// GN strings can encode literal ASCII with "$0x<hex_code>" syntax,
// so we could embed newlines with "$0x0A". However, GN seems to
// escape these incorrectly in its Ninja output so we just skip it.
'\n' => return Ok(()),
// escape these incorrectly in its Ninja output so we just replace
// it with a space.
'\n' => self.0.write_char(' '),
c => self.0.write_char(c),
}
}
Expand Down
6 changes: 3 additions & 3 deletions tools/crates/gnrt/gn_unittest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn test() {
cargo_pkg_authors: Some("Somebody <somebody@foo.org>".to_string()),
cargo_pkg_name: "foo".to_string(),
cargo_pkg_description: Some(
"A generic framework for foo\nNewline\"".to_string(),
"A generic framework for foo\nNewline\"\n".to_string(),
),
deps: vec![RuleDep::construct_for_testing(
Condition::Always,
Expand Down Expand Up @@ -80,7 +80,7 @@ edition = "2021"
cargo_pkg_version = "1.2.3"
cargo_pkg_authors = "Somebody <somebody@foo.org>"
cargo_pkg_name = "foo"
cargo_pkg_description = "A generic framework for fooNewline\""
cargo_pkg_description = "A generic framework for foo Newline\""
library_configs -= [ "//build/config/compiler:chromium_code" ]
library_configs += [ "//build/config/compiler:no_chromium_code" ]
executable_configs -= [ "//build/config/compiler:chromium_code" ]
Expand Down Expand Up @@ -404,7 +404,7 @@ fn test() {
}

expect_eq!("foo bar", escaped("foo bar"));
expect_eq!("foobar", escaped("foo\nbar"));
expect_eq!("foo bar ", escaped("foo\nbar\n"));
expect_eq!(r#"foo \"bar\""#, escaped(r#"foo "bar""#));
expect_eq!("foo 'bar'", escaped("foo 'bar'"));
}

0 comments on commit 42a40ac

Please sign in to comment.