Skip to content

Commit

Permalink
Add initial prototype for the GN meta-buildsystem.
Browse files Browse the repository at this point in the history
This is currently not hooked into the build. To build, add a reference to the
gn.gyp file to build/all.gyp

R=darin@chromium.org, scottmg@chromium.org

Review URL: https://codereview.chromium.org/21114002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214254 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
brettw@chromium.org committed Jul 29, 2013
1 parent 6e778e0 commit c88bd8f
Show file tree
Hide file tree
Showing 140 changed files with 18,197 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file is used by the experimental meta-buildsystem in src/tools/gn to
# find the root of the source tree and to set startup options.

# The location of the build configuration file.
buildconfig = "//build/config/BUILDCONFIG.gn"

# The secondary source root is a parallel directory tree where
secondary_source = "//tools/gn/secondary/"
153 changes: 153 additions & 0 deletions tools/gn/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
static_library("gn_lib") {
sources = [
"build_settings.cc",
"build_settings.h",
"command_desc.cc",
"command_desc.h",
"command_gen.cc",
"command_gen.h",
"command.cc",
"config.cc",
"config.h",
"config_values.h",
"config_values_extractors.cc",
"config_values_extractors.h",
"config_values_generator.cc",
"config_values_generator.h",
"err.cc",
"err.h",
"escape.cc",
"escape.h",
"file_template.cc",
"file_template.h",
"filesystem_utils.cc",
"filesystem_utils.h",
"functions.cc",
"functions.h",
"functions_target.cc",
"function_exec_script.cc",
"function_process_file_template.cc",
"function_read_file.cc",
"function_set_default_toolchain.cc",
"function_template.cc",
"function_toolchain.cc",
"function_write_file.cc",
"import_manager.cc",
"import_manager.h",
"input_conversion.cc",
"input_conversion.h",
"input_file.cc",
"input_file.h",
"input_file_manager.cc",
"input_file_manager.h",
"item.cc",
"item.h",
"item_node.cc",
"item_node.h",
"item_tree.cc",
"item_tree.h",
"label.cc",
"label.h",
"location.h",
"ninja_build_writer.cc",
"ninja_build_writer.h",
"ninja_helper.cc",
"ninja_helper.h",
"ninja_target_writer.cc",
"ninja_target_writer.h",
"ninja_toolchain_writer.cc",
"ninja_toolchain_writer.h",
"ninja_writer.cc",
"ninja_writer.h",
"operators.cc",
"operators.h",
"output_file.h",
"parse_tree.cc",
"parse_tree.h",
"parser.cc",
"parser.h",
"path_output.cc",
"path_output.h",
"pattern.cc",
"pattern.h",
"scheduler.cc",
"scheduler.h",
"scope.cc",
"scope.h",
"scope_per_file_provider.cc",
"scope_per_file_provider.h",
"settings.cc",
"settings.h",
"setup.cc",
"setup.h",
"source_dir.cc",
"source_dir.h",
"source_file.cc",
"source_file.h",
"standard_out.cc",
"standard_out.h",
"string_utils.cc",
"string_utils.h",
"target.cc",
"target.h",
"target_generator.cc",
"target_generator.h",
"target_manager.cc",
"target_manager.h",
"token.cc",
"token.h",
"tokenizer.cc",
"tokenizer.h",
"toolchain.cc",
"toolchain.h",
"toolchain_manager.cc",
"toolchain_manager.h",
"value.cc",
"value.h",
"value_extractors.cc",
"value_extractors.h",
]
deps = [
"//base",
"//base/third_party/dynamic_annotations",
]
}

executable("gn") {
sources = [
"gn_main.cc",
]
deps = [
":gn_lib",
]
}

test("gn_unittests") {
sources = [
"escape_unittest.cc",
"file_template_unittest.cc",
"filesystem_utils_unittest.cc",
"input_conversion_unittest.cc",
"label_unittest.cc",
"ninja_helper_unittest.cc",
"parser_unittest.cc",
"path_output_unittest.cc",
"pattern_unittest.cc",
"source_dir_unittest.cc",
"string_utils_unittest.cc",
"target_generator_unittest.cc",
"target_manager_unittest.cc",
"tokenizer_unittest.cc",
]
deps = [
":gn_lib",
"//base:run_all_unittests",
"//base:test_support_base",
"//testing:gtest",
]
}

executable("generate_test_gn_data") {
sources = [ "generate_test_gn_data.cc" ]
deps = [ "//base" ]
}
1 change: 1 addition & 0 deletions tools/gn/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
brettw@chromium.org
7 changes: 7 additions & 0 deletions tools/gn/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GN "Generate Ninja"

This tool is an experimental metabuildsystem. It is not currently in a state
where it is ready for public consumption.

It is not currently used in the build and there are currently no plans to
replace GYP.
44 changes: 44 additions & 0 deletions tools/gn/build_settings.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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 "tools/gn/build_settings.h"

#include "tools/gn/filesystem_utils.h"

BuildSettings::BuildSettings()
: item_tree_(),
target_manager_(this),
toolchain_manager_(this) {
}

BuildSettings::~BuildSettings() {
}

void BuildSettings::SetSecondarySourcePath(const SourceDir& d) {
secondary_source_path_ = GetFullPath(d);
}

void BuildSettings::SetBuildDir(const SourceDir& d) {
build_dir_ = d;
build_to_source_dir_string_ = InvertDir(d);
}

base::FilePath BuildSettings::GetFullPath(const SourceFile& file) const {
return file.Resolve(root_path_);
}

base::FilePath BuildSettings::GetFullPath(const SourceDir& dir) const {
return dir.Resolve(root_path_);
}

base::FilePath BuildSettings::GetFullPathSecondary(
const SourceFile& file) const {
return file.Resolve(secondary_source_path_);
}

base::FilePath BuildSettings::GetFullPathSecondary(
const SourceDir& dir) const {
return dir.Resolve(secondary_source_path_);
}

110 changes: 110 additions & 0 deletions tools/gn/build_settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// 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.

#ifndef TOOLS_GN_BUILD_SETTINGS_H_
#define TOOLS_GN_BUILD_SETTINGS_H_

#include "base/basictypes.h"
#include "base/callback.h"
#include "base/files/file_path.h"
#include "tools/gn/item_tree.h"
#include "tools/gn/scope.h"
#include "tools/gn/source_dir.h"
#include "tools/gn/source_file.h"
#include "tools/gn/target_manager.h"
#include "tools/gn/toolchain_manager.h"

// Settings for one build, which is one toplevel output directory. There
// may be multiple Settings objects that refer to this, one for each toolchain.
class BuildSettings {
public:
typedef base::Callback<void(const Target*)> TargetResolvedCallback;

BuildSettings();
~BuildSettings();

// Absolute path of the source root on the local system. Everything is
// relative to this.
const base::FilePath& root_path() const { return root_path_; }
void set_root_path(const base::FilePath& r) { root_path_ = r; }

// When nonempty, specifies a parallel directory higherarchy in which to
// search for buildfiles if they're not found in the root higherarchy. This
// allows us to keep buildfiles in a separate tree during development.
const base::FilePath& secondary_source_path() const {
return secondary_source_path_;
}
void SetSecondarySourcePath(const SourceDir& d);

// 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; }

const SourceFile& build_config_file() const { return build_config_file_; }
void set_build_config_file(const SourceFile& f) { build_config_file_ = f; }

// 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.
const SourceDir& build_dir() const { return build_dir_; }
void SetBuildDir(const SourceDir& dir);

// The inverse of relative_build_dir, ending with a separator.
// Example: relative_build_dir_ = "out/Debug/" this will be "../../"
const std::string& build_to_source_dir_string() const {
return build_to_source_dir_string_;
}

// These accessors do not return const objects since the resulting objects
// are threadsafe. In this setting, we use constness primarily to ensure
// that the Settings object is used in a threadsafe manner. Although this
// violates the concept of logical constness, that's less important in our
// application, and actually implementing this in a way that preserves
// logical constness is cumbersome.
ItemTree& item_tree() const { return item_tree_; }
TargetManager& target_manager() const { return target_manager_; }
ToolchainManager& toolchain_manager() const { return toolchain_manager_; }

// Returns the full absolute OS path cooresponding to the given file in the
// root source tree.
base::FilePath GetFullPath(const SourceFile& file) const;
base::FilePath GetFullPath(const SourceDir& dir) const;

// Returns the absolute OS path inside the secondary source path. Will return
// an empty FilePath if the secondary source path is empty. When loading a
// buildfile, the GetFullPath should always be consulted first.
base::FilePath GetFullPathSecondary(const SourceFile& file) const;
base::FilePath GetFullPathSecondary(const SourceDir& dir) const;

// This is the callback to execute when a target is marked resolved. If we
// don't need to do anything, this will be null. When a target is resolved,
// this callback should be posted to the scheduler pool so the work is
// distributed properly.
const TargetResolvedCallback& target_resolved_callback() const {
return target_resolved_callback_;
}
void set_target_resolved_callback(const TargetResolvedCallback& cb) {
target_resolved_callback_ = cb;
}

private:
base::FilePath root_path_;
base::FilePath secondary_source_path_;
base::FilePath python_path_;

SourceFile build_config_file_;
SourceDir build_dir_;
std::string build_to_source_dir_string_;

TargetResolvedCallback target_resolved_callback_;

// See getters above.
mutable ItemTree item_tree_;
mutable TargetManager target_manager_;
mutable ToolchainManager toolchain_manager_;

DISALLOW_COPY_AND_ASSIGN(BuildSettings);
};

#endif // TOOLS_GN_BUILD_SETTINGS_H_
Loading

0 comments on commit c88bd8f

Please sign in to comment.