Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: tools/gn/ninja_copy_target_writer.cc

Issue 387663003: Improve GN handling of directory templates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/ninja_copy_target_writer.h" 5 #include "tools/gn/ninja_copy_target_writer.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "tools/gn/file_template.h" 8 #include "tools/gn/file_template.h"
9 #include "tools/gn/string_utils.h" 9 #include "tools/gn/string_utils.h"
10 10
11 NinjaCopyTargetWriter::NinjaCopyTargetWriter(const Target* target, 11 NinjaCopyTargetWriter::NinjaCopyTargetWriter(const Target* target,
12 const Toolchain* toolchain, 12 const Toolchain* toolchain,
13 std::ostream& out) 13 std::ostream& out)
14 : NinjaTargetWriter(target, toolchain, out) { 14 : NinjaTargetWriter(target, toolchain, out) {
15 } 15 }
16 16
17 NinjaCopyTargetWriter::~NinjaCopyTargetWriter() { 17 NinjaCopyTargetWriter::~NinjaCopyTargetWriter() {
18 } 18 }
19 19
20 void NinjaCopyTargetWriter::Run() { 20 void NinjaCopyTargetWriter::Run() {
21 CHECK(target_->action_values().outputs().size() == 1); 21 CHECK(target_->action_values().outputs().size() == 1);
22 FileTemplate output_template(GetOutputTemplate()); 22 FileTemplate output_template = FileTemplate::GetForTargetOutputs(target_);
23 23
24 std::vector<OutputFile> output_files; 24 std::vector<OutputFile> output_files;
25 25
26 std::string rule_prefix = helper_.GetRulePrefix(target_->settings()); 26 std::string rule_prefix = helper_.GetRulePrefix(target_->settings());
27 27
28 std::string implicit_deps = 28 std::string implicit_deps =
29 WriteInputDepsStampAndGetDep(std::vector<const Target*>()); 29 WriteInputDepsStampAndGetDep(std::vector<const Target*>());
30 30
31 for (size_t i = 0; i < target_->sources().size(); i++) { 31 for (size_t i = 0; i < target_->sources().size(); i++) {
32 const SourceFile& input_file = target_->sources()[i]; 32 const SourceFile& input_file = target_->sources()[i];
33 33
34 // Make the output file from the template. 34 // Make the output file from the template.
35 std::vector<std::string> template_result; 35 std::vector<std::string> template_result;
36 output_template.Apply(input_file, &template_result); 36 output_template.Apply(input_file, &template_result);
37 CHECK(template_result.size() == 1); 37 CHECK(template_result.size() == 1);
38 OutputFile output_file(template_result[0]);
39 38
39 // All output files should be in the build directory, so we can rebase
40 // them just by trimming the prefix.
41 OutputFile output_file(
42 RemovePrefix(template_result[0],
43 settings_->build_settings()->build_dir().value()));
40 output_files.push_back(output_file); 44 output_files.push_back(output_file);
41 45
42 out_ << "build "; 46 out_ << "build ";
43 path_output_.WriteFile(out_, output_file); 47 path_output_.WriteFile(out_, output_file);
44 out_ << ": " << rule_prefix << "copy "; 48 out_ << ": " << rule_prefix << "copy ";
45 path_output_.WriteFile(out_, input_file); 49 path_output_.WriteFile(out_, input_file);
46 out_ << implicit_deps << std::endl; 50 out_ << implicit_deps << std::endl;
47 } 51 }
48 52
49 // Write out the rule for the target to copy all of them. 53 // Write out the rule for the target to copy all of them.
50 out_ << std::endl << "build "; 54 out_ << std::endl << "build ";
51 path_output_.WriteFile(out_, helper_.GetTargetOutputFile(target_)); 55 path_output_.WriteFile(out_, helper_.GetTargetOutputFile(target_));
52 out_ << ": " << rule_prefix << "stamp"; 56 out_ << ": " << rule_prefix << "stamp";
53 for (size_t i = 0; i < output_files.size(); i++) { 57 for (size_t i = 0; i < output_files.size(); i++) {
54 out_ << " "; 58 out_ << " ";
55 path_output_.WriteFile(out_, output_files[i]); 59 path_output_.WriteFile(out_, output_files[i]);
56 } 60 }
57 out_ << std::endl; 61 out_ << std::endl;
58 } 62 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_action_target_writer_unittest.cc ('k') | tools/gn/ninja_copy_target_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698