diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-29 21:06:26 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-29 21:06:26 +0000 |
commit | 0a79fe4b90ca24b1e5ac78f15991ac4017f68b9d (patch) | |
tree | b6b9c5d1f7cfc99f1a4278c46f6fdbfd9e709977 /tools/gn | |
parent | f796b33367f47be55d51a3fd8a19bad6a48b744b (diff) | |
download | chromium_src-0a79fe4b90ca24b1e5ac78f15991ac4017f68b9d.zip chromium_src-0a79fe4b90ca24b1e5ac78f15991ac4017f68b9d.tar.gz chromium_src-0a79fe4b90ca24b1e5ac78f15991ac4017f68b9d.tar.bz2 |
Add a GYP command to GN. This runs GYP and then GN, and does some work to integrate the builds.
Adds an "external" variable that's set in the GYP mode of GN that will cause it to not write out a target but to pretend it's there. These are the ones that should be generated by GYP. This value is not used in the normal "gen" mode so we actually have two builds: a separate GN-only build that includes GN itself and some other low-level libraries, and a hybrid build.
This renames and moves some of the GN targets so that the names and locations match those of the GYP build.
I prefixed the ninja rules for the default toolchain to avoid colliding with the GYP ones. I also fixed some places where the rules were not getting prefixed.
I added an exception to target output labeling to avoid double-prefixing with "lib".
TBR=scottmg
BUG=
Review URL: https://codereview.chromium.org/23493013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220367 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/gn')
56 files changed, 875 insertions, 278 deletions
diff --git a/tools/gn/BUILD.gn b/tools/gn/BUILD.gn index 946c075..a993a19 100644 --- a/tools/gn/BUILD.gn +++ b/tools/gn/BUILD.gn @@ -9,6 +9,7 @@ static_library("gn_lib") { "command_args.cc", "command_desc.cc", "command_gen.cc", + "command_gyp.cc", "command_help.cc", "command_refs.cc", "commands.cc", @@ -168,9 +169,9 @@ test("gn_unittests") { ] deps = [ ":gn_lib", - "//base/test:run_all_unittests", - "//base/test:test_support_base", - "//testing/gtest", + "//base:run_all_unittests", + "//base:test_support_base", + "//testing:gtest", ] } diff --git a/tools/gn/args.cc b/tools/gn/args.cc index d340713..d11892bc 100644 --- a/tools/gn/args.cc +++ b/tools/gn/args.cc @@ -55,12 +55,12 @@ Args::Args() { Args::~Args() { } -void Args::SwapInArgOverrides(Scope::KeyValueMap* overrides) { - DCHECK(overrides_.empty()); - overrides_.swap(*overrides); - for (Scope::KeyValueMap::const_iterator i = overrides_.begin(); - i != overrides_.end(); ++i) +void Args::AddArgOverrides(const Scope::KeyValueMap& overrides) { + for (Scope::KeyValueMap::const_iterator i = overrides.begin(); + i != overrides.end(); ++i) { + overrides_.insert(*i); all_overrides_.insert(*i); + } } void Args::SetupRootScope(Scope* dest, diff --git a/tools/gn/args.h b/tools/gn/args.h index 4d2287d1..d3225ca 100644 --- a/tools/gn/args.h +++ b/tools/gn/args.h @@ -27,7 +27,7 @@ class Args { // Specifies overrides of the build arguments. These are normally specified // on the command line. - void SwapInArgOverrides(Scope::KeyValueMap* overrides); + void AddArgOverrides(const Scope::KeyValueMap& overrides); // Sets up the root scope for a toolchain. This applies the default system // flags, then any overrides stored in this object, then applies any diff --git a/tools/gn/binary_target_generator.cc b/tools/gn/binary_target_generator.cc index 4638be4..6d12768 100644 --- a/tools/gn/binary_target_generator.cc +++ b/tools/gn/binary_target_generator.cc @@ -7,6 +7,7 @@ #include "tools/gn/config_values_generator.h" #include "tools/gn/err.h" #include "tools/gn/scope.h" +#include "tools/gn/variables.h" BinaryTargetGenerator::BinaryTargetGenerator(Target* target, Scope* scope, @@ -23,6 +24,7 @@ BinaryTargetGenerator::~BinaryTargetGenerator() { void BinaryTargetGenerator::DoRun() { target_->set_output_type(output_type_); + FillExternal(); FillSources(); FillConfigs(); diff --git a/tools/gn/build_settings.cc b/tools/gn/build_settings.cc index ebe0323..6b11a28 100644 --- a/tools/gn/build_settings.cc +++ b/tools/gn/build_settings.cc @@ -7,7 +7,8 @@ #include "tools/gn/filesystem_utils.h" BuildSettings::BuildSettings() - : item_tree_(), + : using_external_generator_(false), + item_tree_(), target_manager_(this), toolchain_manager_(this) { } diff --git a/tools/gn/build_settings.h b/tools/gn/build_settings.h index 454eca4..429a183 100644 --- a/tools/gn/build_settings.h +++ b/tools/gn/build_settings.h @@ -39,6 +39,13 @@ class BuildSettings { } void SetSecondarySourcePath(const SourceDir& d); + // Set when we're running an external generator (e.g. GYP) and should + // enable "external" flags on targets. + bool using_external_generator() const { return using_external_generator_; } + void set_using_external_generator(bool ueg) { + using_external_generator_ = ueg; + } + // Path of the python executable to run scripts with. base::FilePath python_path() const { return python_path_; } void set_python_path(const base::FilePath& p) { python_path_ = p; } @@ -98,6 +105,7 @@ class BuildSettings { base::FilePath root_path_; std::string root_path_utf8_; base::FilePath secondary_source_path_; + bool using_external_generator_; base::FilePath python_path_; SourceFile build_config_file_; diff --git a/tools/gn/command_gen.cc b/tools/gn/command_gen.cc index 7d8203d..9f6d38f 100644 --- a/tools/gn/command_gen.cc +++ b/tools/gn/command_gen.cc @@ -39,6 +39,7 @@ const char kGen_Help[] = "\n" " See \"gn help\" for the common command-line switches.\n"; +// Note: partially duplicated in command_gyp.cc. int RunGen(const std::vector<std::string>& args) { base::TimeTicks begin_time = base::TimeTicks::Now(); diff --git a/tools/gn/command_gyp.cc b/tools/gn/command_gyp.cc new file mode 100644 index 0000000..11fd269 --- /dev/null +++ b/tools/gn/command_gyp.cc @@ -0,0 +1,228 @@ +// 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 <fstream> + +#include "base/atomicops.h" +#include "base/bind.h" +#include "base/command_line.h" +#include "base/file_util.h" +#include "base/process/launch.h" +#include "base/strings/string_number_conversions.h" +#include "base/time/time.h" +#include "tools/gn/build_settings.h" +#include "tools/gn/commands.h" +#include "tools/gn/err.h" +#include "tools/gn/filesystem_utils.h" +#include "tools/gn/ninja_target_writer.h" +#include "tools/gn/ninja_writer.h" +#include "tools/gn/path_output.h" +#include "tools/gn/setup.h" +#include "tools/gn/standard_out.h" + +namespace commands { + +namespace { + +// Suppress output on success. +const char kSwitchQuiet[] = "q"; + +// Skip actually executing GYP. This is for when you're working on the GN +// build and don't want to wait for GYP to regenerate. All GN files are +// regenerated, but the GYP ones are not. +const char kSwitchNoGyp[] = "no-gyp"; + +void TargetResolvedCallback(base::subtle::Atomic32* write_counter, + const Target* target) { + base::subtle::NoBarrier_AtomicIncrement(write_counter, 1); + NinjaTargetWriter::RunAndWriteFile(target); +} + +bool SimpleNinjaParse(const std::string& data, + std::set<std::string>* subninjas, + size_t* first_subninja_offset) { + const size_t kSubninjaPrefixLen = 10; + const char kSubninjaPrefix[kSubninjaPrefixLen + 1] = "\nsubninja "; + + *first_subninja_offset = std::string::npos; + size_t next_subninja = 0; + while ((next_subninja = data.find(kSubninjaPrefix, next_subninja)) != + std::string::npos) { + if (*first_subninja_offset == std::string::npos) + *first_subninja_offset = next_subninja; + + size_t line_end = data.find('\n', next_subninja + 1); + if (line_end == std::string::npos) + return false; + + std::string filename = data.substr( + next_subninja + kSubninjaPrefixLen, + line_end - next_subninja - kSubninjaPrefixLen); + subninjas->insert(filename); + + next_subninja = line_end; + } + return *first_subninja_offset != std::string::npos; +} + +bool FixupBuildNinja(const BuildSettings* build_settings, + const base::FilePath& buildfile) { + std::string contents; + if (!file_util::ReadFileToString(buildfile, &contents)) { + Err(Location(), "Could not load " + FilePathToUTF8(buildfile)) + .PrintToStdout(); + return false; + } + + std::set<std::string> subninjas; + size_t first_subninja_offset = 0; + if (!SimpleNinjaParse(contents, &subninjas, &first_subninja_offset)) { + Err(Location(), "Could not parse " + FilePathToUTF8(buildfile)) + .PrintToStdout(); + return false; + } + + // Write toolchain files. + std::vector<const Settings*> all_settings; + if (!NinjaWriter::RunAndWriteToolchainFiles( + build_settings, subninjas, &all_settings)) + return false; + + // Copy first part of buildfile to the output. + std::ofstream file; + file.open(FilePathToUTF8(buildfile).c_str(), + std::ios_base::out | std::ios_base::binary); + if (file.fail()) { + Err(Location(), "Could not write " + FilePathToUTF8(buildfile)) + .PrintToStdout(); + return false; + } + file.write(contents.data(), first_subninja_offset); + + // Add refs for our toolchains to the original build.ninja. + NinjaHelper helper(build_settings); + PathOutput path_output(build_settings->build_dir(), ESCAPE_NINJA, true); + file << "\n# GN-added toolchain files.\n"; + for (size_t i = 0; i < all_settings.size(); i++) { + file << "subninja "; + path_output.WriteFile(file, + helper.GetNinjaFileForToolchain(all_settings[i])); + file << std::endl; + } + file << "\n# GYP-written subninjas."; + + // Write remaining old subninjas from original file. + file.write(&contents[first_subninja_offset], + contents.size() - first_subninja_offset); + return true; +} + +bool RunGyp(const BuildSettings* build_settings) { + if (!CommandLine::ForCurrentProcess()->HasSwitch(kSwitchQuiet)) + OutputString("Running GYP...\n"); + + const base::FilePath& python_path = build_settings->python_path(); + + // Construct the command line. Note that AppendArgPath and AppendSwitchPath + // don't preserve the relative ordering, and we need the python file to be + // first, so we have to convert switch values to strings before appending. + // + // Note that GYP will get confused if this path is quoted, so don't quote it + // and hope that there are no spaces! + CommandLine cmdline(python_path); + cmdline.AppendArgPath( + build_settings->GetFullPath(SourceFile("//build/gyp_chromium.py"))); + base::FilePath::StringType gen_output = + FILE_PATH_LITERAL("--generator-output=") + + build_settings->GetFullPath(SourceFile("//out.gn")).value(); + cmdline.AppendArgPath(base::FilePath(gen_output)); + + std::string output; + if (!base::GetAppOutput(cmdline, &output)) { + Err(Location(), "GYP execution failed.", output).PrintToStdout(); + return false; + } + return true; +} + +} // namespace + +const char kGyp[] = "gyp"; +const char kGyp_HelpShort[] = + "gyp: Run gyp and then GN."; +const char kGyp_Help[] = + "TODO(brettw) write this.\n"; + +// Note: partially duplicated from command_gen.cc. +int RunGyp(const std::vector<std::string>& args) { + const CommandLine* cmdline = CommandLine::ForCurrentProcess(); + bool no_gyp = cmdline->HasSwitch(kSwitchNoGyp); + + // Deliberately leaked to avoid expensive process teardown. + Setup* setup = new Setup; + if (!setup->DoSetup()) + return 1; + + setup->build_settings().SetBuildDir(SourceDir("//out.gn/out/Debug/")); + setup->build_settings().set_using_external_generator(true); + + // Provide a way for buildfiles to know we're doing a GYP build. + /* + Scope::KeyValueMap variable_overrides; + variable_overrides["is_gyp"] = Value(NULL, true); + setup->build_settings().build_args().AddArgOverrides(variable_overrides); + */ + + base::TimeTicks begin_time = base::TimeTicks::Now(); + if (!no_gyp) { + if (!RunGyp(&setup->build_settings())) + return 1; + } + base::TimeTicks end_gyp_time = base::TimeTicks::Now(); + + if (!cmdline->HasSwitch(kSwitchQuiet)) + OutputString("Running GN...\n"); + + // Cause the load to also generate the ninja files for each target. We wrap + // the writing to maintain a counter. + base::subtle::Atomic32 write_counter = 0; + setup->build_settings().set_target_resolved_callback( + base::Bind(&TargetResolvedCallback, &write_counter)); + + // Do the actual load. This will also write out the target ninja files. + if (!setup->Run()) + return 1; + + // Integrate with the GYP build. + if (!no_gyp) { + base::FilePath ninja_buildfile(setup->build_settings().GetFullPath( + SourceFile(setup->build_settings().build_dir().value() + + "build.ninja"))); + if (!FixupBuildNinja(&setup->build_settings(), ninja_buildfile)) + return 1; + } + + // Timing info. + base::TimeTicks end_time = base::TimeTicks::Now(); + if (!cmdline->HasSwitch(kSwitchQuiet)) { + OutputString("Done. ", DECORATION_GREEN); + + std::string stats = "Wrote " + + base::IntToString(static_cast<int>(write_counter)) + + " targets from " + + base::IntToString( + setup->scheduler().input_file_manager()->GetInputFileCount()) + + " files in " + + base::IntToString((end_time - end_gyp_time).InMilliseconds()) + "ms " + + "(GYP took " + + base::IntToString((end_gyp_time - begin_time).InMilliseconds()) + + "ms)\n"; + + OutputString(stats); + } + + return 0; +} + +} // namespace commands diff --git a/tools/gn/commands.cc b/tools/gn/commands.cc index c632cce..e600872 100644 --- a/tools/gn/commands.cc +++ b/tools/gn/commands.cc @@ -37,6 +37,7 @@ const CommandInfoMap& GetCommands() { INSERT_COMMAND(Args) INSERT_COMMAND(Desc) INSERT_COMMAND(Gen) + INSERT_COMMAND(Gyp) INSERT_COMMAND(Help) INSERT_COMMAND(Refs) diff --git a/tools/gn/commands.h b/tools/gn/commands.h index 1900820..bcd0c2e 100644 --- a/tools/gn/commands.h +++ b/tools/gn/commands.h @@ -34,6 +34,11 @@ extern const char kGen_HelpShort[]; extern const char kGen_Help[]; int RunGen(const std::vector<std::string>& args); +extern const char kGyp[]; +extern const char kGyp_HelpShort[]; +extern const char kGyp_Help[]; +int RunGyp(const std::vector<std::string>& args); + extern const char kHelp[]; extern const char kHelp_HelpShort[]; extern const char kHelp_Help[]; diff --git a/tools/gn/copy_target_generator.cc b/tools/gn/copy_target_generator.cc index 6347ca2..18ecc3f 100644 --- a/tools/gn/copy_target_generator.cc +++ b/tools/gn/copy_target_generator.cc @@ -22,6 +22,7 @@ CopyTargetGenerator::~CopyTargetGenerator() { void CopyTargetGenerator::DoRun() { target_->set_output_type(Target::COPY_FILES); + FillExternal(); FillSources(); FillDestDir(); diff --git a/tools/gn/gn.gyp b/tools/gn/gn.gyp index 5781f8b..52275f4 100644 --- a/tools/gn/gn.gyp +++ b/tools/gn/gn.gyp @@ -19,6 +19,7 @@ 'command_args.cc', 'command_desc.cc', 'command_gen.cc', + 'command_gyp.cc', 'command_help.cc', 'command_refs.cc', 'commands.cc', diff --git a/tools/gn/group_target_generator.cc b/tools/gn/group_target_generator.cc index 6f6fe32..30238e7 100644 --- a/tools/gn/group_target_generator.cc +++ b/tools/gn/group_target_generator.cc @@ -18,4 +18,5 @@ void GroupTargetGenerator::DoRun() { target_->set_output_type(Target::GROUP); // Groups only have the default types filled in by the target generator // base class. + FillExternal(); } diff --git a/tools/gn/ninja_copy_target_writer.cc b/tools/gn/ninja_copy_target_writer.cc index 4d2ebe0..d4a65ab 100644 --- a/tools/gn/ninja_copy_target_writer.cc +++ b/tools/gn/ninja_copy_target_writer.cc @@ -50,7 +50,9 @@ 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_ << ": stamp"; + out_ << ": " + << helper_.GetRulePrefix(target_->settings()->toolchain()) + << "stamp"; for (size_t i = 0; i < dest_files.size(); i++) { out_ << " "; path_output_.WriteFile(out_, dest_files[i]); diff --git a/tools/gn/ninja_group_target_writer.cc b/tools/gn/ninja_group_target_writer.cc index f31bf1a..df95a82 100644 --- a/tools/gn/ninja_group_target_writer.cc +++ b/tools/gn/ninja_group_target_writer.cc @@ -20,7 +20,9 @@ void NinjaGroupTargetWriter::Run() { // the deps in the group. out_ << std::endl << "build "; path_output_.WriteFile(out_, helper_.GetTargetOutputFile(target_)); - out_ << ": stamp"; + out_ << ": " + << helper_.GetRulePrefix(target_->settings()->toolchain()) + << "stamp"; const std::vector<const Target*>& deps = target_->deps(); for (size_t i = 0; i < deps.size(); i++) { diff --git a/tools/gn/ninja_helper.cc b/tools/gn/ninja_helper.cc index 15c28af..0a4ebfd 100644 --- a/tools/gn/ninja_helper.cc +++ b/tools/gn/ninja_helper.cc @@ -114,11 +114,14 @@ OutputFile NinjaHelper::GetOutputFileForSource( OutputFile NinjaHelper::GetTargetOutputFile(const Target* target) const { OutputFile ret; - // This is prepended to the output file name. + // This is prepended to the output file name. Some platforms get "lib" + // prepended to library names. but be careful not to make a duplicate (e.g. + // some targets like "libxml" already have the "lib" in the name). const char* prefix; if (!target->settings()->IsWin() && (target->output_type() == Target::SHARED_LIBRARY || - target->output_type() == Target::STATIC_LIBRARY)) + target->output_type() == Target::STATIC_LIBRARY) && + target->label().name().compare(0, 3, "lib") != 0) prefix = "lib"; else prefix = ""; @@ -182,8 +185,12 @@ OutputFile NinjaHelper::GetTargetOutputFile(const Target* target) const { } std::string NinjaHelper::GetRulePrefix(const Toolchain* toolchain) const { - if (toolchain->is_default()) - return std::string(); // Default toolchain has no prefix. + // This code doesn't prefix the default toolchain commands. This is disabled + // so we can coexist with GYP's commands (which aren't prefixed). If we don't + // need to coexist with GYP anymore, we can uncomment this to make things a + // bit prettier. + //if (toolchain->is_default()) + // return std::string(); // Default toolchain has no prefix. return toolchain->label().name() + "_"; } diff --git a/tools/gn/ninja_script_target_writer.cc b/tools/gn/ninja_script_target_writer.cc index e259fff..be53a77 100644 --- a/tools/gn/ninja_script_target_writer.cc +++ b/tools/gn/ninja_script_target_writer.cc @@ -223,7 +223,9 @@ void NinjaScriptTargetWriter::WriteStamp( const std::vector<OutputFile>& output_files) { out_ << "build "; path_output_.WriteFile(out_, helper_.GetTargetOutputFile(target_)); - out_ << ": stamp"; + out_ << ": " + << helper_.GetRulePrefix(target_->settings()->toolchain()) + << "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_target_writer.cc b/tools/gn/ninja_target_writer.cc index 2852c9f..14a8bd7 100644 --- a/tools/gn/ninja_target_writer.cc +++ b/tools/gn/ninja_target_writer.cc @@ -30,6 +30,13 @@ NinjaTargetWriter::~NinjaTargetWriter() { // static void NinjaTargetWriter::RunAndWriteFile(const Target* target) { + // External targets don't get written to disk, we assume they're managed by + // an external program. If we're not using an external generator, this is + // ignored. + if (target->settings()->build_settings()->using_external_generator() && + target->external()) + return; + const Settings* settings = target->settings(); NinjaHelper helper(settings->build_settings()); diff --git a/tools/gn/ninja_toolchain_writer.cc b/tools/gn/ninja_toolchain_writer.cc index 95cb408..0a45e17 100644 --- a/tools/gn/ninja_toolchain_writer.cc +++ b/tools/gn/ninja_toolchain_writer.cc @@ -17,9 +17,11 @@ NinjaToolchainWriter::NinjaToolchainWriter( const Settings* settings, const std::vector<const Target*>& targets, + const std::set<std::string>& skip_files, std::ostream& out) : settings_(settings), targets_(targets), + skip_files_(skip_files), out_(out), path_output_(settings_->build_settings()->build_dir(), ESCAPE_NINJA, true), @@ -37,7 +39,8 @@ void NinjaToolchainWriter::Run() { // static bool NinjaToolchainWriter::RunAndWriteFile( const Settings* settings, - const std::vector<const Target*>& targets) { + const std::vector<const Target*>& targets, + const std::set<std::string>& skip_files) { NinjaHelper helper(settings->build_settings()); base::FilePath ninja_file(settings->build_settings()->GetFullPath( helper.GetNinjaFileForToolchain(settings).GetSourceFile( @@ -50,7 +53,7 @@ bool NinjaToolchainWriter::RunAndWriteFile( if (file.fail()) return false; - NinjaToolchainWriter gen(settings, targets, file); + NinjaToolchainWriter gen(settings, targets, skip_files, file); gen.Run(); return true; } @@ -90,10 +93,17 @@ void NinjaToolchainWriter::WriteRules() { void NinjaToolchainWriter::WriteSubninjas() { // Write subninja commands for each generated target. for (size_t i = 0; i < targets_.size(); i++) { - if (!targets_[i]->item_node()->should_generate()) + if (!targets_[i]->item_node()->should_generate() || + (targets_[i]->settings()->build_settings()->using_external_generator() + && targets_[i]->external())) + continue; + + OutputFile ninja_file = helper_.GetNinjaFileForTarget(targets_[i]); + if (skip_files_.find(ninja_file.value()) != skip_files_.end()) continue; + out_ << "subninja "; - path_output_.WriteFile(out_, helper_.GetNinjaFileForTarget(targets_[i])); + path_output_.WriteFile(out_, ninja_file); out_ << std::endl; } out_ << std::endl; diff --git a/tools/gn/ninja_toolchain_writer.h b/tools/gn/ninja_toolchain_writer.h index 71759ef..5d3daa5 100644 --- a/tools/gn/ninja_toolchain_writer.h +++ b/tools/gn/ninja_toolchain_writer.h @@ -6,6 +6,8 @@ #define TOOLS_GN_NINJA_TOOLCHAIN_WRITER_H_ #include <iosfwd> +#include <set> +#include <string> #include <vector> #include "tools/gn/ninja_helper.h" @@ -18,13 +20,16 @@ class Target; class NinjaToolchainWriter { public: // Takes the settings for the toolchain, as well as the list of all targets - // assicoated with the toolchain. + // assicoated with the toolchain. Ninja files exactly matching "skip_files" + // will not be included in the subninja list. static bool RunAndWriteFile(const Settings* settings, - const std::vector<const Target*>& targets); + const std::vector<const Target*>& targets, + const std::set<std::string>& skip_files); private: NinjaToolchainWriter(const Settings* settings, const std::vector<const Target*>& targets, + const std::set<std::string>& skip_files, std::ostream& out); ~NinjaToolchainWriter(); @@ -35,6 +40,7 @@ class NinjaToolchainWriter { const Settings* settings_; std::vector<const Target*> targets_; + const std::set<std::string>& skip_files_; std::ostream& out_; PathOutput path_output_; diff --git a/tools/gn/ninja_writer.cc b/tools/gn/ninja_writer.cc index 9eec865..1fe893e 100644 --- a/tools/gn/ninja_writer.cc +++ b/tools/gn/ninja_writer.cc @@ -8,7 +8,6 @@ #include "tools/gn/ninja_build_writer.h" #include "tools/gn/ninja_toolchain_writer.h" - NinjaWriter::NinjaWriter(const BuildSettings* build_settings) : build_settings_(build_settings) { } @@ -19,10 +18,29 @@ NinjaWriter::~NinjaWriter() { // static bool NinjaWriter::RunAndWriteFiles(const BuildSettings* build_settings) { NinjaWriter writer(build_settings); - return writer.WriteRootBuildfiles(); + + std::vector<const Settings*> all_settings; + std::vector<const Target*> default_targets; + if (!writer.WriteToolchains(std::set<std::string>(), + &all_settings, &default_targets)) + return false; + return writer.WriteRootBuildfiles(all_settings, default_targets); +} + +// static +bool NinjaWriter::RunAndWriteToolchainFiles( + const BuildSettings* build_settings, + const std::set<std::string>& skip_files, + std::vector<const Settings*>* all_settings) { + NinjaWriter writer(build_settings); + std::vector<const Target*> default_targets; + return writer.WriteToolchains(skip_files, all_settings, &default_targets); } -bool NinjaWriter::WriteRootBuildfiles() { +bool NinjaWriter::WriteToolchains( + const std::set<std::string>& skip_files, + std::vector<const Settings*>* all_settings, + std::vector<const Target*>* default_targets) { // Categorize all targets by toolchain. typedef std::map<Label, std::vector<const Target*> > CategorizedMap; CategorizedMap categorized; @@ -45,8 +63,6 @@ bool NinjaWriter::WriteRootBuildfiles() { // Write out the toolchain buildfiles, and also accumulate the set of // all settings and find the list of targets in the default toolchain. - std::vector<const Settings*> all_settings; - const std::vector<const Target*>* default_targets = NULL; for (CategorizedMap::const_iterator i = categorized.begin(); i != categorized.end(); ++i) { const Settings* settings; @@ -57,19 +73,26 @@ bool NinjaWriter::WriteRootBuildfiles() { build_settings_->toolchain_manager().GetSettingsForToolchainLocked( LocationRange(), i->first, &ignored); } - if (i->first == default_label) - default_targets = &i->second; - all_settings.push_back(settings); - if (!NinjaToolchainWriter::RunAndWriteFile(settings, i->second)) { + all_settings->push_back(settings); + if (!NinjaToolchainWriter::RunAndWriteFile(settings, i->second, + skip_files)) { Err(Location(), "Couldn't open toolchain buildfile(s) for writing").PrintToStdout(); return false; } } + *default_targets = categorized[ + build_settings_->toolchain_manager().GetDefaultToolchainUnlocked()]; + return true; +} + +bool NinjaWriter::WriteRootBuildfiles( + const std::vector<const Settings*>& all_settings, + const std::vector<const Target*>& default_targets) { // Write the root buildfile. if (!NinjaBuildWriter::RunAndWriteFile(build_settings_, all_settings, - *default_targets)) { + default_targets)) { Err(Location(), "Couldn't open toolchain buildfile(s) for writing").PrintToStdout(); return false; diff --git a/tools/gn/ninja_writer.h b/tools/gn/ninja_writer.h index a4050a8..c2efc92 100644 --- a/tools/gn/ninja_writer.h +++ b/tools/gn/ninja_writer.h @@ -5,20 +5,42 @@ #ifndef TOOLS_GN_NINJA_WRITER_H_ #define TOOLS_GN_NINJA_WRITER_H_ +#include <set> +#include <string> +#include <vector> + #include "base/basictypes.h" class BuildSettings; +class Settings; +class Target; class NinjaWriter { public: // On failure will print an error and will return false. static bool RunAndWriteFiles(const BuildSettings* build_settings); + // Writes only the toolchain.ninja files, skipping the root buildfile. The + // settings for the files written will be added to the vector. + // + // The skip files will avoid writing "subninja" rules when we're doing a + // side-by-side GYP build. .ninja files exactly matching the ones in the set + // will be ignored. + static bool RunAndWriteToolchainFiles( + const BuildSettings* build_settings, + const std::set<std::string>& skip_files, + std::vector<const Settings*>* all_settings); + private: NinjaWriter(const BuildSettings* build_settings); ~NinjaWriter(); - bool WriteRootBuildfiles(); + bool WriteToolchains( + const std::set<std::string>& skip_files, + std::vector<const Settings*>* all_settings, + std::vector<const Target*>* default_targets); + bool WriteRootBuildfiles(const std::vector<const Settings*>& all_settings, + const std::vector<const Target*>& default_targets); const BuildSettings* build_settings_; diff --git a/tools/gn/script_target_generator.cc b/tools/gn/script_target_generator.cc index 8df05b6..1725b7f 100644 --- a/tools/gn/script_target_generator.cc +++ b/tools/gn/script_target_generator.cc @@ -23,6 +23,7 @@ ScriptTargetGenerator::~ScriptTargetGenerator() { void ScriptTargetGenerator::DoRun() { target_->set_output_type(Target::CUSTOM); + FillExternal(); FillSources(); FillScript(); FillScriptArgs(); diff --git a/tools/gn/secondary/BUILD.gn b/tools/gn/secondary/BUILD.gn index 0ed32b1..25efbf0 100644 --- a/tools/gn/secondary/BUILD.gn +++ b/tools/gn/secondary/BUILD.gn @@ -5,13 +5,14 @@ group("root") { deps = [ "//base(//build/toolchain/nacl:x86_newlib)", + "//chrome", "//crypto", "//ipc", "//net", "//net/third_party/nss/ssl:crssl", "//sdch", "//third_party/icu:icudata", - "//third_party/zlib", + "//third_party/zlib:chrome_zlib", "//tools/gn", "//url:url_lib", ] diff --git a/tools/gn/secondary/base/BUILD.gn b/tools/gn/secondary/base/BUILD.gn index 0287b13..3ebd0d1 100644 --- a/tools/gn/secondary/base/BUILD.gn +++ b/tools/gn/secondary/base/BUILD.gn @@ -9,6 +9,7 @@ config("base_libs") { } component("base") { + external = true sources = [ "../build/build_config.h", "third_party/dmg_fp/dmg_fp.h", @@ -876,3 +877,147 @@ component("base_i18n") { #}, } +# TODO(brettw) move to base/test. +static_library("test_support_base") { + external = true + sources = [ + "test/expectations/expectation.cc", + "test/expectations/expectation.h", + "test/expectations/parser.cc", + "test/expectations/parser.h", + "test/gtest_xml_util.cc", + "test/gtest_xml_util.h", + "test/mock_chrome_application_mac.h", + "test/mock_chrome_application_mac.mm", + "test/mock_devices_changed_observer.cc", + "test/mock_devices_changed_observer.h", + "test/mock_time_provider.cc", + "test/mock_time_provider.h", + "test/multiprocess_test.cc", + "test/multiprocess_test.h", + "test/multiprocess_test_android.cc", + "test/null_task_runner.cc", + "test/null_task_runner.h", + "test/perf_test_suite.cc", + "test/perf_test_suite.h", + "test/perftimer.cc", + "test/scoped_locale.cc", + "test/scoped_locale.h", + "test/scoped_path_override.cc", + "test/scoped_path_override.h", + "test/sequenced_task_runner_test_template.cc", + "test/sequenced_task_runner_test_template.h", + "test/sequenced_worker_pool_owner.cc", + "test/sequenced_worker_pool_owner.h", + "test/simple_test_clock.cc", + "test/simple_test_clock.h", + "test/simple_test_tick_clock.cc", + "test/simple_test_tick_clock.h", + "test/task_runner_test_template.cc", + "test/task_runner_test_template.h", + "test/test_file_util.h", + "test/test_file_util_linux.cc", + "test/test_file_util_mac.cc", + "test/test_file_util_posix.cc", + "test/test_file_util_win.cc", + "test/test_launcher.cc", + "test/test_launcher.h", + "test/test_listener_ios.h", + "test/test_listener_ios.mm", + "test/test_pending_task.cc", + "test/test_pending_task.h", + "test/test_process_killer_win.cc", + "test/test_process_killer_win.h", + "test/test_reg_util_win.cc", + "test/test_reg_util_win.h", + "test/test_shortcut_win.cc", + "test/test_shortcut_win.h", + "test/test_simple_task_runner.cc", + "test/test_simple_task_runner.h", + "test/test_suite.cc", + "test/test_suite.h", + "test/test_support_android.cc", + "test/test_support_android.h", + "test/test_support_ios.h", + "test/test_support_ios.mm", + "test/test_switches.cc", + "test/test_switches.h", + "test/test_timeouts.cc", + "test/test_timeouts.h", + "test/thread_test_helper.cc", + "test/thread_test_helper.h", + "test/trace_event_analyzer.cc", + "test/trace_event_analyzer.h", + "test/unit_test_launcher.cc", + "test/unit_test_launcher.h", + "test/unit_test_launcher_ios.cc", + "test/values_test_util.cc", + "test/values_test_util.h", + ] + deps = [ + "//base", + "//base:base_static", + "//base:base_i18n", + "//testing:gmock", + "//testing:gtest", + "//third_party/libxml:libxml2", + ] + + if (!is_posix) { + sources -= [ + "scoped_locale.cc", + "scoped_locale.h", + ] + } + if (is_ios) { + # Pull in specific Mac files for iOS (which have been filtered out + # by file name rules). + set_sources_assignment_filter([]) + sources += "test_file_util_mac.cc" + } + #if (!is_bsd) { + # sources -= "test/test_file_util_linux.cc" + #} + #if (use_gtk) { + # deps += "/build/linux/system:gtk" + #} + #export_dependent_settings [ + # 'base', + #] +} + +# TODO(brettw) move to base/test. +config("perf_test_config") { + defines = [ "PERF_TEST" ] +} + +# TODO(brettw) move to base/test. +static_library("test_support_perf") { + external = true + sources = [ + "test/perftimer.cc", + "test/run_all_perftests.cc", + ] + deps = [ + "//base", + "//testing:gtest", + ] + + direct_dependent_configs = [ ":perf_test_config" ] + + #if (toolkit_uses_gtk) { + # deps += "/build/linux/system:gtk", + #} +} + +# TODO(brettw) move to base/test. +static_library("run_all_unittests") { + external = true + sources = [ + "test/run_all_unittests.cc", + ] + deps = [ + ":test_support_base", + ] +} + diff --git a/tools/gn/secondary/base/allocator/BUILD.gn b/tools/gn/secondary/base/allocator/BUILD.gn index 6766911..64d052d 100644 --- a/tools/gn/secondary/base/allocator/BUILD.gn +++ b/tools/gn/secondary/base/allocator/BUILD.gn @@ -3,6 +3,7 @@ # found in the LICENSE file. static_library("allocator_extension_thunks") { + external = true sources = [ "allocator_extension_thunks.cc", "allocator_extension_thunks.h", diff --git a/tools/gn/secondary/base/test/BUILD.gn b/tools/gn/secondary/base/test/BUILD.gn deleted file mode 100644 index aacb9e1..0000000 --- a/tools/gn/secondary/base/test/BUILD.gn +++ /dev/null @@ -1,133 +0,0 @@ -# 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. - -static_library("test_support_base") { - sources = [ - "expectations/expectation.cc", - "expectations/expectation.h", - "expectations/parser.cc", - "expectations/parser.h", - "mock_chrome_application_mac.h", - "mock_chrome_application_mac.mm", - "mock_devices_changed_observer.cc", - "mock_devices_changed_observer.h", - "mock_time_provider.cc", - "mock_time_provider.h", - "multiprocess_test.cc", - "multiprocess_test.h", - "multiprocess_test_android.cc", - "null_task_runner.cc", - "null_task_runner.h", - "perf_test_suite.cc", - "perf_test_suite.h", - "perftimer.cc", - "scoped_locale.cc", - "scoped_locale.h", - "scoped_path_override.cc", - "scoped_path_override.h", - "sequenced_task_runner_test_template.cc", - "sequenced_task_runner_test_template.h", - "sequenced_worker_pool_owner.cc", - "sequenced_worker_pool_owner.h", - "simple_test_clock.cc", - "simple_test_clock.h", - "simple_test_tick_clock.cc", - "simple_test_tick_clock.h", - "task_runner_test_template.cc", - "task_runner_test_template.h", - "test_file_util.h", - "test_file_util_linux.cc", - "test_file_util_mac.cc", - "test_file_util_posix.cc", - "test_file_util_win.cc", - "test_listener_ios.h", - "test_listener_ios.mm", - "test_pending_task.cc", - "test_pending_task.h", - "test_process_killer_win.cc", - "test_process_killer_win.h", - "test_reg_util_win.cc", - "test_reg_util_win.h", - "test_shortcut_win.cc", - "test_shortcut_win.h", - "test_simple_task_runner.cc", - "test_simple_task_runner.h", - "test_suite.cc", - "test_suite.h", - "test_support_android.cc", - "test_support_android.h", - "test_support_ios.h", - "test_support_ios.mm", - "test_switches.cc", - "test_switches.h", - "test_timeouts.cc", - "test_timeouts.h", - "thread_test_helper.cc", - "thread_test_helper.h", - "trace_event_analyzer.cc", - "trace_event_analyzer.h", - "values_test_util.cc", - "values_test_util.h", - ] - deps = [ - "//base", - "//base:base_static", - "//base:base_i18n", - "//testing/gmock", - "//testing/gtest", - ] - - if (!is_posix) { - sources -= [ - "scoped_locale.cc", - "scoped_locale.h", - ] - } - if (is_ios) { - # Pull in specific Mac files for iOS (which have been filtered out - # by file name rules). - set_sources_assignment_filter([]) - sources += "test_file_util_mac.cc" - } - #if (!is_bsd) { - # sources -= "test/test_file_util_linux.cc" - #} - #if (use_gtk) { - # deps += "/build/linux/system:gtk" - #} - #export_dependent_settings [ - # 'base', - #] -} - -config("perf_test_config") { - defines = [ "PERF_TEST" ] -} - -static_library("test_support_perf") { - sources = [ - "perftimer.cc", - "run_all_perftests.cc", - ] - deps = [ - "//base", - "//testing/gtest", - ] - - direct_dependent_configs = [ ":perf_test_config" ] - - #if (toolkit_uses_gtk) { - # deps += "/build/linux/system:gtk", - #} -} - -static_library("run_all_unittests") { - sources = [ - "run_all_unittests.cc", - ] - deps = [ - ":test_support_base", - ] -} - diff --git a/tools/gn/secondary/base/third_party/dynamic_annotations/BUILD.gn b/tools/gn/secondary/base/third_party/dynamic_annotations/BUILD.gn index bf050bf..02beae0 100644 --- a/tools/gn/secondary/base/third_party/dynamic_annotations/BUILD.gn +++ b/tools/gn/secondary/base/third_party/dynamic_annotations/BUILD.gn @@ -3,6 +3,7 @@ # found in the LICENSE file. static_library("dynamic_annotations") { + external = true sources = [ "dynamic_annotations.c", "dynamic_annotations.h", diff --git a/tools/gn/secondary/base/third_party/nspr/BUILD.gn b/tools/gn/secondary/base/third_party/nspr/BUILD.gn index dafd9f1..226f3d8 100644 --- a/tools/gn/secondary/base/third_party/nspr/BUILD.gn +++ b/tools/gn/secondary/base/third_party/nspr/BUILD.gn @@ -3,6 +3,7 @@ # found in the LICENSE file. static_library("nspr") { + external = true sources = [ "prcpucfg.h", "prcpucfg_freebsd.h", diff --git a/tools/gn/secondary/base/third_party/symbolize/BUILD.gn b/tools/gn/secondary/base/third_party/symbolize/BUILD.gn index c13c0d8..f4af9bd 100644 --- a/tools/gn/secondary/base/third_party/symbolize/BUILD.gn +++ b/tools/gn/secondary/base/third_party/symbolize/BUILD.gn @@ -3,6 +3,7 @@ # found in the LICENSE file. static_library("symbolize") { + external = true sources = [ "config.h", "demangle.cc", diff --git a/tools/gn/secondary/base/third_party/xdg_mime/BUILD.gn b/tools/gn/secondary/base/third_party/xdg_mime/BUILD.gn index 9e51bc1..32d9ac4 100644 --- a/tools/gn/secondary/base/third_party/xdg_mime/BUILD.gn +++ b/tools/gn/secondary/base/third_party/xdg_mime/BUILD.gn @@ -3,6 +3,7 @@ # found in the LICENSE file. static_library("xdg_mime") { + external = true sources = [ "xdgmime.c", "xdgmime.h", diff --git a/tools/gn/secondary/base/third_party/xdg_user_dirs/BUILD.gn b/tools/gn/secondary/base/third_party/xdg_user_dirs/BUILD.gn index f2145b7..eda4e02 100644 --- a/tools/gn/secondary/base/third_party/xdg_user_dirs/BUILD.gn +++ b/tools/gn/secondary/base/third_party/xdg_user_dirs/BUILD.gn @@ -3,6 +3,7 @@ # found in the LICENSE file. static_library("xdg_user_dirs") { + external = true sources = [ "xdg_user_dir_lookup.cc", "xdg_user_dir_lookup.h", diff --git a/tools/gn/secondary/build/config/linux/BUILD.gn b/tools/gn/secondary/build/config/linux/BUILD.gn index dec72a7..d6a8499 100644 --- a/tools/gn/secondary/build/config/linux/BUILD.gn +++ b/tools/gn/secondary/build/config/linux/BUILD.gn @@ -30,6 +30,8 @@ config("gtk") { # misconfigured systems. gtk_packages = "gmodule-2.0 gtk+-2.0 gthread-2.0" + defines = [ "TOOLKIT_GTK" ] + cflags = exec_script(pkg_script, [ "--cflags", gtk_packages ], "list lines") ldflags = exec_script(pkg_script, [ "--libs", gtk_packages ], "list lines") } @@ -37,6 +39,8 @@ config("gtk") { config("x11") { x11_packages = "x11 xi" + defines = [ "USE_X11" ] + cflags = exec_script(pkg_script, [ "--cflags", x11_packages ], "list lines") ldflags = exec_script(pkg_script, [ "--libs", x11_packages ], "list lines") } diff --git a/tools/gn/secondary/crypto/BUILD.gn b/tools/gn/secondary/crypto/BUILD.gn index ff6a0c3..02676bd 100644 --- a/tools/gn/secondary/crypto/BUILD.gn +++ b/tools/gn/secondary/crypto/BUILD.gn @@ -5,6 +5,7 @@ import("ssl/flags.gni") component("crypto") { + external = true sources = [ "apple_keychain.h", "apple_keychain_ios.mm", @@ -166,6 +167,7 @@ component("crypto") { # A minimal crypto subset for core features that small standalone targets can # use to reduce code size. static_library("crypto_minimal") { + external = true sources = [ "hmac.cc", "hmac.h", @@ -187,6 +189,7 @@ static_library("crypto_minimal") { } test("crypto_unittests") { + external = true sources = [ # Infrastructure files. "run_all_unittests.cc", @@ -224,9 +227,9 @@ test("crypto_unittests") { deps = [ ":crypto", "//base", - "//base/test:test_support_base", - "//testing/gmock", - "//testing/gtest", + "//base:test_support_base", + "//testing:gmock", + "//testing:gtest", ] if (is_mac) { diff --git a/tools/gn/secondary/ipc/BUILD.gn b/tools/gn/secondary/ipc/BUILD.gn index a0b5f2b..d65d5c6 100644 --- a/tools/gn/secondary/ipc/BUILD.gn +++ b/tools/gn/secondary/ipc/BUILD.gn @@ -3,6 +3,7 @@ # found in the LICENSE file. component("ipc") { + external = true sources = [ "file_descriptor_set_posix.cc", "file_descriptor_set_posix.h", @@ -79,6 +80,7 @@ component("ipc") { } test("ipc_tests") { + external = true sources = [ "file_descriptor_set_posix_unittest.cc", "ipc_channel_posix_unittest.cc", @@ -116,13 +118,14 @@ test("ipc_tests") { ":test_support_ipc", "//base", "//base:base_i18n", - "//base/test:run_all_unittests", - "//base/test:test_support_base", - "//testing/gtest", + "//base:run_all_unittests", + "//base:test_support_base", + "//testing:gtest", ] } test("ipc_perftests") { + external = true sources = [ "ipc_perftests.cc", "ipc_test_base.cc", @@ -146,13 +149,14 @@ test("ipc_perftests") { ":test_support_ipc", "//base", "//base:base_i18n", - "//base/test:test_support_base", - "//base/test:test_support_perf", - "//testing/gtest", + "//base:test_support_base", + "//base:test_support_perf", + "//testing:gtest", ] } static_library("test_support_ipc") { + external = true sources = [ "ipc_multiprocess_test.cc", "ipc_multiprocess_test.h", @@ -162,7 +166,7 @@ static_library("test_support_ipc") { deps = [ ":ipc", "//base", - "//testing/gtest", + "//testing:gtest", ] } diff --git a/tools/gn/secondary/net/BUILD.gn b/tools/gn/secondary/net/BUILD.gn index 4d3e8f3..a0941d9 100644 --- a/tools/gn/secondary/net/BUILD.gn +++ b/tools/gn/secondary/net/BUILD.gn @@ -6,6 +6,7 @@ import("//crypto/ssl/flags.gni") import("//tools/grit/grit_rule.gni") component("net") { + external = true sources = [ "android/cert_verify_result_android.h", "android/cert_verify_result_android_list.h", @@ -1068,7 +1069,7 @@ component("net") { "//sdch", "//third_party/icu:icui18n", "//third_party/icu:icuuc", - "//third_party/zlib", + "//third_party/zlib:chrome_zlib", "//url:url_lib", ] @@ -1198,5 +1199,6 @@ component("net") { } grit("net_resources") { + external = true source = "base/net_resources.grd" } diff --git a/tools/gn/secondary/net/third_party/nss/ssl/BUILD.gn b/tools/gn/secondary/net/third_party/nss/ssl/BUILD.gn index 0410146..e72988d 100644 --- a/tools/gn/secondary/net/third_party/nss/ssl/BUILD.gn +++ b/tools/gn/secondary/net/third_party/nss/ssl/BUILD.gn @@ -10,6 +10,7 @@ config("crssl_config") { # Not named "ssl" so the lib doesn't conflict with OpenSSL's libssl component("crssl") { + external = true sources = [ "authcert.c", "cmpcert.c", diff --git a/tools/gn/secondary/sdch/BUILD.gn b/tools/gn/secondary/sdch/BUILD.gn index 2c5849c..9396624 100644 --- a/tools/gn/secondary/sdch/BUILD.gn +++ b/tools/gn/secondary/sdch/BUILD.gn @@ -7,6 +7,7 @@ config("sdch_config") { } static_library("sdch") { + external = true sources = [ "open-vcdiff/src/addrcache.cc", "open-vcdiff/src/blockhash.cc", @@ -51,5 +52,5 @@ static_library("sdch") { includes = [ "win" ] } - deps = [ "//third_party/zlib" ] + deps = [ "//third_party/zlib:chrome_zlib" ] } diff --git a/tools/gn/secondary/testing/BUILD.gn b/tools/gn/secondary/testing/BUILD.gn new file mode 100644 index 0000000..8e88278 --- /dev/null +++ b/tools/gn/secondary/testing/BUILD.gn @@ -0,0 +1,98 @@ +# 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. + +# TODO(brettw) move to testing/gtest/BUILD.gn +config("gtest_config") { + defines = [ "UNIT_TEST" ] + includes = [ "gtest/include" ] # Gtest headers need to be able to find themselves. +} + +# TODO(brettw) move to testing/gtest/BUILD.gn +static_library("gtest") { + external = true + sources = [ + "gtest/include/gtest/gtest-death-test.h", + "gtest/include/gtest/gtest-message.h", + "gtest/include/gtest/gtest-param-test.h", + "gtest/include/gtest/gtest-printers.h", + "gtest/include/gtest/gtest-spi.h", + "gtest/include/gtest/gtest-test-part.h", + "gtest/include/gtest/gtest-typed-test.h", + "gtest/include/gtest/gtest.h", + "gtest/include/gtest/gtest_pred_impl.h", + "gtest/include/gtest/internal/gtest-death-test-internal.h", + "gtest/include/gtest/internal/gtest-filepath.h", + "gtest/include/gtest/internal/gtest-internal.h", + "gtest/include/gtest/internal/gtest-linked_ptr.h", + "gtest/include/gtest/internal/gtest-param-util-generated.h", + "gtest/include/gtest/internal/gtest-param-util.h", + "gtest/include/gtest/internal/gtest-port.h", + "gtest/include/gtest/internal/gtest-string.h", + "gtest/include/gtest/internal/gtest-tuple.h", + "gtest/include/gtest/internal/gtest-type-util.h", + #"gtest/src/gtest-all.cc", # Not needed by our build. + "gtest/src/gtest-death-test.cc", + "gtest/src/gtest-filepath.cc", + "gtest/src/gtest-internal-inl.h", + "gtest/src/gtest-port.cc", + "gtest/src/gtest-printers.cc", + "gtest/src/gtest-test-part.cc", + "gtest/src/gtest-typed-test.cc", + "gtest/src/gtest.cc", + "multiprocess_func_list.cc", + "multiprocess_func_list.h", + "platform_test.h", + ] + + includes = [ "gtest" ] + direct_dependent_configs = [ ":gtest_config" ] +} + +# TODO(brettw) move to testing/gmock/BUILD.gn +config("gmock_config") { + # Gmock headers need to be able to find themselves. + includes = [ "gmock/include" ] +} + +# TODO(brettw) move to testing/gmock/BUILD.gn +static_library("gmock") { + external = true + sources = [ + # Sources based on files in r173 of gmock. + "gmock/include/gmock/gmock-actions.h", + "gmock/include/gmock/gmock-cardinalities.h", + "gmock/include/gmock/gmock-generated-actions.h", + "gmock/include/gmock/gmock-generated-function-mockers.h", + "gmock/include/gmock/gmock-generated-matchers.h", + "gmock/include/gmock/gmock-generated-nice-strict.h", + "gmock/include/gmock/gmock-matchers.h", + "gmock/include/gmock/gmock-spec-builders.h", + "gmock/include/gmock/gmock.h", + "gmock/include/gmock/internal/gmock-generated-internal-utils.h", + "gmock/include/gmock/internal/gmock-internal-utils.h", + "gmock/include/gmock/internal/gmock-port.h", + #"gmock/src/gmock-all.cc", # Not needed by our build. + "gmock/src/gmock-cardinalities.cc", + "gmock/src/gmock-internal-utils.cc", + "gmock/src/gmock-matchers.cc", + "gmock/src/gmock-spec-builders.cc", + "gmock/src/gmock.cc", + "gmock_mutant.h", # gMock helpers + ] + + # This project includes some stuff form gtest's guts. + includes = [ "gtest/include" ] + + direct_dependent_configs = [ + ":gmock_config", + "//testing:gtest_config", + ] +} + +# TODO(brettw) move to testing/gmock/BUILD.gn +static_library("gmock_main") { + external = true + sources = [ "src/gmock_main.cc" ] + deps = [ ":gmock" ] +} diff --git a/tools/gn/secondary/testing/gmock/BUILD.gn b/tools/gn/secondary/testing/gmock/BUILD.gn deleted file mode 100644 index 532d2a4..0000000 --- a/tools/gn/secondary/testing/gmock/BUILD.gn +++ /dev/null @@ -1,46 +0,0 @@ -# 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. - -config("gmock_config") { - # Gmock headers need to be able to find themselves. - includes = [ "include" ] -} - -static_library("gmock") { - sources = [ - # Sources based on files in r173 of gmock. - "include/gmock/gmock-actions.h", - "include/gmock/gmock-cardinalities.h", - "include/gmock/gmock-generated-actions.h", - "include/gmock/gmock-generated-function-mockers.h", - "include/gmock/gmock-generated-matchers.h", - "include/gmock/gmock-generated-nice-strict.h", - "include/gmock/gmock-matchers.h", - "include/gmock/gmock-spec-builders.h", - "include/gmock/gmock.h", - "include/gmock/internal/gmock-generated-internal-utils.h", - "include/gmock/internal/gmock-internal-utils.h", - "include/gmock/internal/gmock-port.h", - #"src/gmock-all.cc", # Not needed by our build. - "src/gmock-cardinalities.cc", - "src/gmock-internal-utils.cc", - "src/gmock-matchers.cc", - "src/gmock-spec-builders.cc", - "src/gmock.cc", - "../gmock_mutant.h", # gMock helpers - ] - - # This project includes some stuff form gtest's guts. - includes = [ "../gtest/include" ] - - direct_dependent_configs = [ - ":gmock_config", - "//testing/gtest:gtest_config", - ] -} - -static_library("gmock_main") { - sources = [ "src/gmock_main.cc" ] - deps = [ ":gmock" ] -} diff --git a/tools/gn/secondary/testing/gtest/BUILD.gn b/tools/gn/secondary/testing/gtest/BUILD.gn deleted file mode 100644 index 05bedda..0000000 --- a/tools/gn/secondary/testing/gtest/BUILD.gn +++ /dev/null @@ -1,47 +0,0 @@ -# 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. - -config("gtest_config") { - defines = [ "UNIT_TEST" ] - includes = [ "include" ] # Gtest headers need to be able to find themselves. -} - -static_library("gtest") { - sources = [ - "include/gtest/gtest-death-test.h", - "include/gtest/gtest-message.h", - "include/gtest/gtest-param-test.h", - "include/gtest/gtest-printers.h", - "include/gtest/gtest-spi.h", - "include/gtest/gtest-test-part.h", - "include/gtest/gtest-typed-test.h", - "include/gtest/gtest.h", - "include/gtest/gtest_pred_impl.h", - "include/gtest/internal/gtest-death-test-internal.h", - "include/gtest/internal/gtest-filepath.h", - "include/gtest/internal/gtest-internal.h", - "include/gtest/internal/gtest-linked_ptr.h", - "include/gtest/internal/gtest-param-util-generated.h", - "include/gtest/internal/gtest-param-util.h", - "include/gtest/internal/gtest-port.h", - "include/gtest/internal/gtest-string.h", - "include/gtest/internal/gtest-tuple.h", - "include/gtest/internal/gtest-type-util.h", - #"src/gtest-all.cc", # Not needed by our build. - "src/gtest-death-test.cc", - "src/gtest-filepath.cc", - "src/gtest-internal-inl.h", - "src/gtest-port.cc", - "src/gtest-printers.cc", - "src/gtest-test-part.cc", - "src/gtest-typed-test.cc", - "src/gtest.cc", - "../multiprocess_func_list.cc", - "../multiprocess_func_list.h", - "../platform_test.h", - ] - - includes = [ "." ] - direct_dependent_configs = [ ":gtest_config" ] -} diff --git a/tools/gn/secondary/third_party/icu/BUILD.gn b/tools/gn/secondary/third_party/icu/BUILD.gn index f78d981..1db4c2e 100644 --- a/tools/gn/secondary/third_party/icu/BUILD.gn +++ b/tools/gn/secondary/third_party/icu/BUILD.gn @@ -45,6 +45,7 @@ config("icu_code") { } component("icui18n") { + external = true sources = [ "source/i18n/anytrans.cpp", "source/i18n/astro.cpp", @@ -217,6 +218,7 @@ component("icui18n") { } component("icuuc") { + external = true sources = [ "source/common/bmpset.cpp", "source/common/brkeng.cpp", @@ -400,11 +402,13 @@ component("icuuc") { if (is_win) { # On Windows the target DLL is pre-built so just use a copy rule. copy("icudata") { + external = true sources = [ "windows/icudt.dll" ] destdir = root_output_dir } } else { static_library("icudata") { + external = true sources = [ # These are hand-generated, but will do for now. The linux version is an # identical copy of the (mac) icudt46l_dat.S file, modulo removal of the diff --git a/tools/gn/secondary/third_party/libevent/BUILD.gn b/tools/gn/secondary/third_party/libevent/BUILD.gn index afbd67d..ea7cb27 100644 --- a/tools/gn/secondary/third_party/libevent/BUILD.gn +++ b/tools/gn/secondary/third_party/libevent/BUILD.gn @@ -3,6 +3,7 @@ # found in the LICENSE file. static_library("libevent") { + external = true sources = [ "buffer.c", "epoll.c", diff --git a/tools/gn/secondary/third_party/libxml/BUILD.gn b/tools/gn/secondary/third_party/libxml/BUILD.gn new file mode 100644 index 0000000..2a7a3de --- /dev/null +++ b/tools/gn/secondary/third_party/libxml/BUILD.gn @@ -0,0 +1,176 @@ +# 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. + +# Define an "os_include" variable that points at the OS-specific generated +# headers. These were generated by running the configure script offline. +if (is_linux) { + os_include = "linux" +} else if (is_mac) { + os_include = "mac" +} else if (is_win) { + os_include = "win32" +} + +config("libxml_config") { + # Define LIBXML_STATIC as nothing to match how libxml.h (an internal header) + # defines LIBXML_STATIC, otherwise we get the macro redefined warning from + # GCC. ("defines" does "-DFOO" which defines the macro FOO as 1.) + cflags = [ "-DLIBXML_STATIC=" ] + + includes = [ + "src/include", + "$os_include/include", + ] +} + +static_library("libxml2") { + external = true + sources = [ + "chromium/libxml_utils.h", + "chromium/libxml_utils.cc", + "linux/config.h", + "linux/include/libxml/xmlversion.h", + "mac/config.h", + "mac/include/libxml/xmlversion.h", + "src/include/libxml/c14n.h", + "src/include/libxml/catalog.h", + "src/include/libxml/chvalid.h", + "src/include/libxml/debugXML.h", + "src/include/libxml/dict.h", + "src/include/libxml/DOCBparser.h", + "src/include/libxml/encoding.h", + "src/include/libxml/entities.h", + "src/include/libxml/globals.h", + "src/include/libxml/hash.h", + "src/include/libxml/HTMLparser.h", + "src/include/libxml/HTMLtree.h", + "src/include/libxml/list.h", + "src/include/libxml/nanoftp.h", + "src/include/libxml/nanohttp.h", + "src/include/libxml/parser.h", + "src/include/libxml/parserInternals.h", + "src/include/libxml/pattern.h", + "src/include/libxml/relaxng.h", + "src/include/libxml/SAX.h", + "src/include/libxml/SAX2.h", + "src/include/libxml/schemasInternals.h", + "src/include/libxml/schematron.h", + "src/include/libxml/threads.h", + "src/include/libxml/tree.h", + "src/include/libxml/uri.h", + "src/include/libxml/valid.h", + "src/include/libxml/xinclude.h", + "src/include/libxml/xlink.h", + "src/include/libxml/xmlautomata.h", + "src/include/libxml/xmlerror.h", + "src/include/libxml/xmlexports.h", + "src/include/libxml/xmlIO.h", + "src/include/libxml/xmlmemory.h", + "src/include/libxml/xmlmodule.h", + "src/include/libxml/xmlreader.h", + "src/include/libxml/xmlregexp.h", + "src/include/libxml/xmlsave.h", + "src/include/libxml/xmlschemas.h", + "src/include/libxml/xmlschemastypes.h", + "src/include/libxml/xmlstring.h", + "src/include/libxml/xmlunicode.h", + "src/include/libxml/xmlwriter.h", + "src/include/libxml/xpath.h", + "src/include/libxml/xpathInternals.h", + "src/include/libxml/xpointer.h", + "src/include/win32config.h", + "src/include/wsockcompat.h", + "src/acconfig.h", + "src/c14n.c", + "src/catalog.c", + "src/chvalid.c", + "src/debugXML.c", + "src/dict.c", + "src/DOCBparser.c", + "src/elfgcchack.h", + "src/encoding.c", + "src/entities.c", + "src/error.c", + "src/globals.c", + "src/hash.c", + "src/HTMLparser.c", + "src/HTMLtree.c", + "src/legacy.c", + "src/libxml.h", + "src/list.c", + "src/nanoftp.c", + "src/nanohttp.c", + "src/parser.c", + "src/parserInternals.c", + "src/pattern.c", + "src/relaxng.c", + "src/SAX.c", + "src/SAX2.c", + "src/schematron.c", + "src/threads.c", + "src/tree.c", + #"src/trio.c", + #"src/trio.h", + #"src/triodef.h", + #"src/trionan.c", + #"src/trionan.h", + #"src/triop.h", + #"src/triostr.c", + #"src/triostr.h", + "src/uri.c", + "src/valid.c", + "src/xinclude.c", + "src/xlink.c", + "src/xmlIO.c", + "src/xmlmemory.c", + "src/xmlmodule.c", + "src/xmlreader.c", + "src/xmlregexp.c", + "src/xmlsave.c", + "src/xmlschemas.c", + "src/xmlschemastypes.c", + "src/xmlstring.c", + "src/xmlunicode.c", + "src/xmlwriter.c", + "src/xpath.c", + "src/xpointer.c", + "win32/config.h", + "win32/include/libxml/xmlversion.h", + ] + + configs -= "//build/config/compiler:chromium_code" + configs += "//build/config/compiler:no_chromium_code" + + direct_dependent_configs = [ ":libxml_config" ] + forward_dependent_configs_from = [ "//third_party/icu:icuuc" ] + + deps = [ + "//third_party/icu:icuuc", + "//third_party/zlib:chrome_zlib", + ] + + if (is_linux) { + # We need dl for dlopen() and friends. + ldflags = [ "-ldl" ] + } + + if (is_clang) { + cflags = [ + # libxml passes `const unsigned char*` through `const char*`. + "-Wno-pointer-sign", + + # pattern.c and uri.c both have an intentional `for (...);` / + # `while(...);` loop. I submitted a patch to move the `'` to its own + # line, but until that's landed suppress the warning: + "-Wno-empty-body", + + # See http://crbug.com/138571#c8 + "-Wno-ignored-attributes", + ] + } + + includes = [ + "$os_include", + ] +} diff --git a/tools/gn/secondary/third_party/mach_override/BUILD.gn b/tools/gn/secondary/third_party/mach_override/BUILD.gn index 13317b1..1786c1d 100644 --- a/tools/gn/secondary/third_party/mach_override/BUILD.gn +++ b/tools/gn/secondary/third_party/mach_override/BUILD.gn @@ -3,6 +3,7 @@ # found in the LICENSE file. static_library("mach_override") { + external = true sources = [ "mach_override.c", "mach_override.h", diff --git a/tools/gn/secondary/third_party/modp_b64/BUILD.gn b/tools/gn/secondary/third_party/modp_b64/BUILD.gn index 539abe1..bfa7479 100644 --- a/tools/gn/secondary/third_party/modp_b64/BUILD.gn +++ b/tools/gn/secondary/third_party/modp_b64/BUILD.gn @@ -3,6 +3,7 @@ # found in the LICENSE file. static_library("modp_b64") { + external = true sources = [ "modp_b64.cc", "modp_b64.h", diff --git a/tools/gn/secondary/third_party/wtl/BUILD.gn b/tools/gn/secondary/third_party/wtl/BUILD.gn index 07c6ab2..a21ff7e 100644 --- a/tools/gn/secondary/third_party/wtl/BUILD.gn +++ b/tools/gn/secondary/third_party/wtl/BUILD.gn @@ -10,5 +10,6 @@ config("wtl_includes") { # actually generate anything linkable, and inject the required config for # making the include directories work. group("wtl") { + external = true all_dependent_configs = ":wtl_includes" } diff --git a/tools/gn/secondary/third_party/zlib/BUILD.gn b/tools/gn/secondary/third_party/zlib/BUILD.gn index 7805328..749043c 100644 --- a/tools/gn/secondary/third_party/zlib/BUILD.gn +++ b/tools/gn/secondary/third_party/zlib/BUILD.gn @@ -6,7 +6,8 @@ config("zlib_config") { includes = [ "." ] } -static_library("zlib") { +static_library("chrome_zlib") { + external = true sources = [ "adler32.c", "compress.c", @@ -41,6 +42,7 @@ static_library("zlib") { } static_library("minizip") { + external = true sources = [ "contrib/minizip/ioapi.c", "contrib/minizip/ioapi.h", @@ -68,12 +70,13 @@ static_library("minizip") { cflags = [ "-Wno-parentheses-equality" ] } - deps = [ ":zlib" ] + deps = [ ":chrome_zlib" ] direct_dependent_configs = [ ":zlib_config" ] } static_library("zip") { + external = true sources = [ "google/zip.cc", "google/zip.h", diff --git a/tools/gn/secondary/url/BUILD.gn b/tools/gn/secondary/url/BUILD.gn index b9d400a..4b6ee1d 100644 --- a/tools/gn/secondary/url/BUILD.gn +++ b/tools/gn/secondary/url/BUILD.gn @@ -6,6 +6,7 @@ # for a Windows component build, and that will confuse Windows, which has a # system DLL with the same name. component("url_lib") { + external = true sources = [ "gurl.cc", "gurl.h", @@ -48,6 +49,7 @@ component("url_lib") { } test("url_unittests") { + external = true sources = [ "gurl_unittest.cc", "url_canon_unittest.cc", @@ -59,8 +61,8 @@ test("url_unittests") { deps = [ ":url_lib", "//base:base_i18n", - "//base/test:run_all_unittests", - "//testing/gtest", + "//base:run_all_unittests", + "//testing:gtest", "//third_party/icu:icuuc", ] } diff --git a/tools/gn/setup.cc b/tools/gn/setup.cc index 8fba875..69cbaa0 100644 --- a/tools/gn/setup.cc +++ b/tools/gn/setup.cc @@ -173,7 +173,7 @@ bool Setup::FillArguments(const CommandLine& cmdline) { // Save the result of the command args. Scope::KeyValueMap overrides; arg_scope.GetCurrentScopeValues(&overrides); - build_settings_.build_args().SwapInArgOverrides(&overrides); + build_settings_.build_args().AddArgOverrides(overrides); return true; } diff --git a/tools/gn/target.cc b/tools/gn/target.cc index 0d7a492..eabc532 100644 --- a/tools/gn/target.cc +++ b/tools/gn/target.cc @@ -63,6 +63,7 @@ Target::Target(const Settings* settings, const Label& label) : Item(label), settings_(settings), output_type_(UNKNOWN), + external_(false), generated_(false), generator_function_(NULL) { } diff --git a/tools/gn/target.h b/tools/gn/target.h index 2e55805..fda4839 100644 --- a/tools/gn/target.h +++ b/tools/gn/target.h @@ -108,6 +108,9 @@ class Target : public Item { forward_dependent_configs_.swap(*t); } + bool external() const { return external_; } + void set_external(bool e) { external_ = e; } + const std::set<const Target*>& inherited_libraries() const { return inherited_libraries_; } @@ -135,6 +138,8 @@ class Target : public Item { std::vector<const Config*> direct_dependent_configs_; std::vector<const Target*> forward_dependent_configs_; + bool external_; + // Libraries from transitive deps. Libraries need to be linked only // with the end target (executable, shared library). These do not get // pushed beyond shared library boundaries. diff --git a/tools/gn/target_generator.cc b/tools/gn/target_generator.cc index 5421d93..c8e9ff8 100644 --- a/tools/gn/target_generator.cc +++ b/tools/gn/target_generator.cc @@ -159,6 +159,15 @@ void TargetGenerator::FillDependencies() { FillForwardDependentConfigs(); } +void TargetGenerator::FillExternal() { + const Value* value = scope_->GetValue(variables::kExternal, true); + if (!value) + return; + if (!value->VerifyTypeIs(Value::BOOLEAN, err_)) + return; + target_->set_external(value->boolean_value()); +} + void TargetGenerator::SetToolchainDependency() { // TODO(brettw) currently we lock separately for each config, dep, and // toolchain we add which is bad! Do this in one lock. diff --git a/tools/gn/target_generator.h b/tools/gn/target_generator.h index 2b16ee0..be291d7 100644 --- a/tools/gn/target_generator.h +++ b/tools/gn/target_generator.h @@ -50,6 +50,7 @@ class TargetGenerator { void FillSources(); void FillConfigs(); + void FillExternal(); // Sets the current toolchain as a dependecy of this target. All targets with // a dependency on the toolchain should call this function. diff --git a/tools/gn/variables.cc b/tools/gn/variables.cc index 85cfa38..7984fcb 100644 --- a/tools/gn/variables.cc +++ b/tools/gn/variables.cc @@ -393,6 +393,22 @@ const char kDirectDependentConfigs_Help[] = "\n" " See also \"all_dependent_configs\".\n"; +const char kExternal[] = "external"; +const char kExternal_HelpShort[] = + "external: [boolean] Declares a target as externally generated."; +const char kExternal_Help[] = + "external: Declares a target as externally generated.\n" + "\n" + " External targets are treated like normal targets as far as dependent\n" + " targets are concerned, but do not actually have their .ninja file\n" + " written to disk. This allows them to be generated by an external\n" + " program (e.g. GYP).\n" + "\n" + "Example:\n" + " static_library(\"foo\") {\n" + " external = true\n" + " }\n"; + const char kForwardDependentConfigsFrom[] = "forward_dependent_configs_from"; const char kForwardDependentConfigsFrom_HelpShort[] = "forward_dependent_configs_from: [label list] Forward dependent's configs."; @@ -501,6 +517,7 @@ const VariableInfoMap& GetTargetVariables() { INSERT_VARIABLE(Datadeps) INSERT_VARIABLE(Deps) INSERT_VARIABLE(DirectDependentConfigs) + INSERT_VARIABLE(External) INSERT_VARIABLE(ForwardDependentConfigsFrom) INSERT_VARIABLE(Ldflags) INSERT_VARIABLE(Sources) diff --git a/tools/gn/variables.h b/tools/gn/variables.h index 526e796..bddd32a 100644 --- a/tools/gn/variables.h +++ b/tools/gn/variables.h @@ -119,6 +119,10 @@ extern const char kDirectDependentConfigs[]; extern const char kDirectDependentConfigs_HelpShort[]; extern const char kDirectDependentConfigs_Help[]; +extern const char kExternal[]; +extern const char kExternal_HelpShort[]; +extern const char kExternal_Help[]; + extern const char kForwardDependentConfigsFrom[]; extern const char kForwardDependentConfigsFrom_HelpShort[]; extern const char kForwardDependentConfigsFrom_Help[]; |