Avoid trailing slashes for directory in compilation database

This is breaking some clients which don't handle these. Other tools
seem to be omitting trailing slashes in compilation database as well.

Change-Id: I6e74e06df75c13ba5f783ee1d3bd953e2db9fa28
Reviewed-on: https://gn-review.googlesource.com/2640
Reviewed-by: Roland McGrath <mcgrathr@google.com>
Commit-Queue: Petr Hosek <phosek@google.com>
diff --git a/tools/gn/compile_commands_writer.cc b/tools/gn/compile_commands_writer.cc
index 6e31b23..0a545e8 100644
--- a/tools/gn/compile_commands_writer.cc
+++ b/tools/gn/compile_commands_writer.cc
@@ -205,7 +205,8 @@
   compile_commands->append("[");
   compile_commands->append(kPrettyPrintLineEnding);
   bool first = true;
-  auto build_dir = build_settings->GetFullPath(build_settings->build_dir());
+  auto build_dir = build_settings->GetFullPath(build_settings->build_dir())
+                       .StripTrailingSeparators();
   std::vector<OutputFile> tool_outputs;  // Prevent reallocation in loop.
 
   EscapeOptions opts;
diff --git a/tools/gn/compile_commands_writer_unittest.cc b/tools/gn/compile_commands_writer_unittest.cc
index 57c89dc..b162ba5 100644
--- a/tools/gn/compile_commands_writer_unittest.cc
+++ b/tools/gn/compile_commands_writer_unittest.cc
@@ -63,13 +63,13 @@
         "[\r\n"
         "  {\r\n"
         "    \"file\": \"../../foo/input1.cc\",\r\n"
-        "    \"directory\": \"out/Debug/\",\r\n"
+        "    \"directory\": \"out/Debug\",\r\n"
         "    \"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"
+        "    \"directory\": \"out/Debug\",\r\n"
         "    \"command\": \"c++ ../../foo/input2.cc     -o  "
         "obj/foo/bar.input2.o\"\r\n"
         "  }\r\n"
@@ -79,13 +79,13 @@
         "[\n"
         "  {\n"
         "    \"file\": \"../../foo/input1.cc\",\n"
-        "    \"directory\": \"out/Debug/\",\n"
+        "    \"directory\": \"out/Debug\",\n"
         "    \"command\": \"c++ ../../foo/input1.cc     -o  "
         "obj/foo/bar.input1.o\"\n"
         "  },\n"
         "  {\n"
         "    \"file\": \"../../foo/input2.cc\",\n"
-        "    \"directory\": \"out/Debug/\",\n"
+        "    \"directory\": \"out/Debug\",\n"
         "    \"command\": \"c++ ../../foo/input2.cc     -o  "
         "obj/foo/bar.input2.o\"\n"
         "  }\n"
@@ -113,19 +113,19 @@
         "[\r\n"
         "  {\r\n"
         "    \"file\": \"../../foo/input1.cc\",\r\n"
-        "    \"directory\": \"out/Debug/\",\r\n"
+        "    \"directory\": \"out/Debug\",\r\n"
         "    \"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"
+        "    \"directory\": \"out/Debug\",\r\n"
         "    \"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"
+        "    \"directory\": \"out/Debug\",\r\n"
         "    \"command\": \"c++ ../../foo/input3.cc     -o  "
         "obj/foo/libshlib.input3.o\"\r\n"
         "  }\r\n"
@@ -135,19 +135,19 @@
         "[\n"
         "  {\n"
         "    \"file\": \"../../foo/input1.cc\",\n"
-        "    \"directory\": \"out/Debug/\",\n"
+        "    \"directory\": \"out/Debug\",\n"
         "    \"command\": \"c++ ../../foo/input1.cc     -o  "
         "obj/foo/bar.input1.o\"\n"
         "  },\n"
         "  {\n"
         "    \"file\": \"../../foo/input2.cc\",\n"
-        "    \"directory\": \"out/Debug/\",\n"
+        "    \"directory\": \"out/Debug\",\n"
         "    \"command\": \"c++ ../../foo/input2.cc     -o  "
         "obj/foo/bar.input2.o\"\n"
         "  },\n"
         "  {\n"
         "    \"file\": \"../../foo/input3.cc\",\n"
-        "    \"directory\": \"out/Debug/\",\n"
+        "    \"directory\": \"out/Debug\",\n"
         "    \"command\": \"c++ ../../foo/input3.cc     -o  "
         "obj/foo/libshlib.input3.o\"\n"
         "  }\n"
@@ -175,25 +175,25 @@
         "[\r\n"
         "  {\r\n"
         "    \"file\": \"../../foo/input1.cc\",\r\n"
-        "    \"directory\": \"out/Debug/\",\r\n"
+        "    \"directory\": \"out/Debug\",\r\n"
         "    \"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"
+        "    \"directory\": \"out/Debug\",\r\n"
         "    \"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"
+        "    \"directory\": \"out/Debug\",\r\n"
         "    \"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"
+        "    \"directory\": \"out/Debug\",\r\n"
         "    \"command\": \"c++ ../../foo/input4.cc     -o  "
         "obj/foo/libstlib.input4.o\"\r\n"
         "  }\r\n"
@@ -203,25 +203,25 @@
         "[\n"
         "  {\n"
         "    \"file\": \"../../foo/input1.cc\",\n"
-        "    \"directory\": \"out/Debug/\",\n"
+        "    \"directory\": \"out/Debug\",\n"
         "    \"command\": \"c++ ../../foo/input1.cc     -o  "
         "obj/foo/bar.input1.o\"\n"
         "  },\n"
         "  {\n"
         "    \"file\": \"../../foo/input2.cc\",\n"
-        "    \"directory\": \"out/Debug/\",\n"
+        "    \"directory\": \"out/Debug\",\n"
         "    \"command\": \"c++ ../../foo/input2.cc     -o  "
         "obj/foo/bar.input2.o\"\n"
         "  },\n"
         "  {\n"
         "    \"file\": \"../../foo/input3.cc\",\n"
-        "    \"directory\": \"out/Debug/\",\n"
+        "    \"directory\": \"out/Debug\",\n"
         "    \"command\": \"c++ ../../foo/input3.cc     -o  "
         "obj/foo/libshlib.input3.o\"\n"
         "  },\n"
         "  {\n"
         "    \"file\": \"../../foo/input4.cc\",\n"
-        "    \"directory\": \"out/Debug/\",\n"
+        "    \"directory\": \"out/Debug\",\n"
         "    \"command\": \"c++ ../../foo/input4.cc     -o  "
         "obj/foo/libstlib.input4.o\"\n"
         "  }\n"
@@ -309,13 +309,13 @@
         "[\r\n"
         "  {\r\n"
         "    \"file\": \"../../foo/input1.cc\",\r\n"
-        "    \"directory\": \"out/Debug/\",\r\n"
+        "    \"directory\": \"out/Debug\",\r\n"
         "    \"command\": \"c++ ../../foo/input1.cc     -o  "
         "withpch/obj/foo/no_pch_target.input1.o\"\r\n"
         "  },\r\n"
         "  {\r\n"
         "    \"file\": \"../../foo/input2.c\",\r\n"
-        "    \"directory\": \"out/Debug/\",\r\n"
+        "    \"directory\": \"out/Debug\",\r\n"
         "    \"command\": \"cc ../../foo/input2.c   -std=c99   -o  "
         "withpch/obj/foo/no_pch_target.input2.o\"\r\n"
         "  }\r\n"
@@ -325,13 +325,13 @@
         "[\n"
         "  {\n"
         "    \"file\": \"../../foo/input1.cc\",\n"
-        "    \"directory\": \"out/Debug/\",\n"
+        "    \"directory\": \"out/Debug\",\n"
         "    \"command\": \"c++ ../../foo/input1.cc     -o  "
         "withpch/obj/foo/no_pch_target.input1.o\"\n"
         "  },\n"
         "  {\n"
         "    \"file\": \"../../foo/input2.c\",\n"
-        "    \"directory\": \"out/Debug/\",\n"
+        "    \"directory\": \"out/Debug\",\n"
         "    \"command\": \"cc ../../foo/input2.c   -std=c99   -o  "
         "withpch/obj/foo/no_pch_target.input2.o\"\n"
         "  }\n"
@@ -364,14 +364,14 @@
         "[\r\n"
         "  {\r\n"
         "    \"file\": \"../../foo/input1.cc\",\r\n"
-        "    \"directory\": \"out/Debug/\",\r\n"
+        "    \"directory\": \"out/Debug\",\r\n"
         "    \"command\": \"c++ ../../foo/input1.cc   "
         "/Fpwithpch/obj/foo/pch_target_cc.pch /Yubuild/precompile.h   -o  "
         "withpch/obj/foo/pch_target.input1.o\"\r\n"
         "  },\r\n"
         "  {\r\n"
         "    \"file\": \"../../foo/input2.c\",\r\n"
-        "    \"directory\": \"out/Debug/\",\r\n"
+        "    \"directory\": \"out/Debug\",\r\n"
         "    \"command\": \"cc ../../foo/input2.c   "
         "/Fpwithpch/obj/foo/pch_target_c.pch /Yubuild/precompile.h   -o  "
         "withpch/obj/foo/pch_target.input2.o\"\r\n"
@@ -382,14 +382,14 @@
         "[\n"
         "  {\n"
         "    \"file\": \"../../foo/input1.cc\",\n"
-        "    \"directory\": \"out/Debug/\",\n"
+        "    \"directory\": \"out/Debug\",\n"
         "    \"command\": \"c++ ../../foo/input1.cc   "
         "/Fpwithpch/obj/foo/pch_target_cc.pch /Yubuild/precompile.h   -o  "
         "withpch/obj/foo/pch_target.input1.o\"\n"
         "  },\n"
         "  {\n"
         "    \"file\": \"../../foo/input2.c\",\n"
-        "    \"directory\": \"out/Debug/\",\n"
+        "    \"directory\": \"out/Debug\",\n"
         "    \"command\": \"cc ../../foo/input2.c   "
         "/Fpwithpch/obj/foo/pch_target_c.pch /Yubuild/precompile.h   -o  "
         "withpch/obj/foo/pch_target.input2.o\"\n"
@@ -458,13 +458,13 @@
         "[\r\n"
         "  {\r\n"
         "    \"file\": \"../../foo/input1.cc\",\r\n"
-        "    \"directory\": \"out/Debug/\",\r\n"
+        "    \"directory\": \"out/Debug\",\r\n"
         "    \"command\": \"c++ ../../foo/input1.cc     -o  "
         "withpch/obj/foo/no_pch_target.input1.o\"\r\n"
         "  },\r\n"
         "  {\r\n"
         "    \"file\": \"../../foo/input2.c\",\r\n"
-        "    \"directory\": \"out/Debug/\",\r\n"
+        "    \"directory\": \"out/Debug\",\r\n"
         "    \"command\": \"cc ../../foo/input2.c   -std=c99   -o  "
         "withpch/obj/foo/no_pch_target.input2.o\"\r\n"
         "  }\r\n"
@@ -474,13 +474,13 @@
         "[\n"
         "  {\n"
         "    \"file\": \"../../foo/input1.cc\",\n"
-        "    \"directory\": \"out/Debug/\",\n"
+        "    \"directory\": \"out/Debug\",\n"
         "    \"command\": \"c++ ../../foo/input1.cc     -o  "
         "withpch/obj/foo/no_pch_target.input1.o\"\n"
         "  },\n"
         "  {\n"
         "    \"file\": \"../../foo/input2.c\",\n"
-        "    \"directory\": \"out/Debug/\",\n"
+        "    \"directory\": \"out/Debug\",\n"
         "    \"command\": \"cc ../../foo/input2.c   -std=c99   -o  "
         "withpch/obj/foo/no_pch_target.input2.o\"\n"
         "  }\n"
@@ -513,14 +513,14 @@
         "[\r\n"
         "  {\r\n"
         "    \"file\": \"../../foo/input1.cc\",\r\n"
-        "    \"directory\": \"out/Debug/\",\r\n"
+        "    \"directory\": \"out/Debug\",\r\n"
         "    \"command\": \"c++ ../../foo/input1.cc   -include "
         "withpch/obj/build/pch_target.precompile.h-cc   -o  "
         "withpch/obj/foo/pch_target.input1.o\"\r\n"
         "  },\r\n"
         "  {\r\n"
         "    \"file\": \"../../foo/input2.c\",\r\n"
-        "    \"directory\": \"out/Debug/\",\r\n"
+        "    \"directory\": \"out/Debug\",\r\n"
         "    \"command\": \"cc ../../foo/input2.c   -std=c99 -include "
         "withpch/obj/build/pch_target.precompile.h-c   -o  "
         "withpch/obj/foo/pch_target.input2.o\"\r\n"
@@ -531,14 +531,14 @@
         "[\n"
         "  {\n"
         "    \"file\": \"../../foo/input1.cc\",\n"
-        "    \"directory\": \"out/Debug/\",\n"
+        "    \"directory\": \"out/Debug\",\n"
         "    \"command\": \"c++ ../../foo/input1.cc   -include "
         "withpch/obj/build/pch_target.precompile.h-cc   -o  "
         "withpch/obj/foo/pch_target.input1.o\"\n"
         "  },\n"
         "  {\n"
         "    \"file\": \"../../foo/input2.c\",\n"
-        "    \"directory\": \"out/Debug/\",\n"
+        "    \"directory\": \"out/Debug\",\n"
         "    \"command\": \"cc ../../foo/input2.c   -std=c99 -include "
         "withpch/obj/build/pch_target.precompile.h-c   -o  "
         "withpch/obj/foo/pch_target.input2.o\"\n"
@@ -570,7 +570,7 @@
       "[\r\n"
       "  {\r\n"
       "    \"file\": \"../../foo/input1.c\",\r\n"
-      "    \"directory\": \"out/Debug/\",\r\n"
+      "    \"directory\": \"out/Debug\",\r\n"
       "    \"command\": \"cc ../../foo/input1.c   -DCONFIG=\\\"/config\\\"   "
       "-o  obj/foo/bar.input1.o\"\r\n"
       "  }\r\n"
@@ -580,7 +580,7 @@
       "[\n"
       "  {\n"
       "    \"file\": \"../../foo/input1.c\",\n"
-      "    \"directory\": \"out/Debug/\",\n"
+      "    \"directory\": \"out/Debug\",\n"
       "    \"command\": \"cc ../../foo/input1.c   -DCONFIG=\\\"/config\\\"   "
       "-o  obj/foo/bar.input1.o\"\n"
       "  }\n"