| Index: tools/gn/target_generator.cc
|
| diff --git a/tools/gn/target_generator.cc b/tools/gn/target_generator.cc
|
| index 3bb51eb9863c6c9855ef8ff0a9241d5c46cb44de..81c4394e0e2006de6f842f4bd7dcf90e008f65c0 100644
|
| --- a/tools/gn/target_generator.cc
|
| +++ b/tools/gn/target_generator.cc
|
| @@ -12,12 +12,10 @@
|
| #include "tools/gn/filesystem_utils.h"
|
| #include "tools/gn/functions.h"
|
| #include "tools/gn/group_target_generator.h"
|
| -#include "tools/gn/item_node.h"
|
| #include "tools/gn/parse_tree.h"
|
| #include "tools/gn/scheduler.h"
|
| #include "tools/gn/scope.h"
|
| #include "tools/gn/script_target_generator.h"
|
| -#include "tools/gn/target_manager.h"
|
| #include "tools/gn/token.h"
|
| #include "tools/gn/value.h"
|
| #include "tools/gn/value_extractors.h"
|
| @@ -25,11 +23,11 @@
|
|
|
| TargetGenerator::TargetGenerator(Target* target,
|
| Scope* scope,
|
| - const Token& function_token,
|
| + const FunctionCallNode* function_call,
|
| Err* err)
|
| : target_(target),
|
| scope_(scope),
|
| - function_token_(function_token),
|
| + function_call_(function_call),
|
| err_(err) {
|
| }
|
|
|
| @@ -43,26 +41,19 @@ void TargetGenerator::Run() {
|
| FillDependencies();
|
| FillGypFile();
|
|
|
| - // To type-specific generation.
|
| + // Do type-specific generation.
|
| DoRun();
|
| -
|
| - // Mark the target as complete.
|
| - if (!err_->has_error()) {
|
| - target_->SetGenerated(&function_token_);
|
| - GetBuildSettings()->target_manager().TargetGenerationComplete(
|
| - target_->label(), err_);
|
| - }
|
| }
|
|
|
| // static
|
| void TargetGenerator::GenerateTarget(Scope* scope,
|
| - const Token& function_token,
|
| + const FunctionCallNode* function_call,
|
| const std::vector<Value>& args,
|
| const std::string& output_type,
|
| Err* err) {
|
| // Name is the argument to the function.
|
| if (args.size() != 1u || args[0].type() != Value::STRING) {
|
| - *err = Err(function_token,
|
| + *err = Err(function_call,
|
| "Target generator requires one string argument.",
|
| "Otherwise I'm not sure what to call this target.");
|
| return;
|
| @@ -75,44 +66,44 @@ void TargetGenerator::GenerateTarget(Scope* scope,
|
| toolchain_label.dir(), toolchain_label.name());
|
|
|
| if (g_scheduler->verbose_logging())
|
| - g_scheduler->Log("Generating target", label.GetUserVisibleName(true));
|
| + g_scheduler->Log("Defining target", label.GetUserVisibleName(true));
|
|
|
| - Target* target =
|
| - scope->settings()->build_settings()->target_manager().GetTarget(
|
| - label, function_token.range(), NULL, err);
|
| - if (err->has_error())
|
| - return;
|
| + scoped_ptr<Target> target(new Target(scope->settings(), label));
|
| + target->set_defined_from(function_call);
|
|
|
| // Create and call out to the proper generator.
|
| if (output_type == functions::kCopy) {
|
| - CopyTargetGenerator generator(target, scope, function_token, err);
|
| + CopyTargetGenerator generator(target.get(), scope, function_call, err);
|
| generator.Run();
|
| } else if (output_type == functions::kCustom) {
|
| - ScriptTargetGenerator generator(target, scope, function_token, err);
|
| + ScriptTargetGenerator generator(target.get(), scope, function_call, err);
|
| generator.Run();
|
| } else if (output_type == functions::kExecutable) {
|
| - BinaryTargetGenerator generator(target, scope, function_token,
|
| + BinaryTargetGenerator generator(target.get(), scope, function_call,
|
| Target::EXECUTABLE, err);
|
| generator.Run();
|
| } else if (output_type == functions::kGroup) {
|
| - GroupTargetGenerator generator(target, scope, function_token, err);
|
| + GroupTargetGenerator generator(target.get(), scope, function_call, err);
|
| generator.Run();
|
| } else if (output_type == functions::kSharedLibrary) {
|
| - BinaryTargetGenerator generator(target, scope, function_token,
|
| + BinaryTargetGenerator generator(target.get(), scope, function_call,
|
| Target::SHARED_LIBRARY, err);
|
| generator.Run();
|
| } else if (output_type == functions::kSourceSet) {
|
| - BinaryTargetGenerator generator(target, scope, function_token,
|
| + BinaryTargetGenerator generator(target.get(), scope, function_call,
|
| Target::SOURCE_SET, err);
|
| generator.Run();
|
| } else if (output_type == functions::kStaticLibrary) {
|
| - BinaryTargetGenerator generator(target, scope, function_token,
|
| + BinaryTargetGenerator generator(target.get(), scope, function_call,
|
| Target::STATIC_LIBRARY, err);
|
| generator.Run();
|
| } else {
|
| - *err = Err(function_token, "Not a known output type",
|
| + *err = Err(function_call, "Not a known output type",
|
| "I am very confused.");
|
| }
|
| +
|
| + if (!err->has_error())
|
| + scope->settings()->build_settings()->ItemDefined(target.PassAs<Item>());
|
| }
|
|
|
| const BuildSettings* TargetGenerator::GetBuildSettings() const {
|
| @@ -155,8 +146,6 @@ void TargetGenerator::FillDependentConfigs() {
|
| }
|
|
|
| void TargetGenerator::FillData() {
|
| - // TODO(brettW) hook this up to the constant when we have cleaned up
|
| - // how data files are used.
|
| const Value* value = scope_->GetValue(variables::kData, true);
|
| if (!value)
|
| return;
|
| @@ -229,88 +218,30 @@ void TargetGenerator::FillOutputs() {
|
| target_->script_values().outputs().swap(outputs);
|
| }
|
|
|
| -void TargetGenerator::SetToolchainDependency() {
|
| - // TODO(brettw) currently we lock separately for each config, dep, and
|
| - // toolchain we add which is bad! Do this in one lock.
|
| - ItemTree* tree = &GetBuildSettings()->item_tree();
|
| - base::AutoLock lock(tree->lock());
|
| - ItemNode* tc_node =
|
| - tree->GetExistingNodeLocked(ToolchainLabelForScope(scope_));
|
| - target_->item_node()->AddDependency(
|
| - GetBuildSettings(), function_token_.range(), tc_node, err_);
|
| -}
|
| -
|
| void TargetGenerator::FillGenericConfigs(const char* var_name,
|
| LabelConfigVector* dest) {
|
| const Value* value = scope_->GetValue(var_name, true);
|
| - if (!value)
|
| - return;
|
| - if (!ExtractListOfLabels(*value, scope_->GetSourceDir(),
|
| - ToolchainLabelForScope(scope_), dest, err_))
|
| - return;
|
| -
|
| - for (size_t i = 0; i < dest->size(); i++) {
|
| - LabelConfigPair& cur = (*dest)[i];
|
| - cur.ptr = Config::GetConfig(scope_->settings(),
|
| - value->list_value()[i].origin()->GetRange(),
|
| - cur.label, target_, err_);
|
| - if (err_->has_error())
|
| - return;
|
| + if (value) {
|
| + ExtractListOfLabels(*value, scope_->GetSourceDir(),
|
| + ToolchainLabelForScope(scope_), dest, err_);
|
| }
|
| }
|
|
|
| void TargetGenerator::FillGenericDeps(const char* var_name,
|
| LabelTargetVector* dest) {
|
| const Value* value = scope_->GetValue(var_name, true);
|
| - if (!value)
|
| - return;
|
| - if (!ExtractListOfLabels(*value, scope_->GetSourceDir(),
|
| - ToolchainLabelForScope(scope_), dest, err_))
|
| - return;
|
| -
|
| - for (size_t i = 0; i < dest->size(); i++) {
|
| - LabelTargetPair& cur = (*dest)[i];
|
| - cur.ptr = GetBuildSettings()->target_manager().GetTarget(
|
| - cur.label, value->list_value()[i].origin()->GetRange(), target_, err_);
|
| - if (err_->has_error())
|
| - return;
|
| + if (value) {
|
| + ExtractListOfLabels(*value, scope_->GetSourceDir(),
|
| + ToolchainLabelForScope(scope_), dest, err_);
|
| }
|
| }
|
|
|
| void TargetGenerator::FillForwardDependentConfigs() {
|
| const Value* value = scope_->GetValue(
|
| variables::kForwardDependentConfigsFrom, true);
|
| - if (!value)
|
| - return;
|
| -
|
| - LabelTargetVector& dest = target_->forward_dependent_configs();
|
| - if (!ExtractListOfLabels(*value, scope_->GetSourceDir(),
|
| - ToolchainLabelForScope(scope_), &dest, err_))
|
| - return;
|
| -
|
| - // We currently assume that the list is very small and do a brute-force
|
| - // search in the deps for the labeled target. This could be optimized.
|
| - const LabelTargetVector& deps = target_->deps();
|
| - std::vector<const Target*> forward_from_list;
|
| - for (size_t dest_index = 0; dest_index < dest.size(); dest_index++) {
|
| - LabelTargetPair& cur_dest = dest[dest_index];
|
| - for (size_t dep_index = 0; dep_index < deps.size(); dep_index++) {
|
| - if (deps[dep_index].label == cur_dest.label) {
|
| - cur_dest.ptr = deps[dep_index].ptr;
|
| - break;
|
| - }
|
| - }
|
| - if (!cur_dest.ptr) {
|
| - *err_ = Err(cur_dest.origin,
|
| - "Can't forward from this target.",
|
| - "forward_dependent_configs_from must contain a list of labels that\n"
|
| - "must all appear in the deps of the same target.");
|
| - return;
|
| - }
|
| + if (value) {
|
| + ExtractListOfLabels(*value, scope_->GetSourceDir(),
|
| + ToolchainLabelForScope(scope_),
|
| + &target_->forward_dependent_configs(), err_);
|
| }
|
| }
|
| -
|
| -
|
| -
|
| -
|
| -
|
|
|