From c991329db5c1c57f489619b4220329fb26bd59b2 Mon Sep 17 00:00:00 2001 From: Claudio DeSouza Date: Mon, 4 Nov 2024 22:12:21 +0000 Subject: [PATCH] [CodeHealth][rust] Brave `BUILD.gn` handlebars changes This change contains the handlebars changes we apply to our own handlebars file. This commit also adds a patch that can be used to update the handlebar files, based on new upstream additions. --- .../rust/chromium_crates_io/BUILD.gn.hbs | 44 +++---- .../chromium_crates_io/BUILD.gn.hbs.patch | 114 ++++++++++++++++++ 2 files changed, 134 insertions(+), 24 deletions(-) create mode 100644 third_party/rust/chromium_crates_io/BUILD.gn.hbs.patch diff --git a/third_party/rust/chromium_crates_io/BUILD.gn.hbs b/third_party/rust/chromium_crates_io/BUILD.gn.hbs index 4cf2f4f5f8b4..aa598c2dcf14 100644 --- a/third_party/rust/chromium_crates_io/BUILD.gn.hbs +++ b/third_party/rust/chromium_crates_io/BUILD.gn.hbs @@ -1,6 +1,7 @@ -# Copyright 2023 The Chromium Authors -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. +# Copyright (c) 2024 The Brave Authors. All rights reserved. +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this file, +# You can obtain one at https://mozilla.org/MPL/2.0/. # @generated from third_party/rust/chromium_crates_io/BUILD.gn.hbs by # tools/crates/gnrt. @@ -53,14 +54,14 @@ cargo_crate("{{this.name}}") { ":lib", {{/if}} {{#each this.packages}} - "//third_party/rust/{{this.name}}/{{this.epoch}}:lib", + "//brave/third_party/rust/{{this.name}}/{{this.epoch}}:lib", {{/each}} ] {{else}} if ({{this.cond}}) { deps += [ {{#each this.packages}} - "//third_party/rust/{{this.name}}/{{this.epoch}}:lib", + "//brave/third_party/rust/{{this.name}}/{{this.epoch}}:lib", {{/each}} ] } @@ -69,7 +70,7 @@ cargo_crate("{{this.name}}") { {{#if aliased_deps}} aliased_deps = { {{#each aliased_deps}} - {{this.0}} = "{{this.1}}" + {{this.0}} = "//brave/third_party/rust/{{this.1}}:lib" {{/each}} } {{/if}} @@ -77,14 +78,14 @@ cargo_crate("{{this.name}}") { {{#if @first}} build_deps = [ {{#each this.packages}} - "//third_party/rust/{{this.name}}/{{this.epoch}}:buildrs_support", + "//brave/third_party/rust/{{this.name}}/{{this.epoch}}:buildrs_support", {{/each}} ] {{else}} if ({{this.cond}}) { build_deps += [ {{#each this.packages}} - "//third_party/rust/{{this.name}}/{{this.epoch}}:buildrs_support", + "//brave/third_party/rust/{{this.name}}/{{this.epoch}}:buildrs_support", {{/each}} ] } @@ -119,23 +120,32 @@ cargo_crate("{{this.name}}") { ] {{/with}} {{/if}} - {{#if rustenv}} + {{#if (or rustenv extra_kv.rustenv)}} rustenv = [ {{#each rustenv}} "{{this}}", {{/each}} + {{#each extra_kv.rustenv}} + "{{this}}", + {{/each}} ] {{/if}} - {{#if rustflags}} + {{#if (or rustflags extra_kv.rustflags)}} rustflags = [ {{#each rustflags}} "{{this}}", {{/each}} + {{#each extra_kv.rustflags}} + "{{this}}", + {{/each}} ] {{/if}} {{#if output_dir}} output_dir = "{{output_dir}}" {{/if}} + {{#if extra_kv.raw_gn}} + {{extra_kv.raw_gn}} + {{/if}} {{#if native_libs}} native_libs = [ {{#each native_libs}} @@ -144,20 +154,6 @@ cargo_crate("{{this.name}}") { ] {{/if}} {{/with}} - - {{#if gn_visibility.public}} - {{#if detail.extra_kv.visibility}} - visibility = [] - {{/if}} - {{else}} - # Only for usage from third-party crates. Add the crate to - # //third_party/rust/chromium_crates_io/Cargo.toml to use - # it from first-party code. - visibility = [ "//third_party/rust/*" ] - {{/if}} - {{#each detail.extra_kv.visibility}} - visibility += [ "{{this}}" ] - {{/each}} {{#if gn_visibility.testonly}} testonly = true {{/if}} diff --git a/third_party/rust/chromium_crates_io/BUILD.gn.hbs.patch b/third_party/rust/chromium_crates_io/BUILD.gn.hbs.patch new file mode 100644 index 000000000000..409f844a32dd --- /dev/null +++ b/third_party/rust/chromium_crates_io/BUILD.gn.hbs.patch @@ -0,0 +1,114 @@ +diff --git a/third_party/rust/chromium_crates_io/BUILD.gn.hbs b/third_party/rust/chromium_crates_io/BUILD.gn.hbs +index 4cf2f4f5f8b..aa598c2dcf1 100644 +--- a/third_party/rust/chromium_crates_io/BUILD.gn.hbs ++++ b/third_party/rust/chromium_crates_io/BUILD.gn.hbs +@@ -1,6 +1,7 @@ +-# Copyright 2023 The Chromium Authors +-# Use of this source code is governed by a BSD-style license that can be +-# found in the LICENSE file. ++# Copyright (c) 2024 The Brave Authors. All rights reserved. ++# This Source Code Form is subject to the terms of the Mozilla Public ++# License, v. 2.0. If a copy of the MPL was not distributed with this file, ++# You can obtain one at https://mozilla.org/MPL/2.0/. + + # @generated from third_party/rust/chromium_crates_io/BUILD.gn.hbs by + # tools/crates/gnrt. +@@ -53,14 +54,14 @@ cargo_crate("{{this.name}}") { + ":lib", + {{/if}} + {{#each this.packages}} +- "//third_party/rust/{{this.name}}/{{this.epoch}}:lib", ++ "//brave/third_party/rust/{{this.name}}/{{this.epoch}}:lib", + {{/each}} + ] + {{else}} + if ({{this.cond}}) { + deps += [ + {{#each this.packages}} +- "//third_party/rust/{{this.name}}/{{this.epoch}}:lib", ++ "//brave/third_party/rust/{{this.name}}/{{this.epoch}}:lib", + {{/each}} + ] + } +@@ -69,7 +70,7 @@ cargo_crate("{{this.name}}") { + {{#if aliased_deps}} + aliased_deps = { + {{#each aliased_deps}} +- {{this.0}} = "{{this.1}}" ++ {{this.0}} = "//brave/third_party/rust/{{this.1}}:lib" + {{/each}} + } + {{/if}} +@@ -77,14 +78,14 @@ cargo_crate("{{this.name}}") { + {{#if @first}} + build_deps = [ + {{#each this.packages}} +- "//third_party/rust/{{this.name}}/{{this.epoch}}:buildrs_support", ++ "//brave/third_party/rust/{{this.name}}/{{this.epoch}}:buildrs_support", + {{/each}} + ] + {{else}} + if ({{this.cond}}) { + build_deps += [ + {{#each this.packages}} +- "//third_party/rust/{{this.name}}/{{this.epoch}}:buildrs_support", ++ "//brave/third_party/rust/{{this.name}}/{{this.epoch}}:buildrs_support", + {{/each}} + ] + } +@@ -119,23 +120,32 @@ cargo_crate("{{this.name}}") { + ] + {{/with}} + {{/if}} +- {{#if rustenv}} ++ {{#if (or rustenv extra_kv.rustenv)}} + rustenv = [ + {{#each rustenv}} + "{{this}}", + {{/each}} ++ {{#each extra_kv.rustenv}} ++ "{{this}}", ++ {{/each}} + ] + {{/if}} +- {{#if rustflags}} ++ {{#if (or rustflags extra_kv.rustflags)}} + rustflags = [ + {{#each rustflags}} + "{{this}}", + {{/each}} ++ {{#each extra_kv.rustflags}} ++ "{{this}}", ++ {{/each}} + ] + {{/if}} + {{#if output_dir}} + output_dir = "{{output_dir}}" + {{/if}} ++ {{#if extra_kv.raw_gn}} ++ {{extra_kv.raw_gn}} ++ {{/if}} + {{#if native_libs}} + native_libs = [ + {{#each native_libs}} +@@ -144,20 +154,6 @@ cargo_crate("{{this.name}}") { + ] + {{/if}} + {{/with}} +- +- {{#if gn_visibility.public}} +- {{#if detail.extra_kv.visibility}} +- visibility = [] +- {{/if}} +- {{else}} +- # Only for usage from third-party crates. Add the crate to +- # //third_party/rust/chromium_crates_io/Cargo.toml to use +- # it from first-party code. +- visibility = [ "//third_party/rust/*" ] +- {{/if}} +- {{#each detail.extra_kv.visibility}} +- visibility += [ "{{this}}" ] +- {{/each}} + {{#if gn_visibility.testonly}} + testonly = true + {{/if}}