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_
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"
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.
26 typedef base::Callback
<void(scoped_ptr
<Item
>)> ItemDefinedCallback
;
27 typedef base::Callback
<void(const std::string
&)> PrintCallback
;
30 BuildSettings(const BuildSettings
& other
);
33 // Absolute path of the source root on the local system. Everything is
34 // relative to this. Does not end in a [back]slash.
35 const base::FilePath
& root_path() const { return root_path_
; }
36 const std::string
& root_path_utf8() const { return root_path_utf8_
; }
37 void SetRootPath(const base::FilePath
& r
);
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.
42 const base::FilePath
& secondary_source_path() const {
43 return secondary_source_path_
;
45 void SetSecondarySourcePath(const SourceDir
& d
);
47 // Path of the python executable to run scripts with.
48 base::FilePath
python_path() const { return python_path_
; }
49 void set_python_path(const base::FilePath
& p
) { python_path_
= p
; }
51 const SourceFile
& build_config_file() const { return build_config_file_
; }
52 void set_build_config_file(const SourceFile
& f
) { build_config_file_
= f
; }
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.
57 const SourceDir
& build_dir() const { return build_dir_
; }
58 void SetBuildDir(const SourceDir
& dir
);
60 // The build args are normally specified on the command-line.
61 Args
& build_args() { return build_args_
; }
62 const Args
& build_args() const { return build_args_
; }
64 // Returns the full absolute OS path cooresponding to the given file in the
66 base::FilePath
GetFullPath(const SourceFile
& file
) const;
67 base::FilePath
GetFullPath(const SourceDir
& dir
) const;
69 // Returns the absolute OS path inside the secondary source path. Will return
70 // an empty FilePath if the secondary source path is empty. When loading a
71 // buildfile, the GetFullPath should always be consulted first.
72 base::FilePath
GetFullPathSecondary(const SourceFile
& file
) const;
73 base::FilePath
GetFullPathSecondary(const SourceDir
& dir
) const;
75 // Called when an item is defined from a background thread.
76 void ItemDefined(scoped_ptr
<Item
> item
) const;
77 void set_item_defined_callback(ItemDefinedCallback cb
) {
78 item_defined_callback_
= cb
;
81 // Defines a callback that will be used to override the behavior of the
82 // print function. This is used in tests to collect print output. If the
83 // callback is is_null() (the default) the output will be printed to the
85 const PrintCallback
& print_callback() const { return print_callback_
; }
86 void set_print_callback(const PrintCallback
& cb
) { print_callback_
= cb
; }
89 base::FilePath root_path_
;
90 std::string root_path_utf8_
;
91 base::FilePath secondary_source_path_
;
92 base::FilePath python_path_
;
94 SourceFile build_config_file_
;
98 ItemDefinedCallback item_defined_callback_
;
99 PrintCallback print_callback_
;
101 BuildSettings
& operator=(const BuildSettings
& other
); // Disallow.
104 #endif // TOOLS_GN_BUILD_SETTINGS_H_