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

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

Issue 693443002: Make the gn copy() tool honor dependencies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add comments, test Created 6 years, 1 month 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
« no previous file with comments | « no previous file | tools/gn/ninja_copy_target_writer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ninja_utils.h" 8 #include "tools/gn/ninja_utils.h"
9 #include "tools/gn/output_file.h" 9 #include "tools/gn/output_file.h"
10 #include "tools/gn/scheduler.h" 10 #include "tools/gn/scheduler.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 const SubstitutionList& output_subst_list = 64 const SubstitutionList& output_subst_list =
65 target_->action_values().outputs(); 65 target_->action_values().outputs();
66 CHECK_EQ(1u, output_subst_list.list().size()) 66 CHECK_EQ(1u, output_subst_list.list().size())
67 << "Should have one entry exactly."; 67 << "Should have one entry exactly.";
68 const SubstitutionPattern& output_subst = output_subst_list.list()[0]; 68 const SubstitutionPattern& output_subst = output_subst_list.list()[0];
69 69
70 std::string tool_name = 70 std::string tool_name =
71 GetNinjaRulePrefixForToolchain(settings_) + 71 GetNinjaRulePrefixForToolchain(settings_) +
72 Toolchain::ToolTypeToName(Toolchain::TYPE_COPY); 72 Toolchain::ToolTypeToName(Toolchain::TYPE_COPY);
73 73
74 // Note that we don't write implicit deps for copy steps. "copy" only 74 OutputFile input_dep =
75 // depends on the output files themselves, rather than having includes 75 WriteInputDepsStampAndGetDep(std::vector<const Target*>());
76 // (the possibility of generated #includes is the main reason for implicit 76
77 // Note that we don't write implicit deps for copy steps. "copy" only depends
78 // on the output files themselves, rather than having includes (the
79 // possibility of generated #includes is the main reason for implicit
77 // dependencies). 80 // dependencies).
78 // 81 //
79 // It would seem that specifying implicit dependencies on the deps of the 82 // It would seem that specifying implicit dependencies on the deps of the
80 // copy command would still be harmeless. But Chrome implements copy tools 83 // copy command would still be harmeless. But Chrome implements copy tools as
81 // as hard links (much faster) which don't change the timestamp. If the 84 // hard links (much faster) which don't change the timestamp. If the ninja
82 // ninja rule looks like this: 85 // rule looks like this: output: copy input | foo.stamp The copy will not
83 // output: copy input | foo.stamp 86 // make a new timestamp on the output file, but the foo.stamp file generated
brettw 2014/10/31 19:56:57 Seems like this was auto-rewrapping that messed up
Dirk Pranke 2014/10/31 20:02:33 Hm. I don't know what caused this, or the change o
84 // The copy will not make a new timestamp on the output file, but the 87 // from a previous step will have a new timestamp. The copy rule will
85 // foo.stamp file generated from a previous step will have a new timestamp. 88 // therefore look out-of-date to Ninja and the rule will get rebuilt.
86 // The copy rule will therefore look out-of-date to Ninja and the rule will
87 // get rebuilt.
88 // 89 //
89 // If this copy is copying a generated file, not listing the implicit 90 // If this copy is copying a generated file, not listing the implicit
90 // dependency will be fine as long as the input to the copy is properly 91 // dependency will be fine as long as the input to the copy is properly
91 // listed as the output from the step that generated it. 92 // listed as the output from the step that generated it.
92 // 93 //
93 // Moreover, doing this assumes that the copy step is always a simple 94 // Moreover, doing this assumes that the copy step is always a simple locally
94 // locally run command, so there is no need for a toolchain dependency. 95 // run command, so there is no need for a toolchain dependency.
95 for (size_t i = 0; i < target_->sources().size(); i++) { 96 //
96 const SourceFile& input_file = target_->sources()[i]; 97 // Note that there is the need in some cases for order-only dependencies
98 // where a command might need to make sure something else runs before it runs
99 // to avoid conflicts. Such cases should be avoided where possible, but
100 // sometimes that's not possible.
101 for (size_t i = 0; i < target_->sources().size(); i++) { const SourceFile&
102 input_file = target_->sources()[i];
97 103
98 OutputFile output_file = 104 OutputFile output_file =
99 SubstitutionWriter::ApplyPatternToSourceAsOutputFile( 105 SubstitutionWriter::ApplyPatternToSourceAsOutputFile(
100 target_->settings(), output_subst, input_file); 106 target_->settings(), output_subst, input_file);
101 output_files->push_back(output_file); 107 output_files->push_back(output_file);
102 108
103 out_ << "build "; 109 out_ << "build ";
104 path_output_.WriteFile(out_, output_file); 110 path_output_.WriteFile(out_, output_file);
105 out_ << ": " << tool_name << " "; 111 out_ << ": " << tool_name << " ";
106 path_output_.WriteFile(out_, input_file); 112 path_output_.WriteFile(out_, input_file);
113 if (!input_dep.value().empty()) {
114 out_ << " || ";
115 path_output_.WriteFile(out_, input_dep);
116 }
107 out_ << std::endl; 117 out_ << std::endl;
108 } 118 }
109 } 119 }
OLDNEW
« no previous file with comments | « no previous file | tools/gn/ninja_copy_target_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698