[rust] Update RustTargetGenerator to not duplicate work Previously, the RustTargetGenerator inherited from TargetGenerator, and so when it was called from the BinaryTargetGenerator it would re-run the base TargetGenerator logic, resulting in errors about duplicates. This moves the RustValuesGenerator to be more like the ConfigValuesGenerator. Change-Id: I06df41bf1d5788bb2695e2c908342c1aa3568b75 Reviewed-on: https://gn-review.googlesource.com/c/gn/+/5560 Reviewed-by: Brett Wilson <brettw@chromium.org> Commit-Queue: Julie Hockett <juliehockett@google.com>
diff --git a/build/gen.py b/build/gen.py index a1e5201..99de57e 100755 --- a/build/gen.py +++ b/build/gen.py
@@ -517,7 +517,7 @@ 'tools/gn/qt_creator_writer.cc', 'tools/gn/runtime_deps.cc', 'tools/gn/rust_substitution_type.cc', - 'tools/gn/rust_target_generator.cc', + 'tools/gn/rust_values_generator.cc', 'tools/gn/rust_tool.cc', 'tools/gn/rust_values.cc', 'tools/gn/rust_variables.cc',
diff --git a/tools/gn/binary_target_generator.cc b/tools/gn/binary_target_generator.cc index d307342..4feadba 100644 --- a/tools/gn/binary_target_generator.cc +++ b/tools/gn/binary_target_generator.cc
@@ -10,7 +10,7 @@ #include "tools/gn/filesystem_utils.h" #include "tools/gn/functions.h" #include "tools/gn/parse_tree.h" -#include "tools/gn/rust_target_generator.h" +#include "tools/gn/rust_values_generator.h" #include "tools/gn/rust_variables.h" #include "tools/gn/scope.h" #include "tools/gn/settings.h"
diff --git a/tools/gn/functions_target_rust_unittest.cc b/tools/gn/functions_target_rust_unittest.cc index 80e4696..37bd8b1 100644 --- a/tools/gn/functions_target_rust_unittest.cc +++ b/tools/gn/functions_target_rust_unittest.cc
@@ -348,3 +348,26 @@ item_collector.back()->AsTarget()->rust_values().aliased_deps().size(), 2U); } + +TEST_F(RustFunctionsTarget, PublicConfigs) { + TestWithScope setup; + + Scope::ItemVector item_collector; + setup.scope()->set_item_collector(&item_collector); + setup.scope()->set_source_dir(SourceDir("/")); + + TestParseInput exe_input( + "config(\"bar\") {\n" + " defines = [ \"DOOM_MELON\" ]" + "}\n" + "executable(\"foo\") {\n" + " crate_name = \"foo_crate\"\n" + " sources = [ \"foo.rs\", \"lib.rs\", \"main.rs\" ]\n" + " edition = \"2018\"" + " public_configs = [ \":bar\" ]" + "}\n"); + ASSERT_FALSE(exe_input.has_error()); + Err err; + exe_input.parsed()->Execute(setup.scope(), &err); + ASSERT_FALSE(err.has_error()) << err.message(); +}
diff --git a/tools/gn/rust_target_generator.cc b/tools/gn/rust_values_generator.cc similarity index 97% rename from tools/gn/rust_target_generator.cc rename to tools/gn/rust_values_generator.cc index 47dc0b6..910d5af 100644 --- a/tools/gn/rust_target_generator.cc +++ b/tools/gn/rust_values_generator.cc
@@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "tools/gn/rust_target_generator.h" +#include "tools/gn/rust_values_generator.h" #include "tools/gn/config_values_generator.h" #include "tools/gn/err.h" @@ -22,11 +22,14 @@ Scope* scope, const FunctionCallNode* function_call, Err* err) - : TargetGenerator(target, scope, function_call, err) {} + : target_(target), + scope_(scope), + function_call_(function_call), + err_(err) {} RustTargetGenerator::~RustTargetGenerator() = default; -void RustTargetGenerator::DoRun() { +void RustTargetGenerator::Run() { // source_set targets don't need any special Rust handling. if (target_->output_type() == Target::SOURCE_SET) return;
diff --git a/tools/gn/rust_target_generator.h b/tools/gn/rust_values_generator.h similarity index 66% rename from tools/gn/rust_target_generator.h rename to tools/gn/rust_values_generator.h index ae6a365..fb939db 100644 --- a/tools/gn/rust_target_generator.h +++ b/tools/gn/rust_values_generator.h
@@ -2,24 +2,24 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef TOOLS_GN_RUST_TARGET_GENERATOR_H_ -#define TOOLS_GN_RUST_TARGET_GENERATOR_H_ +#ifndef TOOLS_GN_RUST_VALUES_GENERATOR_H_ +#define TOOLS_GN_RUST_VALUES_GENERATOR_H_ #include "base/macros.h" #include "tools/gn/target.h" -#include "tools/gn/target_generator.h" + +class FunctionCallNode; // Collects and writes specified data. -class RustTargetGenerator : public TargetGenerator { +class RustTargetGenerator { public: RustTargetGenerator(Target* target, Scope* scope, const FunctionCallNode* function_call, Err* err); - ~RustTargetGenerator() override; + ~RustTargetGenerator(); - protected: - void DoRun() override; + void Run(); private: bool FillCrateName(); @@ -28,7 +28,12 @@ bool FillEdition(); bool FillAliasedDeps(); + Target* target_; + Scope* scope_; + const FunctionCallNode* function_call_; + Err* err_; + DISALLOW_COPY_AND_ASSIGN(RustTargetGenerator); }; -#endif // TOOLS_GN_GENERATED_FILE_TARGET_GENERATOR_H_ +#endif // TOOLS_GN_RUST_VALUES_GENERATOR_H_