| 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_build_writer.h" | 5 #include "tools/gn/ninja_build_writer.h" |
| 6 | 6 |
| 7 #include <fstream> | 7 #include <fstream> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 if (dir_string.size() == label.name().size() + 3 && // Size matches. | 184 if (dir_string.size() == label.name().size() + 3 && // Size matches. |
| 185 dir_string[0] == '/' && dir_string[1] == '/' && // "//" at beginning. | 185 dir_string[0] == '/' && dir_string[1] == '/' && // "//" at beginning. |
| 186 dir_string[dir_string.size() - 1] == '/' && // "/" at end. | 186 dir_string[dir_string.size() - 1] == '/' && // "/" at end. |
| 187 dir_string.compare(2, label.name().size(), label.name()) == 0) | 187 dir_string.compare(2, label.name().size(), label.name()) == 0) |
| 188 toplevel_targets.push_back(target); | 188 toplevel_targets.push_back(target); |
| 189 } | 189 } |
| 190 | 190 |
| 191 for (size_t i = 0; i < default_toolchain_targets_.size(); i++) { | 191 for (size_t i = 0; i < default_toolchain_targets_.size(); i++) { |
| 192 const Target* target = default_toolchain_targets_[i]; | 192 const Target* target = default_toolchain_targets_[i]; |
| 193 const Label& label = target->label(); | 193 const Label& label = target->label(); |
| 194 const OutputFile& target_file = target->dependency_output_file(); | 194 OutputFile target_file(target->dependency_output_file()); |
| 195 // The output files may have leading "./" so normalize those away. |
| 196 NormalizePath(&target_file.value()); |
| 195 | 197 |
| 196 // Write the long name "foo/bar:baz" for the target "//foo/bar:baz". | 198 // Write the long name "foo/bar:baz" for the target "//foo/bar:baz". |
| 197 std::string long_name = label.GetUserVisibleName(false); | 199 std::string long_name = label.GetUserVisibleName(false); |
| 198 base::TrimString(long_name, "/", &long_name); | 200 base::TrimString(long_name, "/", &long_name); |
| 199 WritePhonyRule(target, target_file, long_name); | 201 WritePhonyRule(target, target_file, long_name); |
| 200 | 202 |
| 201 // Write the directory name with no target name if they match | 203 // Write the directory name with no target name if they match |
| 202 // (e.g. "//foo/bar:bar" -> "foo/bar"). | 204 // (e.g. "//foo/bar:bar" -> "foo/bar"). |
| 203 if (FindLastDirComponent(label.dir()) == label.name()) { | 205 if (FindLastDirComponent(label.dir()) == label.name()) { |
| 204 std::string medium_name = DirectoryWithNoLastSlash(label.dir()); | 206 std::string medium_name = DirectoryWithNoLastSlash(label.dir()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 EscapeOptions ninja_escape; | 245 EscapeOptions ninja_escape; |
| 244 ninja_escape.mode = ESCAPE_NINJA; | 246 ninja_escape.mode = ESCAPE_NINJA; |
| 245 | 247 |
| 246 // Escape for special chars Ninja will handle. | 248 // Escape for special chars Ninja will handle. |
| 247 std::string escaped = EscapeString(phony_name, ninja_escape, NULL); | 249 std::string escaped = EscapeString(phony_name, ninja_escape, NULL); |
| 248 | 250 |
| 249 out_ << "build " << escaped << ": phony "; | 251 out_ << "build " << escaped << ": phony "; |
| 250 path_output_.WriteFile(out_, target_file); | 252 path_output_.WriteFile(out_, target_file); |
| 251 out_ << std::endl; | 253 out_ << std::endl; |
| 252 } | 254 } |
| OLD | NEW |