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

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

Issue 630223002: gn: Support build directories outside the source tree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated patch set 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
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_binary_target_writer.h" 5 #include "tools/gn/ninja_binary_target_writer.h"
6 6
7 #include <set> 7 #include <set>
8 #include <sstream> 8 #include <sstream>
9 9
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 if (subst.used[SUBSTITUTION_DEFINES]) { 95 if (subst.used[SUBSTITUTION_DEFINES]) {
96 out_ << kSubstitutionNinjaNames[SUBSTITUTION_DEFINES] << " ="; 96 out_ << kSubstitutionNinjaNames[SUBSTITUTION_DEFINES] << " =";
97 RecursiveTargetConfigToStream<std::string>( 97 RecursiveTargetConfigToStream<std::string>(
98 target_, &ConfigValues::defines, DefineWriter(), out_); 98 target_, &ConfigValues::defines, DefineWriter(), out_);
99 out_ << std::endl; 99 out_ << std::endl;
100 } 100 }
101 101
102 // Include directories. 102 // Include directories.
103 if (subst.used[SUBSTITUTION_INCLUDE_DIRS]) { 103 if (subst.used[SUBSTITUTION_INCLUDE_DIRS]) {
104 out_ << kSubstitutionNinjaNames[SUBSTITUTION_INCLUDE_DIRS] << " ="; 104 out_ << kSubstitutionNinjaNames[SUBSTITUTION_INCLUDE_DIRS] << " =";
105 PathOutput include_path_output(path_output_.current_dir(), 105 PathOutput include_path_output(
106 ESCAPE_NINJA_COMMAND); 106 path_output_.current_dir(),
107 settings_->build_settings()->root_path_utf8(),
108 ESCAPE_NINJA_COMMAND);
107 RecursiveTargetConfigToStream<SourceDir>( 109 RecursiveTargetConfigToStream<SourceDir>(
108 target_, &ConfigValues::include_dirs, 110 target_, &ConfigValues::include_dirs,
109 IncludeWriter(include_path_output), out_); 111 IncludeWriter(include_path_output), out_);
110 out_ << std::endl; 112 out_ << std::endl;
111 } 113 }
112 114
113 // C flags and friends. 115 // C flags and friends.
114 EscapeOptions flag_escape_options = GetFlagOptions(); 116 EscapeOptions flag_escape_options = GetFlagOptions();
115 #define WRITE_FLAGS(name, subst_enum) \ 117 #define WRITE_FLAGS(name, subst_enum) \
116 if (subst.used[subst_enum]) { \ 118 if (subst.used[subst_enum]) { \
(...skipping 26 matching lines...) Expand all
143 std::vector<OutputFile> tool_outputs; // Prevent reallocation in loop. 145 std::vector<OutputFile> tool_outputs; // Prevent reallocation in loop.
144 for (const auto& source : target_->sources()) { 146 for (const auto& source : target_->sources()) {
145 Toolchain::ToolType tool_type = Toolchain::TYPE_NONE; 147 Toolchain::ToolType tool_type = Toolchain::TYPE_NONE;
146 if (!GetOutputFilesForSource(target_, source, 148 if (!GetOutputFilesForSource(target_, source,
147 &tool_type, &tool_outputs)) 149 &tool_type, &tool_outputs))
148 continue; // No output for this source. 150 continue; // No output for this source.
149 151
150 if (tool_type != Toolchain::TYPE_NONE) { 152 if (tool_type != Toolchain::TYPE_NONE) {
151 out_ << "build"; 153 out_ << "build";
152 path_output_.WriteFiles(out_, tool_outputs); 154 path_output_.WriteFiles(out_, tool_outputs);
155
153 out_ << ": " << rule_prefix << Toolchain::ToolTypeToName(tool_type); 156 out_ << ": " << rule_prefix << Toolchain::ToolTypeToName(tool_type);
154 out_ << " "; 157 out_ << " ";
155 path_output_.WriteFile(out_, source); 158 path_output_.WriteFile(out_, source);
156 if (!input_dep.value().empty()) { 159 if (!input_dep.value().empty()) {
157 // Write out the input dependencies as an order-only dependency. This 160 // Write out the input dependencies as an order-only dependency. This
158 // will cause Ninja to make sure the inputs are up-to-date before 161 // will cause Ninja to make sure the inputs are up-to-date before
159 // compiling this source, but changes in the inputs deps won't cause 162 // compiling this source, but changes in the inputs deps won't cause
160 // the file to be recompiled. 163 // the file to be recompiled.
161 // 164 //
162 // This is important to prevent changes in unrelated actions that 165 // This is important to prevent changes in unrelated actions that
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 RecursiveTargetConfigStringsToStream(target_, &ConfigValues::ldflags, 284 RecursiveTargetConfigStringsToStream(target_, &ConfigValues::ldflags,
282 flag_options, out_); 285 flag_options, out_);
283 286
284 // Followed by library search paths that have been recursively pushed 287 // Followed by library search paths that have been recursively pushed
285 // through the dependency tree. 288 // through the dependency tree.
286 const OrderedSet<SourceDir> all_lib_dirs = target_->all_lib_dirs(); 289 const OrderedSet<SourceDir> all_lib_dirs = target_->all_lib_dirs();
287 if (!all_lib_dirs.empty()) { 290 if (!all_lib_dirs.empty()) {
288 // Since we're passing these on the command line to the linker and not 291 // Since we're passing these on the command line to the linker and not
289 // to Ninja, we need to do shell escaping. 292 // to Ninja, we need to do shell escaping.
290 PathOutput lib_path_output(path_output_.current_dir(), 293 PathOutput lib_path_output(path_output_.current_dir(),
294 settings_->build_settings()->root_path_utf8(),
291 ESCAPE_NINJA_COMMAND); 295 ESCAPE_NINJA_COMMAND);
292 for (size_t i = 0; i < all_lib_dirs.size(); i++) { 296 for (size_t i = 0; i < all_lib_dirs.size(); i++) {
293 out_ << " " << tool_->lib_dir_switch(); 297 out_ << " " << tool_->lib_dir_switch();
294 lib_path_output.WriteDir(out_, all_lib_dirs[i], 298 lib_path_output.WriteDir(out_, all_lib_dirs[i],
295 PathOutput::DIR_NO_LAST_SLASH); 299 PathOutput::DIR_NO_LAST_SLASH);
296 } 300 }
297 } 301 }
298 out_ << std::endl; 302 out_ << std::endl;
299 } 303 }
300 304
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 return false; // No tool for this file (it's a header file or something). 472 return false; // No tool for this file (it's a header file or something).
469 const Tool* tool = target->toolchain()->GetTool(*computed_tool_type); 473 const Tool* tool = target->toolchain()->GetTool(*computed_tool_type);
470 if (!tool) 474 if (!tool)
471 return false; // Tool does not apply for this toolchain.file. 475 return false; // Tool does not apply for this toolchain.file.
472 476
473 // Figure out what output(s) this compiler produces. 477 // Figure out what output(s) this compiler produces.
474 SubstitutionWriter::ApplyListToCompilerAsOutputFile( 478 SubstitutionWriter::ApplyListToCompilerAsOutputFile(
475 target, source, tool->outputs(), outputs); 479 target, source, tool->outputs(), outputs);
476 return !outputs->empty(); 480 return !outputs->empty();
477 } 481 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698