1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "tools/gn/script_target_generator.h"
7 #include "tools/gn/err.h"
8 #include "tools/gn/filesystem_utils.h"
9 #include "tools/gn/scope.h"
10 #include "tools/gn/value.h"
11 #include "tools/gn/value_extractors.h"
12 #include "tools/gn/variables.h"
14 ScriptTargetGenerator::ScriptTargetGenerator(Target* target,
16 const Token& function_token,
18 : TargetGenerator(target, scope, function_token, err) {
21 ScriptTargetGenerator::~ScriptTargetGenerator() {
24 void ScriptTargetGenerator::DoRun() {
25 target_->set_output_type(Target::CUSTOM);
28 if (err_->has_error())
32 if (err_->has_error())
36 if (err_->has_error())
40 if (err_->has_error())
44 if (err_->has_error())
48 if (err_->has_error())
51 // Script outputs don't depend on the current toolchain so we can skip adding
55 void ScriptTargetGenerator::FillScript() {
56 // If this gets called, the target type requires a script, so error out
57 // if it doesn't have one.
58 const Value* value = scope_->GetValue(variables::kScript, true);
60 *err_ = Err(function_token_, "This target type requires a \"script\".");
63 if (!value->VerifyTypeIs(Value::STRING, err_))
66 target_->script_values().set_script(
67 scope_->GetSourceDir().ResolveRelativeFile(value->string_value()));
70 void ScriptTargetGenerator::FillScriptArgs() {
71 const Value* value = scope_->GetValue(variables::kArgs, true);
75 std::vector<std::string> args;
76 if (!ExtractListOfStringValues(*value, &args, err_))
78 target_->script_values().swap_in_args(&args);