OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/build_settings.h" | 5 #include "tools/gn/build_settings.h" |
6 #include "tools/gn/file_template.h" | 6 #include "tools/gn/file_template.h" |
7 #include "tools/gn/functions.h" | 7 #include "tools/gn/functions.h" |
8 #include "tools/gn/ninja_helper.h" | 8 #include "tools/gn/ninja_helper.h" |
9 #include "tools/gn/parse_tree.h" | 9 #include "tools/gn/parse_tree.h" |
10 #include "tools/gn/settings.h" | 10 #include "tools/gn/settings.h" |
11 #include "tools/gn/target.h" | 11 #include "tools/gn/target.h" |
12 #include "tools/gn/value.h" | 12 #include "tools/gn/value.h" |
13 | 13 |
14 namespace functions { | 14 namespace functions { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 void GetOutputsForTarget(const BuildSettings* build_settings, | 18 void GetOutputsForTarget(const Settings* settings, |
19 const Target* target, | 19 const Target* target, |
20 std::vector<std::string>* ret) { | 20 std::vector<std::string>* ret) { |
21 switch (target->output_type()) { | 21 switch (target->output_type()) { |
22 case Target::ACTION: | 22 case Target::ACTION: |
23 case Target::COPY_FILES: { | 23 case Target::COPY_FILES: { |
24 // Actions and copy targets: return the outputs specified. | 24 // Actions and copy targets: return the outputs specified. |
25 const std::vector<SourceFile>& outs = target->action_values().outputs(); | 25 const std::vector<SourceFile>& outs = target->action_values().outputs(); |
26 ret->reserve(outs.size()); | 26 ret->reserve(outs.size()); |
27 for (size_t i = 0; i < outs.size(); i++) | 27 for (size_t i = 0; i < outs.size(); i++) |
28 ret->push_back(outs[i].value()); | 28 ret->push_back(outs[i].value()); |
29 break; | 29 break; |
30 } | 30 } |
31 | 31 |
32 case Target::ACTION_FOREACH: { | 32 case Target::ACTION_FOREACH: { |
33 // Action_foreach: return the result of the template in the outputs. | 33 // Action_foreach: return the result of the template in the outputs. |
34 FileTemplate file_template(target->action_values().outputs()); | 34 FileTemplate file_template(settings, target->action_values().outputs()); |
35 const std::vector<SourceFile>& sources = target->sources(); | 35 const std::vector<SourceFile>& sources = target->sources(); |
36 for (size_t i = 0; i < sources.size(); i++) | 36 for (size_t i = 0; i < sources.size(); i++) |
37 file_template.ApplyString(sources[i].value(), ret); | 37 file_template.Apply(sources[i], ret); |
38 break; | 38 break; |
39 } | 39 } |
40 | 40 |
41 case Target::EXECUTABLE: | 41 case Target::EXECUTABLE: |
42 case Target::SHARED_LIBRARY: | 42 case Target::SHARED_LIBRARY: |
43 case Target::STATIC_LIBRARY: | 43 case Target::STATIC_LIBRARY: |
44 // Return the resulting binary file. Currently, fall through to the | 44 // Return the resulting binary file. Currently, fall through to the |
45 // Ninja helper below which will compute the main output name. | 45 // Ninja helper below which will compute the main output name. |
46 // | 46 // |
47 // TODO(brettw) some targets have secondary files which should go into | 47 // TODO(brettw) some targets have secondary files which should go into |
48 // the list after the main (like shared libraries on Windows have an | 48 // the list after the main (like shared libraries on Windows have an |
49 // import library). | 49 // import library). |
50 case Target::GROUP: | 50 case Target::GROUP: |
51 case Target::SOURCE_SET: { | 51 case Target::SOURCE_SET: { |
52 // These return the stamp file, which is computed by the NinjaHelper. | 52 // These return the stamp file, which is computed by the NinjaHelper. |
53 NinjaHelper helper(build_settings); | 53 NinjaHelper helper(settings->build_settings()); |
54 OutputFile output_file = helper.GetTargetOutputFile(target); | 54 OutputFile output_file = helper.GetTargetOutputFile(target); |
55 | 55 |
56 // The output file is relative to the build dir. | 56 // The output file is relative to the build dir. |
57 std::string absolute_output_file = build_settings->build_dir().value(); | 57 std::string absolute_output_file = |
| 58 settings->build_settings()->build_dir().value(); |
58 absolute_output_file.append(output_file.value()); | 59 absolute_output_file.append(output_file.value()); |
59 | 60 |
60 ret->push_back(absolute_output_file); | 61 ret->push_back(absolute_output_file); |
61 break; | 62 break; |
62 } | 63 } |
63 | 64 |
64 default: | 65 default: |
65 NOTREACHED(); | 66 NOTREACHED(); |
66 } | 67 } |
67 } | 68 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 162 |
162 if (!target) { | 163 if (!target) { |
163 *err = Err(function, "Target not found in this context.", | 164 *err = Err(function, "Target not found in this context.", |
164 label.GetUserVisibleName(false) + | 165 label.GetUserVisibleName(false) + |
165 "\nwas not found. get_target_outputs() can only be used for targets\n" | 166 "\nwas not found. get_target_outputs() can only be used for targets\n" |
166 "previously defined in the current file."); | 167 "previously defined in the current file."); |
167 return Value(); | 168 return Value(); |
168 } | 169 } |
169 | 170 |
170 std::vector<std::string> files; | 171 std::vector<std::string> files; |
171 GetOutputsForTarget(scope->settings()->build_settings(), target, &files); | 172 GetOutputsForTarget(scope->settings(), target, &files); |
172 | 173 |
173 Value ret(function, Value::LIST); | 174 Value ret(function, Value::LIST); |
174 ret.list_value().reserve(files.size()); | 175 ret.list_value().reserve(files.size()); |
175 for (size_t i = 0; i < files.size(); i++) | 176 for (size_t i = 0; i < files.size(); i++) |
176 ret.list_value().push_back(Value(function, files[i])); | 177 ret.list_value().push_back(Value(function, files[i])); |
177 | 178 |
178 return ret; | 179 return ret; |
179 } | 180 } |
180 | 181 |
181 } // namespace functions | 182 } // namespace functions |
OLD | NEW |