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

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, 2 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
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(path_output_.current_dir(),
106 settings_->build_settings()->root_path(),
106 ESCAPE_NINJA_COMMAND); 107 ESCAPE_NINJA_COMMAND);
107 RecursiveTargetConfigToStream<SourceDir>( 108 RecursiveTargetConfigToStream<SourceDir>(
108 target_, &ConfigValues::include_dirs, 109 target_, &ConfigValues::include_dirs,
109 IncludeWriter(include_path_output), out_); 110 IncludeWriter(include_path_output), out_);
110 out_ << std::endl; 111 out_ << std::endl;
111 } 112 }
112 113
113 // C flags and friends. 114 // C flags and friends.
114 EscapeOptions flag_escape_options = GetFlagOptions(); 115 EscapeOptions flag_escape_options = GetFlagOptions();
115 #define WRITE_FLAGS(name, subst_enum) \ 116 #define WRITE_FLAGS(name, subst_enum) \
(...skipping 27 matching lines...) Expand all
143 std::vector<OutputFile> tool_outputs; // Prevent reallocation in loop. 144 std::vector<OutputFile> tool_outputs; // Prevent reallocation in loop.
144 for (const auto& source : target_->sources()) { 145 for (const auto& source : target_->sources()) {
145 Toolchain::ToolType tool_type = Toolchain::TYPE_NONE; 146 Toolchain::ToolType tool_type = Toolchain::TYPE_NONE;
146 if (!GetOutputFilesForSource(target_, source, 147 if (!GetOutputFilesForSource(target_, source,
147 &tool_type, &tool_outputs)) 148 &tool_type, &tool_outputs))
148 continue; // No output for this source. 149 continue; // No output for this source.
149 150
150 if (tool_type != Toolchain::TYPE_NONE) { 151 if (tool_type != Toolchain::TYPE_NONE) {
151 out_ << "build"; 152 out_ << "build";
152 path_output_.WriteFiles(out_, tool_outputs); 153 path_output_.WriteFiles(out_, tool_outputs);
154
153 out_ << ": " << rule_prefix << Toolchain::ToolTypeToName(tool_type); 155 out_ << ": " << rule_prefix << Toolchain::ToolTypeToName(tool_type);
154 out_ << " "; 156 out_ << " ";
155 path_output_.WriteFile(out_, source); 157 path_output_.WriteFile(out_, source);
156 if (!input_dep.value().empty()) { 158 if (!input_dep.value().empty()) {
157 // Write out the input dependencies as an order-only dependency. This 159 // 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 160 // 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 161 // compiling this source, but changes in the inputs deps won't cause
160 // the file to be recompiled. 162 // the file to be recompiled.
161 // 163 //
162 // This is important to prevent changes in unrelated actions that 164 // 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, 283 RecursiveTargetConfigStringsToStream(target_, &ConfigValues::ldflags,
282 flag_options, out_); 284 flag_options, out_);
283 285
284 // Followed by library search paths that have been recursively pushed 286 // Followed by library search paths that have been recursively pushed
285 // through the dependency tree. 287 // through the dependency tree.
286 const OrderedSet<SourceDir> all_lib_dirs = target_->all_lib_dirs(); 288 const OrderedSet<SourceDir> all_lib_dirs = target_->all_lib_dirs();
287 if (!all_lib_dirs.empty()) { 289 if (!all_lib_dirs.empty()) {
288 // Since we're passing these on the command line to the linker and not 290 // Since we're passing these on the command line to the linker and not
289 // to Ninja, we need to do shell escaping. 291 // to Ninja, we need to do shell escaping.
290 PathOutput lib_path_output(path_output_.current_dir(), 292 PathOutput lib_path_output(path_output_.current_dir(),
293 settings_->build_settings()->root_path(),
291 ESCAPE_NINJA_COMMAND); 294 ESCAPE_NINJA_COMMAND);
292 for (size_t i = 0; i < all_lib_dirs.size(); i++) { 295 for (size_t i = 0; i < all_lib_dirs.size(); i++) {
293 out_ << " " << tool_->lib_dir_switch(); 296 out_ << " " << tool_->lib_dir_switch();
294 lib_path_output.WriteDir(out_, all_lib_dirs[i], 297 lib_path_output.WriteDir(out_, all_lib_dirs[i],
295 PathOutput::DIR_NO_LAST_SLASH); 298 PathOutput::DIR_NO_LAST_SLASH);
296 } 299 }
297 } 300 }
298 out_ << std::endl; 301 out_ << std::endl;
299 } 302 }
300 303
(...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). 471 return false; // No tool for this file (it's a header file or something).
469 const Tool* tool = target->toolchain()->GetTool(*computed_tool_type); 472 const Tool* tool = target->toolchain()->GetTool(*computed_tool_type);
470 if (!tool) 473 if (!tool)
471 return false; // Tool does not apply for this toolchain.file. 474 return false; // Tool does not apply for this toolchain.file.
472 475
473 // Figure out what output(s) this compiler produces. 476 // Figure out what output(s) this compiler produces.
474 SubstitutionWriter::ApplyListToCompilerAsOutputFile( 477 SubstitutionWriter::ApplyListToCompilerAsOutputFile(
475 target, source, tool->outputs(), outputs); 478 target, source, tool->outputs(), outputs);
476 return !outputs->empty(); 479 return !outputs->empty();
477 } 480 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698