Chromium Code Reviews| 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" | |
| 7 #include "tools/gn/functions.h" | 6 #include "tools/gn/functions.h" |
| 8 #include "tools/gn/ninja_helper.h" | 7 #include "tools/gn/ninja_helper.h" |
| 9 #include "tools/gn/parse_tree.h" | 8 #include "tools/gn/parse_tree.h" |
| 10 #include "tools/gn/settings.h" | 9 #include "tools/gn/settings.h" |
| 10 #include "tools/gn/substitution_writer.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 Settings* settings, | 18 void GetOutputsForTarget(const Settings* settings, |
| 19 const Target* target, | 19 const Target* target, |
| 20 std::vector<std::string>* ret) { | 20 std::vector<SourceFile>* ret) { |
| 21 switch (target->output_type()) { | 21 switch (target->output_type()) { |
| 22 case Target::ACTION: { | 22 case Target::ACTION: { |
| 23 // Actions: return the outputs specified. | 23 // Actions just use the output list with no substitution. To keep things |
| 24 const std::vector<std::string>& outs = target->action_values().outputs(); | 24 // simple, pass an empty "source file" in to use the same code path for |
| 25 ret->reserve(outs.size()); | 25 // computing substitution outputs. |
| 26 for (size_t i = 0; i < outs.size(); i++) | 26 std::vector<SourceFile> sources; |
| 27 ret->push_back(outs[i]); | 27 sources.push_back(SourceFile()); |
| 28 SubstitutionWriter::ApplyListToSources( | |
| 29 settings, target->action_values().outputs(), sources, ret); | |
|
scottmg
2014/08/05 22:30:32
What will happen if there is a substitution? Maybe
brettw
2014/08/06 18:25:01
The thing that makes the target should prohibit th
| |
| 28 break; | 30 break; |
| 29 } | 31 } |
| 30 | 32 |
| 31 case Target::COPY_FILES: | 33 case Target::COPY_FILES: |
| 32 case Target::ACTION_FOREACH: { | 34 case Target::ACTION_FOREACH: |
| 33 // Copy/action_foreach: return the result of the template in the outputs. | 35 SubstitutionWriter::ApplyListToSources( |
| 34 FileTemplate file_template(settings, target->action_values().outputs(), | 36 settings, target->action_values().outputs(), target->sources(), ret); |
| 35 FileTemplate::OUTPUT_ABSOLUTE, SourceDir()); | |
| 36 const std::vector<SourceFile>& sources = target->sources(); | |
| 37 for (size_t i = 0; i < sources.size(); i++) | |
| 38 file_template.Apply(sources[i], ret); | |
| 39 break; | 37 break; |
| 40 } | |
| 41 | 38 |
| 42 case Target::EXECUTABLE: | 39 case Target::EXECUTABLE: |
| 43 case Target::SHARED_LIBRARY: | 40 case Target::SHARED_LIBRARY: |
| 44 case Target::STATIC_LIBRARY: | 41 case Target::STATIC_LIBRARY: |
| 45 // Return the resulting binary file. Currently, fall through to the | 42 // Return the resulting binary file. Currently, fall through to the |
| 46 // Ninja helper below which will compute the main output name. | 43 // Ninja helper below which will compute the main output name. |
| 47 // | 44 // |
| 48 // TODO(brettw) some targets have secondary files which should go into | 45 // TODO(brettw) some targets have secondary files which should go into |
| 49 // the list after the main (like shared libraries on Windows have an | 46 // the list after the main (like shared libraries on Windows have an |
| 50 // import library). | 47 // import library). |
| 51 case Target::GROUP: | 48 case Target::GROUP: |
| 52 case Target::SOURCE_SET: { | 49 case Target::SOURCE_SET: { |
| 53 // These return the stamp file, which is computed by the NinjaHelper. | 50 // These return the stamp file, which is computed by the NinjaHelper. |
| 54 NinjaHelper helper(settings->build_settings()); | 51 NinjaHelper helper(settings->build_settings()); |
| 55 OutputFile output_file = helper.GetTargetOutputFile(target); | 52 OutputFile output_file = helper.GetTargetOutputFile(target); |
| 56 | 53 |
| 57 // The output file is relative to the build dir. | 54 // The output file is relative to the build dir. |
| 58 std::string absolute_output_file = | 55 ret->push_back(SourceFile( |
| 59 settings->build_settings()->build_dir().value(); | 56 settings->build_settings()->build_dir().value() + |
| 60 absolute_output_file.append(output_file.value()); | 57 output_file.value())); |
| 61 | |
| 62 ret->push_back(absolute_output_file); | |
| 63 break; | 58 break; |
| 64 } | 59 } |
| 65 | 60 |
| 66 default: | 61 default: |
| 67 NOTREACHED(); | 62 NOTREACHED(); |
| 68 } | 63 } |
| 69 } | 64 } |
| 70 | 65 |
| 71 } // namespace | 66 } // namespace |
| 72 | 67 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 } | 157 } |
| 163 | 158 |
| 164 if (!target) { | 159 if (!target) { |
| 165 *err = Err(function, "Target not found in this context.", | 160 *err = Err(function, "Target not found in this context.", |
| 166 label.GetUserVisibleName(false) + | 161 label.GetUserVisibleName(false) + |
| 167 "\nwas not found. get_target_outputs() can only be used for targets\n" | 162 "\nwas not found. get_target_outputs() can only be used for targets\n" |
| 168 "previously defined in the current file."); | 163 "previously defined in the current file."); |
| 169 return Value(); | 164 return Value(); |
| 170 } | 165 } |
| 171 | 166 |
| 172 std::vector<std::string> files; | 167 std::vector<SourceFile> files; |
| 173 GetOutputsForTarget(scope->settings(), target, &files); | 168 GetOutputsForTarget(scope->settings(), target, &files); |
| 174 | 169 |
| 175 Value ret(function, Value::LIST); | 170 Value ret(function, Value::LIST); |
| 176 ret.list_value().reserve(files.size()); | 171 ret.list_value().reserve(files.size()); |
| 177 for (size_t i = 0; i < files.size(); i++) | 172 for (size_t i = 0; i < files.size(); i++) |
| 178 ret.list_value().push_back(Value(function, files[i])); | 173 ret.list_value().push_back(Value(function, files[i].value())); |
| 179 | 174 |
| 180 return ret; | 175 return ret; |
| 181 } | 176 } |
| 182 | 177 |
| 183 } // namespace functions | 178 } // namespace functions |
| OLD | NEW |