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 typedef base::Callback<void(const std::string&)> PrintCallback; 28 29 BuildSettings(); 30 BuildSettings(const BuildSettings& other); 31 ~BuildSettings(); 32 33 // Absolute path of the source root on the local system. Everything is 34 // relative to this. Does not end in a [back]slash. root_path()35 const base::FilePath& root_path() const { return root_path_; } root_path_utf8()36 const std::string& root_path_utf8() const { return root_path_utf8_; } 37 void SetRootPath(const base::FilePath& r); 38 39 // When nonempty, specifies a parallel directory higherarchy in which to 40 // search for buildfiles if they're not found in the root higherarchy. This 41 // allows us to keep buildfiles in a separate tree during development. secondary_source_path()42 const base::FilePath& secondary_source_path() const { 43 return secondary_source_path_; 44 } 45 void SetSecondarySourcePath(const SourceDir& d); 46 47 // Path of the python executable to run scripts with. python_path()48 base::FilePath python_path() const { return python_path_; } set_python_path(const base::FilePath & p)49 void set_python_path(const base::FilePath& p) { python_path_ = p; } 50 build_config_file()51 const SourceFile& build_config_file() const { return build_config_file_; } set_build_config_file(const SourceFile & f)52 void set_build_config_file(const SourceFile& f) { build_config_file_ = f; } 53 54 // The build directory is the root of all output files. The default toolchain 55 // files go into here, and non-default toolchains will have separate 56 // toolchain-specific root directories inside this. build_dir()57 const SourceDir& build_dir() const { return build_dir_; } 58 void SetBuildDir(const SourceDir& dir); 59 60 // The inverse of relative_build_dir, ending with a separator. 61 // Example: relative_build_dir_ = "out/Debug/" this will be "../../" build_to_source_dir_string()62 const std::string& build_to_source_dir_string() const { 63 return build_to_source_dir_string_; 64 } 65 66 // The build args are normally specified on the command-line. build_args()67 Args& build_args() { return build_args_; } build_args()68 const Args& build_args() const { return build_args_; } 69 70 // Returns the full absolute OS path cooresponding to the given file in the 71 // root source tree. 72 base::FilePath GetFullPath(const SourceFile& file) const; 73 base::FilePath GetFullPath(const SourceDir& dir) const; 74 75 // Returns the absolute OS path inside the secondary source path. Will return 76 // an empty FilePath if the secondary source path is empty. When loading a 77 // buildfile, the GetFullPath should always be consulted first. 78 base::FilePath GetFullPathSecondary(const SourceFile& file) const; 79 base::FilePath GetFullPathSecondary(const SourceDir& dir) const; 80 81 // Called when an item is defined from a background thread. 82 void ItemDefined(scoped_ptr<Item> item) const; set_item_defined_callback(ItemDefinedCallback cb)83 void set_item_defined_callback(ItemDefinedCallback cb) { 84 item_defined_callback_ = cb; 85 } 86 87 // Defines a callback that will be used to override the behavior of the 88 // print function. This is used in tests to collect print output. If the 89 // callback is is_null() (the default) the output will be printed to the 90 // console. print_callback()91 const PrintCallback& print_callback() const { return print_callback_; } set_print_callback(const PrintCallback & cb)92 void set_print_callback(const PrintCallback& cb) { print_callback_ = cb; } 93 94 private: 95 base::FilePath root_path_; 96 std::string root_path_utf8_; 97 base::FilePath secondary_source_path_; 98 base::FilePath python_path_; 99 100 SourceFile build_config_file_; 101 SourceDir build_dir_; 102 std::string build_to_source_dir_string_; 103 Args build_args_; 104 105 ItemDefinedCallback item_defined_callback_; 106 PrintCallback print_callback_; 107 108 BuildSettings& operator=(const BuildSettings& other); // Disallow. 109 }; 110 111 #endif // TOOLS_GN_BUILD_SETTINGS_H_ 112