• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1commit 86087bbf2aa81100e77e44ee4ea096a5d2870088
2Author: chenmudan <chenmudan@huawei.com>
3Date:   Sat Oct 8 20:51:42 2022 +0800
4
5    Revert "Fix output directories for generated source files."
6
7    This reverts commit fd9f2036f26d83f9fcfe93042fb952e5a7fe2167.
8
9diff --git a/src/gn/filesystem_utils.cc b/src/gn/filesystem_utils.cc
10index 7a7078ed..6de3fbdf 100644
11--- a/src/gn/filesystem_utils.cc
12+++ b/src/gn/filesystem_utils.cc
13@@ -1025,25 +1025,10 @@ OutputFile GetSubBuildDirAsOutputFile(const BuildDirContext& context,
14   OutputFile result = GetBuildDirAsOutputFile(context, type);
15
16   if (source_dir.is_source_absolute()) {
17-    std::string_view build_dir = context.build_settings->build_dir().value();
18-    std::string_view source_dir_path = source_dir.value();
19-    if (source_dir_path.substr(0, build_dir.size()) == build_dir) {
20-      // The source dir is source-absolute, but in the build directory
21-      // (e.g. `//out/Debug/gen/src/foo.cc` or
22-      // `//out/Debug/toolchain1/gen/foo.cc`), which happens for generated
23-      // sources. In this case, remove the build directory prefix, and replace
24-      // it with `BUILD_DIR`. This will create results like `obj/BUILD_DIR/gen`
25-      // or `toolchain2/obj/BUILD_DIR/toolchain1/gen` which look surprising,
26-      // but guarantee unicity.
27-      result.value().append("BUILD_DIR/");
28-      result.value().append(&source_dir_path[build_dir.size()],
29-                            source_dir_path.size() - build_dir.size());
30-    } else {
31-      // The source dir is source-absolute, so we trim off the two leading
32-      // slashes to append to the toolchain object directory.
33-      result.value().append(&source_dir.value()[2],
34-                            source_dir.value().size() - 2);
35-    }
36+    // The source dir is source-absolute, so we trim off the two leading
37+    // slashes to append to the toolchain object directory.
38+    result.value().append(&source_dir.value()[2],
39+                          source_dir.value().size() - 2);
40   } else {
41     // System-absolute.
42     AppendFixedAbsolutePathSuffix(context.build_settings, source_dir, &result);
43diff --git a/src/gn/ninja_c_binary_target_writer_unittest.cc b/src/gn/ninja_c_binary_target_writer_unittest.cc
44index 94761931..6056c368 100644
45--- a/src/gn/ninja_c_binary_target_writer_unittest.cc
46+++ b/src/gn/ninja_c_binary_target_writer_unittest.cc
47@@ -405,18 +405,18 @@ TEST_F(NinjaCBinaryTargetWriterTest, NoHardDepsToNoPublicHeaderTarget) {
48       "target_out_dir = obj/foo\n"
49       "target_output_name = gen_obj\n"
50       "\n"
51-      "build obj/BUILD_DIR/gen_obj.generated.o: cxx generated.cc"
52+      "build obj/out/Debug/gen_obj.generated.o: cxx generated.cc"
53       " || obj/foo/generate.stamp\n"
54       "  source_file_part = generated.cc\n"
55       "  source_name_part = generated\n"
56       "\n"
57-      "build obj/foo/gen_obj.stamp: stamp obj/BUILD_DIR/gen_obj.generated.o"
58+      "build obj/foo/gen_obj.stamp: stamp obj/out/Debug/gen_obj.generated.o"
59       // The order-only dependency here is strictly unnecessary since the
60       // sources list this as an order-only dep.
61       " || obj/foo/generate.stamp\n";
62
63   std::string obj_str = obj_out.str();
64-  EXPECT_EQ(std::string(obj_expected), obj_str);
65+  EXPECT_EQ(obj_expected, obj_str);
66
67   // A shared library depends on gen_obj, having corresponding header for
68   // generated obj.
69@@ -442,7 +442,7 @@ TEST_F(NinjaCBinaryTargetWriterTest, NoHardDepsToNoPublicHeaderTarget) {
70       "target_output_name = libgen_lib\n"
71       "\n"
72       "\n"
73-      "build ./libgen_lib.so: solink obj/BUILD_DIR/gen_obj.generated.o"
74+      "build ./libgen_lib.so: solink obj/out/Debug/gen_obj.generated.o"
75       // The order-only dependency here is strictly unnecessary since
76       // obj/out/Debug/gen_obj.generated.o has dependency to
77       // obj/foo/gen_obj.stamp
78diff --git a/src/gn/substitution_writer_unittest.cc b/src/gn/substitution_writer_unittest.cc
79index eaa521ab..fc3c4469 100644
80--- a/src/gn/substitution_writer_unittest.cc
81+++ b/src/gn/substitution_writer_unittest.cc
82@@ -45,12 +45,6 @@ TEST(SubstitutionWriter, ApplyPatternToSource) {
83   SourceFile result = SubstitutionWriter::ApplyPatternToSource(
84       nullptr, setup.settings(), pattern, SourceFile("//foo/bar/myfile.txt"));
85   ASSERT_EQ("//out/Debug/gen/foo/bar/myfile.tmp", result.value());
86-
87-  result = SubstitutionWriter::ApplyPatternToSource(
88-      nullptr, setup.settings(), pattern,
89-      SourceFile("//out/Debug/gen/generated_file.cc"));
90-  ASSERT_EQ("//out/Debug/gen/BUILD_DIR/gen/generated_file.tmp", result.value())
91-      << result.value();
92 }
93
94 TEST(SubstitutionWriter, ApplyPatternToSourceAsOutputFile) {
95