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 <cstring> | 7 #include <cstring> |
8 #include <set> | 8 #include <set> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
| 11 #include "base/containers/hash_tables.h" |
11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
12 #include "tools/gn/config_values_extractors.h" | 13 #include "tools/gn/config_values_extractors.h" |
13 #include "tools/gn/deps_iterator.h" | 14 #include "tools/gn/deps_iterator.h" |
14 #include "tools/gn/err.h" | 15 #include "tools/gn/err.h" |
15 #include "tools/gn/escape.h" | 16 #include "tools/gn/escape.h" |
16 #include "tools/gn/filesystem_utils.h" | 17 #include "tools/gn/filesystem_utils.h" |
17 #include "tools/gn/ninja_utils.h" | 18 #include "tools/gn/ninja_utils.h" |
| 19 #include "tools/gn/scheduler.h" |
18 #include "tools/gn/settings.h" | 20 #include "tools/gn/settings.h" |
19 #include "tools/gn/source_file_type.h" | 21 #include "tools/gn/source_file_type.h" |
20 #include "tools/gn/string_utils.h" | 22 #include "tools/gn/string_utils.h" |
21 #include "tools/gn/substitution_writer.h" | 23 #include "tools/gn/substitution_writer.h" |
22 #include "tools/gn/target.h" | 24 #include "tools/gn/target.h" |
23 | 25 |
24 // Represents a set of tool types. Must be first since it is also shared by | 26 // Represents a set of tool types. Must be first since it is also shared by |
25 // some helper functions in the anonymous namespace below. | 27 // some helper functions in the anonymous namespace below. |
26 class NinjaBinaryTargetWriter::SourceFileTypeSet { | 28 class NinjaBinaryTargetWriter::SourceFileTypeSet { |
27 public: | 29 public: |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 // precompiled header compile step (it outputs both the .pch file and a | 289 // precompiled header compile step (it outputs both the .pch file and a |
288 // corresponding .obj file). So we consistently list the .obj file and the | 290 // corresponding .obj file). So we consistently list the .obj file and the |
289 // .pch file we really need comes along with it. | 291 // .pch file we really need comes along with it. |
290 std::vector<OutputFile> obj_files; | 292 std::vector<OutputFile> obj_files; |
291 std::vector<SourceFile> other_files; | 293 std::vector<SourceFile> other_files; |
292 WriteSources(pch_obj_files, order_only_dep, &obj_files, &other_files); | 294 WriteSources(pch_obj_files, order_only_dep, &obj_files, &other_files); |
293 | 295 |
294 // Also link all pch object files. | 296 // Also link all pch object files. |
295 obj_files.insert(obj_files.end(), pch_obj_files.begin(), pch_obj_files.end()); | 297 obj_files.insert(obj_files.end(), pch_obj_files.begin(), pch_obj_files.end()); |
296 | 298 |
| 299 if (!CheckForDuplicateObjectFiles(obj_files)) |
| 300 return; |
| 301 |
297 if (target_->output_type() == Target::SOURCE_SET) { | 302 if (target_->output_type() == Target::SOURCE_SET) { |
298 WriteSourceSetStamp(obj_files); | 303 WriteSourceSetStamp(obj_files); |
299 #ifndef NDEBUG | 304 #ifndef NDEBUG |
300 // Verify that the function that separately computes a source set's object | 305 // Verify that the function that separately computes a source set's object |
301 // files match the object files just computed. | 306 // files match the object files just computed. |
302 UniqueVector<OutputFile> computed_obj; | 307 UniqueVector<OutputFile> computed_obj; |
303 AddSourceSetObjectFiles(target_, &computed_obj); | 308 AddSourceSetObjectFiles(target_, &computed_obj); |
304 DCHECK_EQ(obj_files.size(), computed_obj.size()); | 309 DCHECK_EQ(obj_files.size(), computed_obj.size()); |
305 for (const auto& obj : obj_files) | 310 for (const auto& obj : obj_files) |
306 DCHECK_NE(static_cast<size_t>(-1), computed_obj.IndexOf(obj)); | 311 DCHECK_NE(static_cast<size_t>(-1), computed_obj.IndexOf(obj)); |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 // Use "obj/{dir}/{target_name}_{lang}.pch" which ends up | 789 // Use "obj/{dir}/{target_name}_{lang}.pch" which ends up |
785 // looking like "obj/chrome/browser/browser.cc.pch" | 790 // looking like "obj/chrome/browser/browser.cc.pch" |
786 OutputFile ret = GetTargetOutputDirAsOutputFile(target_); | 791 OutputFile ret = GetTargetOutputDirAsOutputFile(target_); |
787 ret.value().append(target_->label().name()); | 792 ret.value().append(target_->label().name()); |
788 ret.value().push_back('_'); | 793 ret.value().push_back('_'); |
789 ret.value().append(GetPCHLangForToolType(tool_type)); | 794 ret.value().append(GetPCHLangForToolType(tool_type)); |
790 ret.value().append(".pch"); | 795 ret.value().append(".pch"); |
791 | 796 |
792 return ret; | 797 return ret; |
793 } | 798 } |
| 799 |
| 800 bool NinjaBinaryTargetWriter::CheckForDuplicateObjectFiles( |
| 801 const std::vector<OutputFile>& files) const { |
| 802 base::hash_set<std::string> set; |
| 803 for (const auto& file : files) { |
| 804 if (!set.insert(file.value()).second) { |
| 805 Err err( |
| 806 target_->defined_from(), |
| 807 "Duplicate object file", |
| 808 "The target " + target_->label().GetUserVisibleName(false) + |
| 809 "\ngenerates two object files with the same name:\n " + |
| 810 file.value() + "\n" |
| 811 "\n" |
| 812 "It could be you accidentally have a file listed twice in the\n" |
| 813 "sources. Or, depending on how your toolchain maps sources to\n" |
| 814 "object files, two source files with the same name in different\n" |
| 815 "directories could map to the same object file.\n" |
| 816 "\n" |
| 817 "In the latter case, either rename one of the files or move one of\n" |
| 818 "the sources to a separate source_set to avoid them both being in\n" |
| 819 "the same target."); |
| 820 g_scheduler->FailWithError(err); |
| 821 return false; |
| 822 } |
| 823 } |
| 824 return true; |
| 825 } |
OLD | NEW |