OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/action_target_generator.h" | 5 #include "tools/gn/action_target_generator.h" |
6 | 6 |
7 #include "tools/gn/build_settings.h" | 7 #include "tools/gn/build_settings.h" |
8 #include "tools/gn/err.h" | 8 #include "tools/gn/err.h" |
9 #include "tools/gn/filesystem_utils.h" | 9 #include "tools/gn/filesystem_utils.h" |
10 #include "tools/gn/parse_tree.h" | 10 #include "tools/gn/parse_tree.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 : TargetGenerator(target, scope, function_call, err), | 22 : TargetGenerator(target, scope, function_call, err), |
23 output_type_(type) { | 23 output_type_(type) { |
24 } | 24 } |
25 | 25 |
26 ActionTargetGenerator::~ActionTargetGenerator() { | 26 ActionTargetGenerator::~ActionTargetGenerator() { |
27 } | 27 } |
28 | 28 |
29 void ActionTargetGenerator::DoRun() { | 29 void ActionTargetGenerator::DoRun() { |
30 target_->set_output_type(output_type_); | 30 target_->set_output_type(output_type_); |
31 | 31 |
32 FillSources(); | 32 if (!FillSources()) |
33 if (err_->has_error()) | |
34 return; | 33 return; |
35 if (output_type_ == Target::ACTION_FOREACH && target_->sources().empty()) { | 34 if (output_type_ == Target::ACTION_FOREACH && target_->sources().empty()) { |
36 // Foreach rules must always have some sources to have an effect. | 35 // Foreach rules must always have some sources to have an effect. |
37 *err_ = Err(function_call_, "action_foreach target has no sources.", | 36 *err_ = Err(function_call_, "action_foreach target has no sources.", |
38 "If you don't specify any sources, there is nothing to run your\n" | 37 "If you don't specify any sources, there is nothing to run your\n" |
39 "script over."); | 38 "script over."); |
40 return; | 39 return; |
41 } | 40 } |
42 | 41 |
43 FillInputs(); | 42 if (!FillInputs()) |
44 if (err_->has_error()) | |
45 return; | 43 return; |
46 | 44 |
47 FillScript(); | 45 if (!FillScript()) |
48 if (err_->has_error()) | |
49 return; | 46 return; |
50 | 47 |
51 FillScriptArgs(); | 48 if (!FillScriptArgs()) |
52 if (err_->has_error()) | |
53 return; | 49 return; |
54 | 50 |
55 FillOutputs(output_type_ == Target::ACTION_FOREACH); | 51 if (!FillOutputs(output_type_ == Target::ACTION_FOREACH)) |
56 if (err_->has_error()) | |
57 return; | 52 return; |
58 | 53 |
59 FillDepfile(); | 54 if (!FillDepfile()) |
60 if (err_->has_error()) | |
61 return; | 55 return; |
62 | 56 |
63 CheckOutputs(); | 57 if (!CheckOutputs()) |
64 if (err_->has_error()) | |
65 return; | 58 return; |
66 | 59 |
67 // Action outputs don't depend on the current toolchain so we can skip adding | 60 // Action outputs don't depend on the current toolchain so we can skip adding |
68 // that dependency. | 61 // that dependency. |
69 } | 62 } |
70 | 63 |
71 void ActionTargetGenerator::FillScript() { | 64 bool ActionTargetGenerator::FillScript() { |
72 // If this gets called, the target type requires a script, so error out | 65 // If this gets called, the target type requires a script, so error out |
73 // if it doesn't have one. | 66 // if it doesn't have one. |
74 const Value* value = scope_->GetValue(variables::kScript, true); | 67 const Value* value = scope_->GetValue(variables::kScript, true); |
75 if (!value) { | 68 if (!value) { |
76 *err_ = Err(function_call_, "This target type requires a \"script\"."); | 69 *err_ = Err(function_call_, "This target type requires a \"script\"."); |
77 return; | 70 return true; |
jamesr
2014/09/16 20:09:24
wait, what does 'return true' mean? here we are re
brettw
2014/09/16 21:01:33
Mistake
| |
78 } | 71 } |
79 if (!value->VerifyTypeIs(Value::STRING, err_)) | 72 if (!value->VerifyTypeIs(Value::STRING, err_)) |
80 return; | 73 return false; |
81 | 74 |
82 SourceFile script_file = | 75 SourceFile script_file = |
83 scope_->GetSourceDir().ResolveRelativeFile(value->string_value()); | 76 scope_->GetSourceDir().ResolveRelativeFile(value->string_value()); |
84 if (script_file.value().empty()) { | 77 if (script_file.value().empty()) { |
85 *err_ = Err(*value, "script name is empty"); | 78 *err_ = Err(*value, "script name is empty"); |
86 return; | 79 return false; |
jamesr
2014/09/16 20:09:24
but here we are returning *false* and populating a
| |
87 } | 80 } |
88 target_->action_values().set_script(script_file); | 81 target_->action_values().set_script(script_file); |
82 return true; | |
89 } | 83 } |
90 | 84 |
91 void ActionTargetGenerator::FillScriptArgs() { | 85 bool ActionTargetGenerator::FillScriptArgs() { |
92 const Value* value = scope_->GetValue(variables::kArgs, true); | 86 const Value* value = scope_->GetValue(variables::kArgs, true); |
93 if (!value) | 87 if (!value) |
94 return; | 88 return true; |
95 | 89 return target_->action_values().args().Parse(*value, err_); |
96 if (!target_->action_values().args().Parse(*value, err_)) | |
97 return; | |
98 } | 90 } |
99 | 91 |
100 void ActionTargetGenerator::FillDepfile() { | 92 bool ActionTargetGenerator::FillDepfile() { |
101 const Value* value = scope_->GetValue(variables::kDepfile, true); | 93 const Value* value = scope_->GetValue(variables::kDepfile, true); |
102 if (!value) | 94 if (!value) |
103 return; | 95 return true; |
104 | 96 |
105 SubstitutionPattern depfile; | 97 SubstitutionPattern depfile; |
106 if (!depfile.Parse(*value, err_)) | 98 if (!depfile.Parse(*value, err_)) |
107 return; | 99 return false; |
108 if (!EnsureSubstitutionIsInOutputDir(depfile, *value)) | 100 if (!EnsureSubstitutionIsInOutputDir(depfile, *value)) |
109 return; | 101 return false; |
110 | 102 |
111 target_->action_values().set_depfile(depfile); | 103 target_->action_values().set_depfile(depfile); |
104 return true; | |
112 } | 105 } |
113 | 106 |
114 void ActionTargetGenerator::CheckOutputs() { | 107 bool ActionTargetGenerator::CheckOutputs() { |
115 const SubstitutionList& outputs = target_->action_values().outputs(); | 108 const SubstitutionList& outputs = target_->action_values().outputs(); |
116 if (outputs.list().empty()) { | 109 if (outputs.list().empty()) { |
117 *err_ = Err(function_call_, "Action has no outputs.", | 110 *err_ = Err(function_call_, "Action has no outputs.", |
118 "If you have no outputs, the build system can not tell when your\n" | 111 "If you have no outputs, the build system can not tell when your\n" |
119 "script needs to be run."); | 112 "script needs to be run."); |
120 return; | 113 return false; |
121 } | 114 } |
122 | 115 |
123 if (output_type_ == Target::ACTION) { | 116 if (output_type_ == Target::ACTION) { |
124 if (!outputs.required_types().empty()) { | 117 if (!outputs.required_types().empty()) { |
125 *err_ = Err(function_call_, "Action has patterns in the output.", | 118 *err_ = Err(function_call_, "Action has patterns in the output.", |
126 "An action target should have the outputs completely specified. If\n" | 119 "An action target should have the outputs completely specified. If\n" |
127 "you want to provide a mapping from source to output, use an\n" | 120 "you want to provide a mapping from source to output, use an\n" |
128 "\"action_foreach\" target."); | 121 "\"action_foreach\" target."); |
129 return; | 122 return false; |
130 } | 123 } |
131 } else if (output_type_ == Target::ACTION_FOREACH) { | 124 } else if (output_type_ == Target::ACTION_FOREACH) { |
132 // A foreach target should always have a pattern in the outputs. | 125 // A foreach target should always have a pattern in the outputs. |
133 if (outputs.required_types().empty()) { | 126 if (outputs.required_types().empty()) { |
134 *err_ = Err(function_call_, | 127 *err_ = Err(function_call_, |
135 "action_foreach should have a pattern in the output.", | 128 "action_foreach should have a pattern in the output.", |
136 "An action_foreach target should have a source expansion pattern in\n" | 129 "An action_foreach target should have a source expansion pattern in\n" |
137 "it to map source file to unique output file name. Otherwise, the\n" | 130 "it to map source file to unique output file name. Otherwise, the\n" |
138 "build system can't determine when your script needs to be run."); | 131 "build system can't determine when your script needs to be run."); |
139 return; | 132 return false; |
140 } | 133 } |
141 } | 134 } |
135 return true; | |
142 } | 136 } |
OLD | NEW |