1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef TOOLS_GN_BUILD_SETTINGS_H_ 6 #define TOOLS_GN_BUILD_SETTINGS_H_ 7 8 #include <map> 9 10 #include "base/basictypes.h" 11 #include "base/callback.h" 12 #include "base/files/file_path.h" 13 #include "base/memory/scoped_ptr.h" 14 #include "tools/gn/args.h" 15 #include "tools/gn/scope.h" 16 #include "tools/gn/source_dir.h" 17 #include "tools/gn/source_file.h" 18 19 class Item; 20 class OutputFile; 21 22 // Settings for one build, which is one toplevel output directory. There 23 // may be multiple Settings objects that refer to this, one for each toolchain. 24 class BuildSettings { 25 public: 26 typedef base::Callback<void(scoped_ptr<Item>)> ItemDefinedCallback; 27 28 BuildSettings(); 29 BuildSettings(const BuildSettings& other); 30 ~BuildSettings(); 31 32 // Absolute path of the source root on the local system. Everything is 33 // relative to this. Does not end in a [back]slash. 34 const base::FilePath& root_path() const { return root_path_; } 35 const std::string& root_path_utf8() const { return root_path_utf8_; } 36 void SetRootPath(const base::FilePath& r); 37 38 // When nonempty, specifies a parallel directory higherarchy in which to 39 // search for buildfiles if they're not found in the root higherarchy. This 40 // allows us to keep buildfiles in a separate tree during development. 41 const base::FilePath& secondary_source_path() const { 42 return secondary_source_path_; 43 } 44 void SetSecondarySourcePath(const SourceDir& d); 45 46 // Path of the python executable to run scripts with. 47 base::FilePath python_path() const { return python_path_; } 48 void set_python_path(const base::FilePath& p) { python_path_ = p; } 49 50 const SourceFile& build_config_file() const { return build_config_file_; } 51 void set_build_config_file(const SourceFile& f) { build_config_file_ = f; } 52 53 // The build directory is the root of all output files. The default toolchain 54 // files go into here, and non-default toolchains will have separate 55 // toolchain-specific root directories inside this. 56 const SourceDir& build_dir() const { return build_dir_; } 57 void SetBuildDir(const SourceDir& dir); 58 59 // The inverse of relative_build_dir, ending with a separator. 60 // Example: relative_build_dir_ = "out/Debug/" this will be "../../" 61 const std::string& build_to_source_dir_string() const { 62 return build_to_source_dir_string_; 63 } 64 65 // The build args are normally specified on the command-line. 66 Args& build_args() { return build_args_; } 67 const Args& build_args() const { return build_args_; } 68 69 // Returns the full absolute OS path cooresponding to the given file in the 70 // root source tree. 71 base::FilePath GetFullPath(const SourceFile& file) const; 72 base::FilePath GetFullPath(const SourceDir& dir) const; 73 74 // Returns the absolute OS path inside the secondary source path. Will return 75 // an empty FilePath if the secondary source path is empty. When loading a 76 // buildfile, the GetFullPath should always be consulted first. 77 base::FilePath GetFullPathSecondary(const SourceFile& file) const; 78 base::FilePath GetFullPathSecondary(const SourceDir& dir) const; 79 80 // Called when an item is defined from a background thread. 81 void ItemDefined(scoped_ptr<Item> item) const; 82 void set_item_defined_callback(ItemDefinedCallback cb) { 83 item_defined_callback_ = cb; 84 } 85 86 private: 87 base::FilePath root_path_; 88 std::string root_path_utf8_; 89 base::FilePath secondary_source_path_; 90 base::FilePath python_path_; 91 92 SourceFile build_config_file_; 93 SourceDir build_dir_; 94 std::string build_to_source_dir_string_; 95 Args build_args_; 96 97 ItemDefinedCallback item_defined_callback_; 98 99 BuildSettings& operator=(const BuildSettings& other); // Disallow. 100 }; 101 102 #endif // TOOLS_GN_BUILD_SETTINGS_H_ 103