summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-25 21:54:21 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-25 21:54:21 +0000
commit1650bb3384f1ae90c3d3e20659e2735676896183 (patch)
treec93c8cc609c99d14f35c4daed5f58bee691e2445
parent61091a53e2c777a398ba5e1fa03b38d6a4fd8b39 (diff)
downloadchromium_src-1650bb3384f1ae90c3d3e20659e2735676896183.zip
chromium_src-1650bb3384f1ae90c3d3e20659e2735676896183.tar.gz
chromium_src-1650bb3384f1ae90c3d3e20659e2735676896183.tar.bz2
Fix GN unit tests
Various uses or $arch were not updated in the script writing code and in the expected output from when I changed how this works. This updates the script target writer and updates the test expectations. This moves the creation of the output directory from the build settings to the script execute code. I added this previously because the output directory wasn't always created by the time the windows toolchain setup script was run. But lots of tests don't bother to set the source root, and we don't want the tests creating directories randomly anyway. So this moves the creation to when we need it, although most of the time it will be a NOP. I added a build file for device/usb because I was bored last night. BUG= R=scottmg@chromium.org Review URL: https://codereview.chromium.org/41703002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231124 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--tools/gn/build_settings.cc3
-rw-r--r--tools/gn/build_settings.h3
-rw-r--r--tools/gn/function_exec_script.cc8
-rw-r--r--tools/gn/ninja_binary_target_writer_unittest.cc176
-rw-r--r--tools/gn/ninja_script_target_writer.cc6
-rw-r--r--tools/gn/ninja_script_target_writer_unittest.cc3
-rw-r--r--tools/gn/secondary/BUILD.gn1
-rw-r--r--tools/gn/secondary/device/usb/BUILD.gn25
8 files changed, 128 insertions, 97 deletions
diff --git a/tools/gn/build_settings.cc b/tools/gn/build_settings.cc
index af81467..0a75569 100644
--- a/tools/gn/build_settings.cc
+++ b/tools/gn/build_settings.cc
@@ -46,9 +46,6 @@ void BuildSettings::SetSecondarySourcePath(const SourceDir& d) {
void BuildSettings::SetBuildDir(const SourceDir& d) {
build_dir_ = d;
build_to_source_dir_string_ = InvertDir(d);
-
- DCHECK(!root_path_.empty());
- file_util::CreateDirectory(build_dir_.Resolve(root_path_));
}
base::FilePath BuildSettings::GetFullPath(const SourceFile& file) const {
diff --git a/tools/gn/build_settings.h b/tools/gn/build_settings.h
index 231d040..fc175df 100644
--- a/tools/gn/build_settings.h
+++ b/tools/gn/build_settings.h
@@ -60,8 +60,7 @@ class BuildSettings {
// The build directory is the root of all output files. The default toolchain
// files go into here, and non-default toolchains will have separate
- // toolchain-specific root directories inside this. This should be set after
- // the root path for the proper directory to be created.
+ // toolchain-specific root directories inside this.
const SourceDir& build_dir() const { return build_dir_; }
void SetBuildDir(const SourceDir& dir);
diff --git a/tools/gn/function_exec_script.cc b/tools/gn/function_exec_script.cc
index 540d189..bf55165 100644
--- a/tools/gn/function_exec_script.cc
+++ b/tools/gn/function_exec_script.cc
@@ -348,6 +348,14 @@ Value RunExecScript(Scope* scope,
base::FilePath startup_dir =
build_settings->GetFullPath(build_settings->build_dir());
+ // The first time a build is run, no targets will have been written so the
+ // build output directory won't exist. We need to make sure it does before
+ // running any scripts with this as its startup directory, although it will
+ // be relatively rare that the directory won't exist by the time we get here.
+ //
+ // If this shows up on benchmarks, we can cache whether we've done this
+ // or not and skip creating the directory.
+ file_util::CreateDirectory(startup_dir);
// Execute the process.
// TODO(brettw) set the environment block.
diff --git a/tools/gn/ninja_binary_target_writer_unittest.cc b/tools/gn/ninja_binary_target_writer_unittest.cc
index f57bb19..0bf4722 100644
--- a/tools/gn/ninja_binary_target_writer_unittest.cc
+++ b/tools/gn/ninja_binary_target_writer_unittest.cc
@@ -1,89 +1,87 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <sstream>
-
-#include "testing/gtest/include/gtest/gtest.h"
-#include "tools/gn/ninja_binary_target_writer.h"
-#include "tools/gn/test_with_scope.h"
-
-TEST(NinjaBinaryTargetWriter, SourceSet) {
- TestWithScope setup;
- setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
- setup.settings()->set_target_os(Settings::WIN);
-
- Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
- target.set_output_type(Target::SOURCE_SET);
- target.sources().push_back(SourceFile("//foo/input1.cc"));
- target.sources().push_back(SourceFile("//foo/input2.cc"));
- target.OnResolved();
-
- // Source set itself.
- {
- std::ostringstream out;
- NinjaBinaryTargetWriter writer(&target, out);
- writer.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[] =
- "arch = environment.x86\n"
- "defines =\n"
- "includes =\n"
- "cflags =\n"
- "cflags_c =\n"
- "cflags_cc =\n"
- "cflags_objc =\n"
- "cflags_objcc =\n"
- "\n"
- "build obj/foo/bar.input1.obj: tc_cxx ../../foo/input1.cc\n"
- "build obj/foo/bar.input2.obj: tc_cxx ../../foo/input2.cc\n"
- "\n"
- "build obj/foo/bar.stamp: tc_stamp obj/foo/bar.input1.obj obj/foo/bar.input2.obj\n";
- 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);
- }
-
- // A shared library that depends on the source set.
- Target shlib_target(setup.settings(), Label(SourceDir("//foo/"), "shlib"));
- shlib_target.set_output_type(Target::SHARED_LIBRARY);
- shlib_target.deps().push_back(&target);
- shlib_target.OnResolved();
-
- {
- std::ostringstream out;
- NinjaBinaryTargetWriter writer(&shlib_target, out);
- writer.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[] =
- "arch = environment.x86\n"
- "defines =\n"
- "includes =\n"
- "cflags =\n"
- "cflags_c =\n"
- "cflags_cc =\n"
- "cflags_objc =\n"
- "cflags_objcc =\n"
- "\n"
- "\n"
- "manifests = obj/foo/shlib.intermediate.manifest\n"
- "ldflags = /MANIFEST /ManifestFile:obj/foo/shlib.intermediate.manifest\n"
- "libs =\n"
- "build shlib.dll shlib.dll.lib: tc_solink obj/foo/bar.input1.obj obj/foo/bar.input2.obj\n"
- " soname = shlib.dll\n"
- " lib = shlib.dll\n"
- " dll = shlib.dll\n"
- " implibflag = /IMPLIB:shlib.dll.lib\n\n";
- 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);
- }
-}
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <sstream>
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "tools/gn/ninja_binary_target_writer.h"
+#include "tools/gn/test_with_scope.h"
+
+TEST(NinjaBinaryTargetWriter, SourceSet) {
+ TestWithScope setup;
+ setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
+ setup.settings()->set_target_os(Settings::WIN);
+
+ Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
+ target.set_output_type(Target::SOURCE_SET);
+ target.sources().push_back(SourceFile("//foo/input1.cc"));
+ target.sources().push_back(SourceFile("//foo/input2.cc"));
+ target.OnResolved();
+
+ // Source set itself.
+ {
+ std::ostringstream out;
+ NinjaBinaryTargetWriter writer(&target, out);
+ writer.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[] =
+ "defines =\n"
+ "includes =\n"
+ "cflags =\n"
+ "cflags_c =\n"
+ "cflags_cc =\n"
+ "cflags_objc =\n"
+ "cflags_objcc =\n"
+ "\n"
+ "build obj/foo/bar.input1.obj: tc_cxx ../../foo/input1.cc\n"
+ "build obj/foo/bar.input2.obj: tc_cxx ../../foo/input2.cc\n"
+ "\n"
+ "build obj/foo/bar.stamp: tc_stamp obj/foo/bar.input1.obj obj/foo/bar.input2.obj\n";
+ 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);
+ }
+
+ // A shared library that depends on the source set.
+ Target shlib_target(setup.settings(), Label(SourceDir("//foo/"), "shlib"));
+ shlib_target.set_output_type(Target::SHARED_LIBRARY);
+ shlib_target.deps().push_back(&target);
+ shlib_target.OnResolved();
+
+ {
+ std::ostringstream out;
+ NinjaBinaryTargetWriter writer(&shlib_target, out);
+ writer.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[] =
+ "defines =\n"
+ "includes =\n"
+ "cflags =\n"
+ "cflags_c =\n"
+ "cflags_cc =\n"
+ "cflags_objc =\n"
+ "cflags_objcc =\n"
+ "\n"
+ "\n"
+ "manifests = obj/foo/shlib.intermediate.manifest\n"
+ "ldflags = /MANIFEST /ManifestFile:obj/foo/shlib.intermediate.manifest\n"
+ "libs =\n"
+ "build shlib.dll shlib.dll.lib: tc_solink obj/foo/bar.input1.obj obj/foo/bar.input2.obj\n"
+ " soname = shlib.dll\n"
+ " lib = shlib.dll\n"
+ " dll = shlib.dll\n"
+ " implibflag = /IMPLIB:shlib.dll.lib\n\n";
+ 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 b362976..5dd8095 100644
--- a/tools/gn/ninja_script_target_writer.cc
+++ b/tools/gn/ninja_script_target_writer.cc
@@ -75,7 +75,11 @@ std::string NinjaScriptTargetWriter::WriteRuleDefinition(
out_ << "rule " << custom_rule_name << std::endl;
out_ << " command = ";
path_output_.WriteFile(out_, settings_->build_settings()->python_path());
- out_ << " gyp-win-tool action-wrapper $arch " << rspfile << std::endl;
+ // TODO(brettw) this hardcodes "environment.x86" which is something that
+ // the Chrome Windows toolchain writes. We should have a way to invoke
+ // python without requiring this gyp_win_tool thing.
+ out_ << " gyp-win-tool action-wrapper environment.x86 " << rspfile
+ << std::endl;
out_ << " description = CUSTOM " << target_label << std::endl;
out_ << " restat = 1" << std::endl;
out_ << " rspfile = " << rspfile << std::endl;
diff --git a/tools/gn/ninja_script_target_writer_unittest.cc b/tools/gn/ninja_script_target_writer_unittest.cc
index 2057f07..f3e7bf1 100644
--- a/tools/gn/ninja_script_target_writer_unittest.cc
+++ b/tools/gn/ninja_script_target_writer_unittest.cc
@@ -126,9 +126,8 @@ TEST(NinjaScriptTargetWriter, InvokeOverSources) {
// 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[] =
- "arch = environment.x86\n"
"rule __foo_bar___rule\n"
- " command = C:/python/python.exe gyp-win-tool action-wrapper $arch __foo_bar___rule.$unique_name.rsp\n"
+ " command = C:/python/python.exe gyp-win-tool action-wrapper environment.x86 __foo_bar___rule.$unique_name.rsp\n"
" description = CUSTOM //foo:bar()\n"
" restat = 1\n"
" rspfile = __foo_bar___rule.$unique_name.rsp\n"
diff --git a/tools/gn/secondary/BUILD.gn b/tools/gn/secondary/BUILD.gn
index d285eb4..7a4f786 100644
--- a/tools/gn/secondary/BUILD.gn
+++ b/tools/gn/secondary/BUILD.gn
@@ -9,6 +9,7 @@ group("root") {
"//base(//build/toolchain/nacl:x86_newlib)",
"//chrome",
"//crypto",
+ "//device/usb:device_usb",
"//ipc",
"//net",
"//net/third_party/nss:ssl",
diff --git a/tools/gn/secondary/device/usb/BUILD.gn b/tools/gn/secondary/device/usb/BUILD.gn
new file mode 100644
index 0000000..afe95dc
--- /dev/null
+++ b/tools/gn/secondary/device/usb/BUILD.gn
@@ -0,0 +1,25 @@
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+source_ids = "//third_party/usb_ids/usb.ids"
+generated_ids = "$target_gen_dir/usb_ids_gen.cc"
+
+static_library("device_usb") {
+ sources = [
+ "usb_ids.cc",
+ "usb_ids.h",
+ generated_ids,
+ ]
+ deps = [ ":device_usb_ids" ]
+}
+
+custom("device_usb_ids") {
+ script = "//tools/usb_ids/usb_ids.py"
+ source_prereqs = [ source_ids ]
+ outputs = [ generated_ids ]
+ args = [
+ "-i", rebase_path(source_ids, ".", root_build_dir),
+ "-o", rebase_path(generated_ids, ".", root_build_dir),
+ ]
+}