summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-23 23:12:58 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-23 23:12:58 +0000
commitc9f0540e4207ddd1a462b9e76ddcfe13e3b75b9a (patch)
tree094c3e45b41478dbeb1145c246fa436cda5a40ba /tools
parent7791cf4320968b5d1fde781626dbbf0cf96b8ab5 (diff)
downloadchromium_src-c9f0540e4207ddd1a462b9e76ddcfe13e3b75b9a.zip
chromium_src-c9f0540e4207ddd1a462b9e76ddcfe13e3b75b9a.tar.gz
chromium_src-c9f0540e4207ddd1a462b9e76ddcfe13e3b75b9a.tar.bz2
Fix GN on Windows build and tests.
This adds some logic to find python.exe inside your depot tools. This won't work 100% of the time, but should work for 99% of them. In real life we'll probably have gn in depot_tools and it won't matter. This adds some canonicalization for slashes for some of the unit tests. I'm not sure if this is the best way to run them so I didn't make a helper function. I'm wondering if the slashes should always key off of the build type rather than the current OS type, so an is_win build will always get backslashes. I may work on this next. Fixes copy rules (needed a prefix) Updates some build files that had regressed. Add RC toolchain rule for Windows. BUG= R=scottmg@chromium.org Review URL: https://codereview.chromium.org/24363004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224827 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rw-r--r--tools/gn/ninja_copy_target_writer.cc9
-rw-r--r--tools/gn/ninja_copy_target_writer_unittest.cc21
-rw-r--r--tools/gn/ninja_script_target_writer.cc2
-rw-r--r--tools/gn/ninja_script_target_writer_unittest.cc25
-rw-r--r--tools/gn/secondary/base/BUILD.gn10
-rw-r--r--tools/gn/secondary/base/third_party/nspr/BUILD.gn4
-rw-r--r--tools/gn/secondary/build/config/BUILDCONFIG.gn2
-rw-r--r--tools/gn/secondary/build/toolchain/win/BUILD.gn9
-rw-r--r--tools/gn/setup.cc97
-rw-r--r--tools/gn/setup.h4
-rw-r--r--tools/gn/toolchain.cc3
-rw-r--r--tools/gn/toolchain.h2
12 files changed, 151 insertions, 37 deletions
diff --git a/tools/gn/ninja_copy_target_writer.cc b/tools/gn/ninja_copy_target_writer.cc
index aae8e6d..5de249f 100644
--- a/tools/gn/ninja_copy_target_writer.cc
+++ b/tools/gn/ninja_copy_target_writer.cc
@@ -22,6 +22,9 @@ void NinjaCopyTargetWriter::Run() {
std::vector<OutputFile> output_files;
+ std::string rule_prefix =
+ helper_.GetRulePrefix(target_->settings()->toolchain());
+
for (size_t i = 0; i < target_->sources().size(); i++) {
const SourceFile& input_file = target_->sources()[i];
@@ -35,7 +38,7 @@ void NinjaCopyTargetWriter::Run() {
out_ << "build ";
path_output_.WriteFile(out_, output_file);
- out_ << ": copy ";
+ out_ << ": " << rule_prefix << "copy ";
path_output_.WriteFile(out_, input_file);
out_ << std::endl;
}
@@ -43,9 +46,7 @@ void NinjaCopyTargetWriter::Run() {
// Write out the rule for the target to copy all of them.
out_ << std::endl << "build ";
path_output_.WriteFile(out_, helper_.GetTargetOutputFile(target_));
- out_ << ": "
- << helper_.GetRulePrefix(target_->settings()->toolchain())
- << "stamp";
+ out_ << ": " << rule_prefix << "stamp";
for (size_t i = 0; i < output_files.size(); i++) {
out_ << " ";
path_output_.WriteFile(out_, output_files[i]);
diff --git a/tools/gn/ninja_copy_target_writer_unittest.cc b/tools/gn/ninja_copy_target_writer_unittest.cc
index eb913d9..c31cbd2 100644
--- a/tools/gn/ninja_copy_target_writer_unittest.cc
+++ b/tools/gn/ninja_copy_target_writer_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <algorithm>
#include <sstream>
#include "testing/gtest/include/gtest/gtest.h"
@@ -30,11 +31,15 @@ TEST(NinjaCopyTargetWriter, Run) {
writer.Run();
const char expected_linux[] =
- "build input1.out: copy ../../foo/input1.txt\n"
- "build input2.out: copy ../../foo/input2.txt\n"
+ "build input1.out: tc_copy ../../foo/input1.txt\n"
+ "build input2.out: tc_copy ../../foo/input2.txt\n"
"\n"
"build obj/foo/bar.stamp: tc_stamp input1.out input2.out\n";
- EXPECT_EQ(expected_linux, out.str());
+ std::string out_str = out.str();
+#if defined(OS_WIN)
+ std::replace(out_str.begin(), out_str.end(), '\\', '/');
+#endif
+ EXPECT_EQ(expected_linux, out_str);
}
// Windows.
@@ -48,10 +53,14 @@ TEST(NinjaCopyTargetWriter, Run) {
// TODO(brettw) I think we'll need to worry about backslashes here
// depending if we're on actual Windows or Linux pretending to be Windows.
const char expected_win[] =
- "build input1.out: copy ../../foo/input1.txt\n"
- "build input2.out: copy ../../foo/input2.txt\n"
+ "build input1.out: tc_copy ../../foo/input1.txt\n"
+ "build input2.out: tc_copy ../../foo/input2.txt\n"
"\n"
"build obj/foo/bar.stamp: tc_stamp input1.out input2.out\n";
- EXPECT_EQ(expected_win, out.str());
+ std::string out_str = out.str();
+#if defined(OS_WIN)
+ std::replace(out_str.begin(), out_str.end(), '\\', '/');
+#endif
+ EXPECT_EQ(expected_win, out_str);
}
}
diff --git a/tools/gn/ninja_script_target_writer.cc b/tools/gn/ninja_script_target_writer.cc
index ba0e7a2..e74459c 100644
--- a/tools/gn/ninja_script_target_writer.cc
+++ b/tools/gn/ninja_script_target_writer.cc
@@ -15,7 +15,7 @@ NinjaScriptTargetWriter::NinjaScriptTargetWriter(const Target* target,
: NinjaTargetWriter(target, out),
path_output_no_escaping_(
target->settings()->build_settings()->build_dir(),
- ESCAPE_NONE, true) {
+ ESCAPE_NONE, false) {
}
NinjaScriptTargetWriter::~NinjaScriptTargetWriter() {
diff --git a/tools/gn/ninja_script_target_writer_unittest.cc b/tools/gn/ninja_script_target_writer_unittest.cc
index 2052c74..9fa018e 100644
--- a/tools/gn/ninja_script_target_writer_unittest.cc
+++ b/tools/gn/ninja_script_target_writer_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <algorithm>
#include <sstream>
#include "testing/gtest/include/gtest/gtest.h"
@@ -28,7 +29,11 @@ TEST(NinjaScriptTargetWriter, WriteOutputFilesForBuildLine) {
std::vector<OutputFile> output_files;
writer.WriteOutputFilesForBuildLine(output_template, source, &output_files);
- EXPECT_EQ(" gen/a$ bbar.h gen/bar.cc", out.str());
+ std::string out_str = out.str();
+#if defined(OS_WIN)
+ std::replace(out_str.begin(), out_str.end(), '\\', '/');
+#endif
+ EXPECT_EQ(" gen/a$ bbar.h gen/bar.cc", out_str);
}
TEST(NinjaScriptTargetWriter, WriteArgsSubstitutions) {
@@ -47,8 +52,12 @@ TEST(NinjaScriptTargetWriter, WriteArgsSubstitutions) {
writer.WriteArgsSubstitutions(SourceFile("//foo/b ar.in"), args_template);
+ std::string out_str = out.str();
+#if defined(OS_WIN)
+ std::replace(out_str.begin(), out_str.end(), '\\', '/');
+#endif
EXPECT_EQ(" source = ../../foo/b$ ar.in\n source_name_part = b$ ar\n",
- out.str());
+ out_str);
}
// Tests the "run script over multiple source files" mode.
@@ -95,7 +104,11 @@ TEST(NinjaScriptTargetWriter, InvokeOverSources) {
"\n"
"build obj/foo/bar.stamp: tc_stamp input1.out input2.out\n";
- EXPECT_EQ(expected_linux, out.str());
+ std::string out_str = out.str();
+#if defined(OS_WIN)
+ std::replace(out_str.begin(), out_str.end(), '\\', '/');
+#endif
+ EXPECT_EQ(expected_linux, out_str);
}
// Windows.
@@ -127,6 +140,10 @@ TEST(NinjaScriptTargetWriter, InvokeOverSources) {
" source_name_part = input2\n"
"\n"
"build obj/foo/bar.stamp: tc_stamp input1.out input2.out\n";
- EXPECT_EQ(expected_win, out.str());
+ std::string out_str = out.str();
+#if defined(OS_WIN)
+ std::replace(out_str.begin(), out_str.end(), '\\', '/');
+#endif
+ EXPECT_EQ(expected_win, out_str);
}
}
diff --git a/tools/gn/secondary/base/BUILD.gn b/tools/gn/secondary/base/BUILD.gn
index ca26584..9ef2d8c 100644
--- a/tools/gn/secondary/base/BUILD.gn
+++ b/tools/gn/secondary/base/BUILD.gn
@@ -635,8 +635,6 @@ component("base") {
"win/registry.h",
"win/resource_util.cc",
"win/resource_util.h",
- "win/sampling_profiler.cc",
- "win/sampling_profiler.h",
"win/scoped_bstr.cc",
"win/scoped_bstr.h",
"win/scoped_co_mem.h",
@@ -741,6 +739,7 @@ component("base") {
# Windows.
if (is_win) {
sources -= [
+ "message_loop/message_pump_libevent.cc",
"strings/string16.cc",
# Not using sha1_win.cc because it may have caused a
# regression to page cycler moz.
@@ -791,17 +790,10 @@ component("base") {
"message_loop/message_pump_glib.h",
"message_loop/message_pump_gtk.cc",
"message_loop/message_pump_gtk.h",
- ]
- }
-
- # Non-Mac Unix stuff.
- if (is_mac) { #!is_posix || is_mac) {
- sources -= [
"nix/mime_util_xdg.cc",
"nix/mime_util_xdg.h",
"nix/xdg_util.cc",
"nix/xdg_util.h",
- "third_party/xdg_mime/xdgmime.h",
]
}
}
diff --git a/tools/gn/secondary/base/third_party/nspr/BUILD.gn b/tools/gn/secondary/base/third_party/nspr/BUILD.gn
index 226f3d8..9852f5d 100644
--- a/tools/gn/secondary/base/third_party/nspr/BUILD.gn
+++ b/tools/gn/secondary/base/third_party/nspr/BUILD.gn
@@ -17,4 +17,8 @@ static_library("nspr") {
"prtime.h",
"prtypes.h",
]
+
+ # In GYP this project is part of base, so it uses the base implementation
+ # define. TODO(brettw) rename this define.
+ defines = [ "BASE_IMPLEMENTATION" ]
}
diff --git a/tools/gn/secondary/build/config/BUILDCONFIG.gn b/tools/gn/secondary/build/config/BUILDCONFIG.gn
index 0e3a718..10cb3b3 100644
--- a/tools/gn/secondary/build/config/BUILDCONFIG.gn
+++ b/tools/gn/secondary/build/config/BUILDCONFIG.gn
@@ -104,6 +104,8 @@ linux_sources_filters = [
"*_linux_unittest.h",
"*_linux_unittest.cc",
"*\blinux/*",
+ "*_x11.cc",
+ "*_x11.h",
]
android_sources_filters = [
"*_android.h",
diff --git a/tools/gn/secondary/build/toolchain/win/BUILD.gn b/tools/gn/secondary/build/toolchain/win/BUILD.gn
index f602b0b..6a6d7ca 100644
--- a/tools/gn/secondary/build/toolchain/win/BUILD.gn
+++ b/tools/gn/secondary/build/toolchain/win/BUILD.gn
@@ -40,11 +40,10 @@ toolchain("32") {
# \$proxy \$in \$idlflags
# description = IDL \$in
#}
- #tool("rc") {
- # command = $python_path gyp-win-tool rc-wrapper \$arch rc.exe \$defines \$includes \$rcflags \$
- # /fo\$out \$in
- # description = RC \$in
- #}
+ tool("rc") {
+ command = "$python_path gyp-win-tool rc-wrapper \$arch rc.exe \$defines \$includes \$rcflags /fo\$out \$in"
+ description = "RC \$in"
+ }
#tool("asm") {
# command = $python_path gyp-win-tool asm-wrapper \$arch ml.exe \$defines \$includes /c /Fo \$
# \$out \$in
diff --git a/tools/gn/setup.cc b/tools/gn/setup.cc
index b183468..b94a4ae 100644
--- a/tools/gn/setup.cc
+++ b/tools/gn/setup.cc
@@ -4,9 +4,14 @@
#include "tools/gn/setup.h"
+#include <stdlib.h>
+
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
+#include "base/strings/string_split.h"
+#include "base/strings/string_util.h"
+#include "build/build_config.h"
#include "tools/gn/filesystem_utils.h"
#include "tools/gn/input_file.h"
#include "tools/gn/parse_tree.h"
@@ -18,6 +23,10 @@
#include "tools/gn/trace.h"
#include "tools/gn/value.h"
+#if defined(OS_WIN)
+#include <windows.h>
+#endif
+
extern const char kDotfile_Help[] =
".gn file\n"
"\n"
@@ -90,6 +99,58 @@ base::FilePath FindDotFile(const base::FilePath& current_dir) {
return FindDotFile(up_one_dir);
}
+// Searches the list of strings, and returns the FilePat corresponding to the
+// one ending in the given substring, or the empty path if none match.
+base::FilePath GetPathEndingIn(
+ const std::vector<base::FilePath::StringType>& list,
+ const base::FilePath::StringType ending_in) {
+ for (size_t i = 0; i < list.size(); i++) {
+ if (EndsWith(list[i], ending_in, true))
+ return base::FilePath(list[i]);
+ }
+ return base::FilePath();
+}
+
+// Fins the depot tools directory in the path environment variable and returns
+// its value. Returns an empty file path if not found.
+//
+// We detect the depot_tools path by looking for a directory with depot_tools
+// at the end (optionally followed by a separator).
+base::FilePath ExtractDepotToolsFromPath() {
+#if defined(OS_WIN)
+ static const wchar_t kPathVarName[] = L"Path";
+ DWORD env_buf_size = GetEnvironmentVariable(kPathVarName, NULL, 0);
+ if (env_buf_size == 0)
+ return base::FilePath();
+ base::string16 path;
+ path.resize(env_buf_size);
+ GetEnvironmentVariable(kPathVarName, &path[0],
+ static_cast<DWORD>(path.size()));
+ path.resize(path.size() - 1); // Trim off null.
+
+ std::vector<base::string16> components;
+ base::SplitString(path, ';', &components);
+
+ base::string16 ending_in1 = L"depot_tools\\";
+#else
+ static const char kPathVarName[] = "PATH";
+ const char* path = getenv(kPathVarName);
+ if (!path)
+ return base::FilePath();
+
+ std::vector<std::string> components;
+ base::SplitString(path, ':', &components);
+
+ std::string ending_in1 = "depot_tools/";
+#endif
+ base::FilePath::StringType ending_in2 = FILE_PATH_LITERAL("depot_tools");
+
+ base::FilePath found = GetPathEndingIn(components, ending_in1);
+ if (!found.empty())
+ return found;
+ return GetPathEndingIn(components, ending_in2);
+}
+
} // namespace
Setup::Setup()
@@ -118,14 +179,7 @@ bool Setup::DoSetup() {
return false;
if (!FillOtherConfig(*cmdline))
return false;
-
- // FIXME(brettw) get python path!
-#if defined(OS_WIN)
- build_settings_.set_python_path(base::FilePath(
- FILE_PATH_LITERAL("python.exe")));
-#else
- build_settings_.set_python_path(base::FilePath(FILE_PATH_LITERAL("python")));
-#endif
+ FillPythonPath();
base::FilePath build_path = cmdline->GetSwitchValuePath(kSwitchBuildOutput);
if (!build_path.empty()) {
@@ -240,6 +294,33 @@ bool Setup::FillSourceDir(const CommandLine& cmdline) {
return true;
}
+void Setup::FillPythonPath() {
+#if defined(OS_WIN)
+ // We use python from the depot tools which should be on the path. If we
+ // converted the python_path to a python_command_line then we could
+ // potentially use "cmd.exe /c python.exe" and remove this.
+ static const wchar_t kPythonName[] = L"python.exe";
+ base::FilePath depot_tools = ExtractDepotToolsFromPath();
+ if (!depot_tools.empty()) {
+ base::FilePath python =
+ depot_tools.Append(L"python_bin").Append(kPythonName);
+ if (scheduler_.verbose_logging())
+ scheduler_.Log("Using python", FilePathToUTF8(python));
+ build_settings_.set_python_path(python);
+ return;
+ }
+
+ if (scheduler_.verbose_logging()) {
+ scheduler_.Log("WARNING", "Could not find depot_tools on path, using "
+ "just " + FilePathToUTF8(kPythonName));
+ }
+#else
+ static const char kPythonName[] = "python";
+#endif
+
+ build_settings_.set_python_path(base::FilePath(kPythonName));
+}
+
bool Setup::RunConfigFile() {
if (scheduler_.verbose_logging())
scheduler_.Log("Got dotfile", FilePathToUTF8(dotfile_name_));
diff --git a/tools/gn/setup.h b/tools/gn/setup.h
index 069da92..bd7166d 100644
--- a/tools/gn/setup.h
+++ b/tools/gn/setup.h
@@ -52,6 +52,10 @@ class Setup {
// Fills the root directory into the settings. Returns true on success.
bool FillSourceDir(const CommandLine& cmdline);
+ // Fills the python path portion of the command line. On failure, sets
+ // it to just "python".
+ void FillPythonPath();
+
// Run config file.
bool RunConfigFile();
diff --git a/tools/gn/toolchain.cc b/tools/gn/toolchain.cc
index cf9bfdb..887fba2 100644
--- a/tools/gn/toolchain.cc
+++ b/tools/gn/toolchain.cc
@@ -11,6 +11,7 @@ const char* Toolchain::kToolCc = "cc";
const char* Toolchain::kToolCxx = "cxx";
const char* Toolchain::kToolObjC = "objc";
const char* Toolchain::kToolObjCxx = "objcxx";
+const char* Toolchain::kToolRc = "rc";
const char* Toolchain::kToolAsm = "asm";
const char* Toolchain::kToolAlink = "alink";
const char* Toolchain::kToolSolink = "solink";
@@ -44,6 +45,7 @@ Toolchain::ToolType Toolchain::ToolNameToType(const base::StringPiece& str) {
if (str == kToolCxx) return TYPE_CXX;
if (str == kToolObjC) return TYPE_OBJC;
if (str == kToolObjCxx) return TYPE_OBJCXX;
+ if (str == kToolRc) return TYPE_RC;
if (str == kToolAsm) return TYPE_ASM;
if (str == kToolAlink) return TYPE_ALINK;
if (str == kToolSolink) return TYPE_SOLINK;
@@ -60,6 +62,7 @@ std::string Toolchain::ToolTypeToName(ToolType type) {
case TYPE_CXX: return kToolCxx;
case TYPE_OBJC: return kToolObjC;
case TYPE_OBJCXX: return kToolObjCxx;
+ case TYPE_RC: return kToolRc;
case TYPE_ASM: return kToolAsm;
case TYPE_ALINK: return kToolAlink;
case TYPE_SOLINK: return kToolSolink;
diff --git a/tools/gn/toolchain.h b/tools/gn/toolchain.h
index b00c113..bb64e55 100644
--- a/tools/gn/toolchain.h
+++ b/tools/gn/toolchain.h
@@ -31,6 +31,7 @@ class Toolchain : public Item {
TYPE_CXX,
TYPE_OBJC,
TYPE_OBJCXX,
+ TYPE_RC,
TYPE_ASM,
TYPE_ALINK,
TYPE_SOLINK,
@@ -45,6 +46,7 @@ class Toolchain : public Item {
static const char* kToolCxx;
static const char* kToolObjC;
static const char* kToolObjCxx;
+ static const char* kToolRc;
static const char* kToolAsm;
static const char* kToolAlink;
static const char* kToolSolink;