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.
5 #ifndef TOOLS_GN_BUILD_SETTINGS_H_
6 #define TOOLS_GN_BUILD_SETTINGS_H_
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "tools/gn/args.h"
16 #include "tools/gn/scope.h"
17 #include "tools/gn/source_dir.h"
18 #include "tools/gn/source_file.h"
23 // Settings for one build, which is one toplevel output directory. There
24 // may be multiple Settings objects that refer to this, one for each toolchain.
27 typedef base::Callback
<void(scoped_ptr
<Item
>)> ItemDefinedCallback
;
28 typedef base::Callback
<void(const std::string
&)> PrintCallback
;
31 BuildSettings(const BuildSettings
& other
);
34 // Absolute path of the source root on the local system. Everything is
35 // relative to this. Does not end in a [back]slash.
36 const base::FilePath
& root_path() const { return root_path_
; }
37 const std::string
& root_path_utf8() const { return root_path_utf8_
; }
38 void SetRootPath(const base::FilePath
& r
);
40 // When nonempty, specifies a parallel directory higherarchy in which to
41 // search for buildfiles if they're not found in the root higherarchy. This
42 // allows us to keep buildfiles in a separate tree during development.
43 const base::FilePath
& secondary_source_path() const {
44 return secondary_source_path_
;
46 void SetSecondarySourcePath(const SourceDir
& d
);
48 // Path of the python executable to run scripts with.
49 base::FilePath
python_path() const { return python_path_
; }
50 void set_python_path(const base::FilePath
& p
) { python_path_
= p
; }
52 const SourceFile
& build_config_file() const { return build_config_file_
; }
53 void set_build_config_file(const SourceFile
& f
) { build_config_file_
= f
; }
55 // The build directory is the root of all output files. The default toolchain
56 // files go into here, and non-default toolchains will have separate
57 // toolchain-specific root directories inside this.
58 const SourceDir
& build_dir() const { return build_dir_
; }
59 void SetBuildDir(const SourceDir
& dir
);
61 // The build args are normally specified on the command-line.
62 Args
& build_args() { return build_args_
; }
63 const Args
& build_args() const { return build_args_
; }
65 // Returns the full absolute OS path cooresponding to the given file in the
67 base::FilePath
GetFullPath(const SourceFile
& file
) const;
68 base::FilePath
GetFullPath(const SourceDir
& dir
) const;
70 // Returns the absolute OS path inside the secondary source path. Will return
71 // an empty FilePath if the secondary source path is empty. When loading a
72 // buildfile, the GetFullPath should always be consulted first.
73 base::FilePath
GetFullPathSecondary(const SourceFile
& file
) const;
74 base::FilePath
GetFullPathSecondary(const SourceDir
& dir
) const;
76 // Called when an item is defined from a background thread.
77 void ItemDefined(scoped_ptr
<Item
> item
) const;
78 void set_item_defined_callback(ItemDefinedCallback cb
) {
79 item_defined_callback_
= cb
;
82 // Defines a callback that will be used to override the behavior of the
83 // print function. This is used in tests to collect print output. If the
84 // callback is is_null() (the default) the output will be printed to the
86 const PrintCallback
& print_callback() const { return print_callback_
; }
87 void set_print_callback(const PrintCallback
& cb
) { print_callback_
= cb
; }
89 // A list of files that can call exec_script(). If the returned pointer is
90 // null, exec_script may be called from anywhere.
91 const std::set
<SourceFile
>* exec_script_whitelist() const {
92 return exec_script_whitelist_
.get();
94 void set_exec_script_whitelist(scoped_ptr
<std::set
<SourceFile
>> list
) {
95 exec_script_whitelist_
= list
.Pass();
99 base::FilePath root_path_
;
100 std::string root_path_utf8_
;
101 base::FilePath secondary_source_path_
;
102 base::FilePath python_path_
;
104 SourceFile build_config_file_
;
105 SourceDir build_dir_
;
108 ItemDefinedCallback item_defined_callback_
;
109 PrintCallback print_callback_
;
111 scoped_ptr
<std::set
<SourceFile
>> exec_script_whitelist_
;
113 BuildSettings
& operator=(const BuildSettings
& other
); // Disallow.
116 #endif // TOOLS_GN_BUILD_SETTINGS_H_