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/build_settings.h"
8 #include "tools/gn/err.h"
9 #include "tools/gn/filesystem_utils.h"
10 #include "tools/gn/parse_tree.h"
11 #include "tools/gn/scope.h"
12 #include "tools/gn/value.h"
13 #include "tools/gn/value_extractors.h"
14 #include "tools/gn/variables.h"
16 ScriptTargetGenerator::ScriptTargetGenerator(
19 const FunctionCallNode
* function_call
,
21 : TargetGenerator(target
, scope
, function_call
, err
) {
24 ScriptTargetGenerator::~ScriptTargetGenerator() {
27 void ScriptTargetGenerator::DoRun() {
28 target_
->set_output_type(Target::CUSTOM
);
31 if (err_
->has_error())
35 if (err_
->has_error())
39 if (err_
->has_error())
43 if (err_
->has_error())
47 if (err_
->has_error())
51 if (err_
->has_error())
55 if (err_
->has_error())
58 // Script outputs don't depend on the current toolchain so we can skip adding
62 void ScriptTargetGenerator::FillScript() {
63 // If this gets called, the target type requires a script, so error out
64 // if it doesn't have one.
65 const Value
* value
= scope_
->GetValue(variables::kScript
, true);
67 *err_
= Err(function_call_
, "This target type requires a \"script\".");
70 if (!value
->VerifyTypeIs(Value::STRING
, err_
))
73 target_
->script_values().set_script(
74 scope_
->GetSourceDir().ResolveRelativeFile(value
->string_value()));
77 void ScriptTargetGenerator::FillScriptArgs() {
78 const Value
* value
= scope_
->GetValue(variables::kArgs
, true);
82 std::vector
<std::string
> args
;
83 if (!ExtractListOfStringValues(*value
, &args
, err_
))
85 target_
->script_values().swap_in_args(&args
);
88 void ScriptTargetGenerator::FillDepfile() {
89 const Value
* value
= scope_
->GetValue(variables::kDepfile
, true);
92 target_
->script_values().set_depfile(
93 scope_
->settings()->build_settings()->build_dir().ResolveRelativeFile(
94 value
->string_value()));