- add sources.
[platform/framework/web/crosswalk.git] / src / tools / gn / script_target_generator.cc
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.
4
5 #include "tools/gn/script_target_generator.h"
6
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"
13
14 ScriptTargetGenerator::ScriptTargetGenerator(Target* target,
15                                              Scope* scope,
16                                              const Token& function_token,
17                                              Err* err)
18     : TargetGenerator(target, scope, function_token, err) {
19 }
20
21 ScriptTargetGenerator::~ScriptTargetGenerator() {
22 }
23
24 void ScriptTargetGenerator::DoRun() {
25   target_->set_output_type(Target::CUSTOM);
26
27   FillExternal();
28   if (err_->has_error())
29     return;
30
31   FillSources();
32   if (err_->has_error())
33     return;
34
35   FillSourcePrereqs();
36   if (err_->has_error())
37     return;
38
39   FillScript();
40   if (err_->has_error())
41     return;
42
43   FillScriptArgs();
44   if (err_->has_error())
45     return;
46
47   FillOutputs();
48   if (err_->has_error())
49     return;
50
51   // Script outputs don't depend on the current toolchain so we can skip adding
52   // that dependency.
53 }
54
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);
59   if (!value) {
60     *err_ = Err(function_token_, "This target type requires a \"script\".");
61     return;
62   }
63   if (!value->VerifyTypeIs(Value::STRING, err_))
64     return;
65
66   target_->script_values().set_script(
67       scope_->GetSourceDir().ResolveRelativeFile(value->string_value()));
68 }
69
70 void ScriptTargetGenerator::FillScriptArgs() {
71   const Value* value = scope_->GetValue(variables::kArgs, true);
72   if (!value)
73     return;
74
75   std::vector<std::string> args;
76   if (!ExtractListOfStringValues(*value, &args, err_))
77     return;
78   target_->script_values().swap_in_args(&args);
79 }