Add module_deps[_no_self] to the default test toolchain

This should make test cases involving modules more reliable, as they
would otherwise show incorrect output.

Change-Id: I275e80534b4377154f1b7218e7c1c3976a6a6964
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/22880
Reviewed-by: Takuto Ikuta <tikuta@google.com>
Commit-Queue: Matt Stark <msta@google.com>
diff --git a/src/gn/compile_commands_writer_unittest.cc b/src/gn/compile_commands_writer_unittest.cc
index b4aa2b5..7987080 100644
--- a/src/gn/compile_commands_writer_unittest.cc
+++ b/src/gn/compile_commands_writer_unittest.cc
@@ -77,13 +77,13 @@
         "  {\r\n"
         "    \"file\": \"../../foo/input1.cc\",\r\n"
         "    \"directory\": \"out/Debug\",\r\n"
-        "    \"command\": \"c++ ../../foo/input1.cc     -o  "
+        "    \"command\": \"c++ ../../foo/input1.cc      -o  "
         "obj/foo/bar.input1.o\"\r\n"
         "  },\r\n"
         "  {\r\n"
         "    \"file\": \"../../foo/input2.cc\",\r\n"
         "    \"directory\": \"out/Debug\",\r\n"
-        "    \"command\": \"c++ ../../foo/input2.cc     -o  "
+        "    \"command\": \"c++ ../../foo/input2.cc      -o  "
         "obj/foo/bar.input2.o\"\r\n"
         "  }\r\n"
         "]\r\n";
@@ -93,13 +93,13 @@
         "  {\n"
         "    \"file\": \"../../foo/input1.cc\",\n"
         "    \"directory\": \"out/Debug\",\n"
-        "    \"command\": \"c++ ../../foo/input1.cc     -o  "
+        "    \"command\": \"c++ ../../foo/input1.cc      -o  "
         "obj/foo/bar.input1.o\"\n"
         "  },\n"
         "  {\n"
         "    \"file\": \"../../foo/input2.cc\",\n"
         "    \"directory\": \"out/Debug\",\n"
-        "    \"command\": \"c++ ../../foo/input2.cc     -o  "
+        "    \"command\": \"c++ ../../foo/input2.cc      -o  "
         "obj/foo/bar.input2.o\"\n"
         "  }\n"
         "]\n";
@@ -126,19 +126,19 @@
         "  {\r\n"
         "    \"file\": \"../../foo/input1.cc\",\r\n"
         "    \"directory\": \"out/Debug\",\r\n"
-        "    \"command\": \"c++ ../../foo/input1.cc     -o  "
+        "    \"command\": \"c++ ../../foo/input1.cc      -o  "
         "obj/foo/bar.input1.o\"\r\n"
         "  },\r\n"
         "  {\r\n"
         "    \"file\": \"../../foo/input2.cc\",\r\n"
         "    \"directory\": \"out/Debug\",\r\n"
-        "    \"command\": \"c++ ../../foo/input2.cc     -o  "
+        "    \"command\": \"c++ ../../foo/input2.cc      -o  "
         "obj/foo/bar.input2.o\"\r\n"
         "  },\r\n"
         "  {\r\n"
         "    \"file\": \"../../foo/input3.cc\",\r\n"
         "    \"directory\": \"out/Debug\",\r\n"
-        "    \"command\": \"c++ ../../foo/input3.cc     -o  "
+        "    \"command\": \"c++ ../../foo/input3.cc      -o  "
         "obj/foo/libshlib.input3.o\"\r\n"
         "  }\r\n"
         "]\r\n";
@@ -148,19 +148,19 @@
         "  {\n"
         "    \"file\": \"../../foo/input1.cc\",\n"
         "    \"directory\": \"out/Debug\",\n"
-        "    \"command\": \"c++ ../../foo/input1.cc     -o  "
+        "    \"command\": \"c++ ../../foo/input1.cc      -o  "
         "obj/foo/bar.input1.o\"\n"
         "  },\n"
         "  {\n"
         "    \"file\": \"../../foo/input2.cc\",\n"
         "    \"directory\": \"out/Debug\",\n"
-        "    \"command\": \"c++ ../../foo/input2.cc     -o  "
+        "    \"command\": \"c++ ../../foo/input2.cc      -o  "
         "obj/foo/bar.input2.o\"\n"
         "  },\n"
         "  {\n"
         "    \"file\": \"../../foo/input3.cc\",\n"
         "    \"directory\": \"out/Debug\",\n"
-        "    \"command\": \"c++ ../../foo/input3.cc     -o  "
+        "    \"command\": \"c++ ../../foo/input3.cc      -o  "
         "obj/foo/libshlib.input3.o\"\n"
         "  }\n"
         "]\n";
@@ -187,25 +187,25 @@
         "  {\r\n"
         "    \"file\": \"../../foo/input1.cc\",\r\n"
         "    \"directory\": \"out/Debug\",\r\n"
-        "    \"command\": \"c++ ../../foo/input1.cc     -o  "
+        "    \"command\": \"c++ ../../foo/input1.cc      -o  "
         "obj/foo/bar.input1.o\"\r\n"
         "  },\r\n"
         "  {\r\n"
         "    \"file\": \"../../foo/input2.cc\",\r\n"
         "    \"directory\": \"out/Debug\",\r\n"
-        "    \"command\": \"c++ ../../foo/input2.cc     -o  "
+        "    \"command\": \"c++ ../../foo/input2.cc      -o  "
         "obj/foo/bar.input2.o\"\r\n"
         "  },\r\n"
         "  {\r\n"
         "    \"file\": \"../../foo/input3.cc\",\r\n"
         "    \"directory\": \"out/Debug\",\r\n"
-        "    \"command\": \"c++ ../../foo/input3.cc     -o  "
+        "    \"command\": \"c++ ../../foo/input3.cc      -o  "
         "obj/foo/libshlib.input3.o\"\r\n"
         "  },\r\n"
         "  {\r\n"
         "    \"file\": \"../../foo/input4.cc\",\r\n"
         "    \"directory\": \"out/Debug\",\r\n"
-        "    \"command\": \"c++ ../../foo/input4.cc     -o  "
+        "    \"command\": \"c++ ../../foo/input4.cc      -o  "
         "obj/foo/libstlib.input4.o\"\r\n"
         "  }\r\n"
         "]\r\n";
@@ -215,25 +215,25 @@
         "  {\n"
         "    \"file\": \"../../foo/input1.cc\",\n"
         "    \"directory\": \"out/Debug\",\n"
-        "    \"command\": \"c++ ../../foo/input1.cc     -o  "
+        "    \"command\": \"c++ ../../foo/input1.cc      -o  "
         "obj/foo/bar.input1.o\"\n"
         "  },\n"
         "  {\n"
         "    \"file\": \"../../foo/input2.cc\",\n"
         "    \"directory\": \"out/Debug\",\n"
-        "    \"command\": \"c++ ../../foo/input2.cc     -o  "
+        "    \"command\": \"c++ ../../foo/input2.cc      -o  "
         "obj/foo/bar.input2.o\"\n"
         "  },\n"
         "  {\n"
         "    \"file\": \"../../foo/input3.cc\",\n"
         "    \"directory\": \"out/Debug\",\n"
-        "    \"command\": \"c++ ../../foo/input3.cc     -o  "
+        "    \"command\": \"c++ ../../foo/input3.cc      -o  "
         "obj/foo/libshlib.input3.o\"\n"
         "  },\n"
         "  {\n"
         "    \"file\": \"../../foo/input4.cc\",\n"
         "    \"directory\": \"out/Debug\",\n"
-        "    \"command\": \"c++ ../../foo/input4.cc     -o  "
+        "    \"command\": \"c++ ../../foo/input4.cc      -o  "
         "obj/foo/libstlib.input4.o\"\n"
         "  }\n"
         "]\n";
diff --git a/src/gn/json_project_writer_unittest.cc b/src/gn/json_project_writer_unittest.cc
index 6c43cc7..88b2842 100644
--- a/src/gn/json_project_writer_unittest.cc
+++ b/src/gn/json_project_writer_unittest.cc
@@ -120,7 +120,7 @@
             "command": "cp {{source}} {{output}}"
          },
          "cxx": {
-            "command": "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} -o {{output}}",
+            "command": "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} {{module_deps}} -o {{output}}",
             "command_launcher": "launcher",
             "framework_dir_switch": "-F",
             "framework_switch": "-framework ",
@@ -130,7 +130,7 @@
             "weak_framework_switch": "-weak_framework "
          },
          "cxx_module": {
-            "command": "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} -o {{output}}",
+            "command": "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} {{module_deps_no_self}} -o {{output}}",
             "framework_dir_switch": "-F",
             "framework_switch": "-framework ",
             "lib_dir_switch": "-L",
@@ -360,7 +360,7 @@
             "command": "cp {{source}} {{output}}"
          },
          "cxx": {
-            "command": "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} -o {{output}}",
+            "command": "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} {{module_deps}} -o {{output}}",
             "command_launcher": "launcher",
             "framework_dir_switch": "-F",
             "framework_switch": "-framework ",
@@ -370,7 +370,7 @@
             "weak_framework_switch": "-weak_framework "
          },
          "cxx_module": {
-            "command": "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} -o {{output}}",
+            "command": "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} {{module_deps_no_self}} -o {{output}}",
             "framework_dir_switch": "-F",
             "framework_switch": "-framework ",
             "lib_dir_switch": "-L",
@@ -624,7 +624,7 @@
             "command": "cp {{source}} {{output}}"
          },
          "cxx": {
-            "command": "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} -o {{output}}",
+            "command": "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} {{module_deps}} -o {{output}}",
             "command_launcher": "launcher",
             "framework_dir_switch": "-F",
             "framework_switch": "-framework ",
@@ -634,7 +634,7 @@
             "weak_framework_switch": "-weak_framework "
          },
          "cxx_module": {
-            "command": "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} -o {{output}}",
+            "command": "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} {{module_deps_no_self}} -o {{output}}",
             "framework_dir_switch": "-F",
             "framework_switch": "-framework ",
             "lib_dir_switch": "-L",
diff --git a/src/gn/ninja_c_binary_target_writer_unittest.cc b/src/gn/ninja_c_binary_target_writer_unittest.cc
index 73ffbeb..34a473f 100644
--- a/src/gn/ninja_c_binary_target_writer_unittest.cc
+++ b/src/gn/ninja_c_binary_target_writer_unittest.cc
@@ -2718,6 +2718,9 @@
       "include_dirs =\n"
       "cflags =\n"
       "cflags_cc =\n"
+      "module_deps = -fmodule-map-file=../../foo/bar.modulemap "
+      "-fmodule-file=//foo:bar=obj/foo/libbar.bar.pcm\n"
+      "module_deps_no_self = -fmodule-map-file=../../foo/bar.modulemap\n"
       "root_out_dir = .\n"
       "target_gen_dir = gen/foo\n"
       "target_out_dir = obj/foo\n"
@@ -2760,6 +2763,9 @@
       "include_dirs =\n"
       "cflags =\n"
       "cflags_cc =\n"
+      "module_deps = -fmodule-map-file=../../foo/bar.modulemap "
+      "-fmodule-file=//foo:bar=obj/foo/bar.bar.pcm\n"
+      "module_deps_no_self = -fmodule-map-file=../../foo/bar.modulemap\n"
       "root_out_dir = .\n"
       "target_gen_dir = gen/foo\n"
       "target_out_dir = obj/foo\n"
@@ -3430,6 +3436,8 @@
       "include_dirs =\n"
       "cflags =\n"
       "cflags_cc =\n"
+      "module_deps = -fmodule-map-file=gen/foo/bar.private.modulemap\n"
+      "module_deps_no_self = -fmodule-map-file=gen/foo/bar.private.modulemap\n"
       "root_out_dir = .\n"
       "target_gen_dir = gen/foo\n"
       "target_out_dir = obj/foo\n"
diff --git a/src/gn/ninja_toolchain_writer_unittest.cc b/src/gn/ninja_toolchain_writer_unittest.cc
index 7c46dcd..ba58326 100644
--- a/src/gn/ninja_toolchain_writer_unittest.cc
+++ b/src/gn/ninja_toolchain_writer_unittest.cc
@@ -34,7 +34,7 @@
   EXPECT_EQ(
       "rule prefix_cxx\n"
       "  command = launcher c++ ${in} ${cflags} ${cflags_cc} ${defines} "
-      "${include_dirs} "
+      "${include_dirs} ${module_deps} "
       "-o ${out}\n",
       stream.str());
 }
diff --git a/src/gn/test_with_scope.cc b/src/gn/test_with_scope.cc
index 98a021f..ae5bc32 100644
--- a/src/gn/test_with_scope.cc
+++ b/src/gn/test_with_scope.cc
@@ -102,6 +102,7 @@
   std::unique_ptr<Tool> cxx_tool = Tool::CreateTool(CTool::kCToolCxx);
   SetCommandForTool(
       "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} "
+      "{{module_deps}} "
       "-o {{output}}",
       cxx_tool.get());
   cxx_tool->set_outputs(SubstitutionList::MakeForTest(
@@ -114,6 +115,7 @@
       Tool::CreateTool(CTool::kCToolCxxModule);
   SetCommandForTool(
       "c++ {{source}} {{cflags}} {{cflags_cc}} {{defines}} {{include_dirs}} "
+      "{{module_deps_no_self}} "
       "-o {{output}}",
       cxx_module_tool.get());
   cxx_module_tool->set_outputs(SubstitutionList::MakeForTest(