| OLD | NEW |
| 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 | 9 |
| 9 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 10 #include "tools/gn/config_values_extractors.h" | 11 #include "tools/gn/config_values_extractors.h" |
| 11 #include "tools/gn/deps_iterator.h" | 12 #include "tools/gn/deps_iterator.h" |
| 12 #include "tools/gn/err.h" | 13 #include "tools/gn/err.h" |
| 13 #include "tools/gn/escape.h" | 14 #include "tools/gn/escape.h" |
| 14 #include "tools/gn/ninja_utils.h" | 15 #include "tools/gn/ninja_utils.h" |
| 15 #include "tools/gn/settings.h" | 16 #include "tools/gn/settings.h" |
| 16 #include "tools/gn/string_utils.h" | 17 #include "tools/gn/string_utils.h" |
| 17 #include "tools/gn/substitution_writer.h" | 18 #include "tools/gn/substitution_writer.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 45 EscapeOptions options; | 46 EscapeOptions options; |
| 46 }; | 47 }; |
| 47 | 48 |
| 48 struct IncludeWriter { | 49 struct IncludeWriter { |
| 49 IncludeWriter(PathOutput& path_output) : path_output_(path_output) { | 50 IncludeWriter(PathOutput& path_output) : path_output_(path_output) { |
| 50 } | 51 } |
| 51 ~IncludeWriter() { | 52 ~IncludeWriter() { |
| 52 } | 53 } |
| 53 | 54 |
| 54 void operator()(const SourceDir& d, std::ostream& out) const { | 55 void operator()(const SourceDir& d, std::ostream& out) const { |
| 55 out << " -I"; | 56 std::ostringstream path_out; |
| 56 path_output_.WriteDir(out, d, PathOutput::DIR_NO_LAST_SLASH); | 57 path_output_.WriteDir(path_out, d, PathOutput::DIR_NO_LAST_SLASH); |
| 58 const std::string& path = path_out.str(); |
| 59 if (path[0] == '"') |
| 60 out << " \"-I" << path.substr(1); |
| 61 else |
| 62 out << " -I" << path; |
| 57 } | 63 } |
| 58 | 64 |
| 59 PathOutput& path_output_; | 65 PathOutput& path_output_; |
| 60 }; | 66 }; |
| 61 | 67 |
| 62 } // namespace | 68 } // namespace |
| 63 | 69 |
| 64 NinjaBinaryTargetWriter::NinjaBinaryTargetWriter(const Target* target, | 70 NinjaBinaryTargetWriter::NinjaBinaryTargetWriter(const Target* target, |
| 65 std::ostream& out) | 71 std::ostream& out) |
| 66 : NinjaTargetWriter(target, out), | 72 : NinjaTargetWriter(target, out), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 89 if (subst.used[SUBSTITUTION_DEFINES]) { | 95 if (subst.used[SUBSTITUTION_DEFINES]) { |
| 90 out_ << kSubstitutionNinjaNames[SUBSTITUTION_DEFINES] << " ="; | 96 out_ << kSubstitutionNinjaNames[SUBSTITUTION_DEFINES] << " ="; |
| 91 RecursiveTargetConfigToStream<std::string>( | 97 RecursiveTargetConfigToStream<std::string>( |
| 92 target_, &ConfigValues::defines, DefineWriter(), out_); | 98 target_, &ConfigValues::defines, DefineWriter(), out_); |
| 93 out_ << std::endl; | 99 out_ << std::endl; |
| 94 } | 100 } |
| 95 | 101 |
| 96 // Include directories. | 102 // Include directories. |
| 97 if (subst.used[SUBSTITUTION_INCLUDE_DIRS]) { | 103 if (subst.used[SUBSTITUTION_INCLUDE_DIRS]) { |
| 98 out_ << kSubstitutionNinjaNames[SUBSTITUTION_INCLUDE_DIRS] << " ="; | 104 out_ << kSubstitutionNinjaNames[SUBSTITUTION_INCLUDE_DIRS] << " ="; |
| 105 PathOutput include_path_output(path_output_.current_dir(), |
| 106 ESCAPE_NINJA_COMMAND); |
| 99 RecursiveTargetConfigToStream<SourceDir>( | 107 RecursiveTargetConfigToStream<SourceDir>( |
| 100 target_, &ConfigValues::include_dirs, | 108 target_, &ConfigValues::include_dirs, |
| 101 IncludeWriter(path_output_), out_); | 109 IncludeWriter(include_path_output), out_); |
| 102 out_ << std::endl; | 110 out_ << std::endl; |
| 103 } | 111 } |
| 104 | 112 |
| 105 // C flags and friends. | 113 // C flags and friends. |
| 106 EscapeOptions flag_escape_options = GetFlagOptions(); | 114 EscapeOptions flag_escape_options = GetFlagOptions(); |
| 107 #define WRITE_FLAGS(name, subst_enum) \ | 115 #define WRITE_FLAGS(name, subst_enum) \ |
| 108 if (subst.used[subst_enum]) { \ | 116 if (subst.used[subst_enum]) { \ |
| 109 out_ << kSubstitutionNinjaNames[subst_enum] << " ="; \ | 117 out_ << kSubstitutionNinjaNames[subst_enum] << " ="; \ |
| 110 RecursiveTargetConfigStringsToStream(target_, &ConfigValues::name, \ | 118 RecursiveTargetConfigStringsToStream(target_, &ConfigValues::name, \ |
| 111 flag_escape_options, out_); \ | 119 flag_escape_options, out_); \ |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 return false; // No tool for this file (it's a header file or something). | 477 return false; // No tool for this file (it's a header file or something). |
| 470 const Tool* tool = target->toolchain()->GetTool(*computed_tool_type); | 478 const Tool* tool = target->toolchain()->GetTool(*computed_tool_type); |
| 471 if (!tool) | 479 if (!tool) |
| 472 return false; // Tool does not apply for this toolchain.file. | 480 return false; // Tool does not apply for this toolchain.file. |
| 473 | 481 |
| 474 // Figure out what output(s) this compiler produces. | 482 // Figure out what output(s) this compiler produces. |
| 475 SubstitutionWriter::ApplyListToCompilerAsOutputFile( | 483 SubstitutionWriter::ApplyListToCompilerAsOutputFile( |
| 476 target, source, tool->outputs(), outputs); | 484 target, source, tool->outputs(), outputs); |
| 477 return !outputs->empty(); | 485 return !outputs->empty(); |
| 478 } | 486 } |
| OLD | NEW |