#ifndef TOOLS_GN_BUILD_SETTINGS_H_
#define TOOLS_GN_BUILD_SETTINGS_H_
#include <functional>
#include <map>
#include <memory>
#include <set>
#include <utility>
#include "base/files/file_path.h"
#include "gn/args.h"
#include "gn/label.h"
#include "gn/label_pattern.h"
#include "gn/scope.h"
#include "gn/source_dir.h"
#include "gn/source_file.h"
#include "gn/version.h"
class Item;
class OhosComponent;
class OhosComponents;
class BuildSettings {
public:
using ItemDefinedCallback = std::function<void(std::unique_ptr<Item>)>;
using PrintCallback = std::function<void(const std::string&)>;
BuildSettings();
BuildSettings(const BuildSettings& other);
const Label& root_target_label() const { return root_target_label_; }
void SetRootTargetLabel(const Label& r);
const std::vector<LabelPattern>& root_patterns() const {
return root_patterns_;
}
void SetRootPatterns(std::vector<LabelPattern>&& root_patterns);
const base::FilePath& root_path() const { return root_path_; }
const base::FilePath& dotfile_name() const { return dotfile_name_; }
const std::string& root_path_utf8() const { return root_path_utf8_; }
void SetRootPath(const base::FilePath& r);
void set_dotfile_name(const base::FilePath& d) { dotfile_name_ = d; }
const base::FilePath& secondary_source_path() const {
return secondary_source_path_;
}
void SetSecondarySourcePath(const SourceDir& d);
base::FilePath python_path() const { return python_path_; }
void SetPythonPath(base::FilePath p);
bool python_path_is_relative_to_build_dir() const {
return python_path_is_relative_to_build_dir_;
}
void set_python_path(const base::FilePath& p) { python_path_ = p; }
void SetOhosComponentsInfo(OhosComponents *ohos_components);
bool GetExternalDepsLabel(const Value& external_dep, std::string& label,
const Label& current_toolchain, int &whole_status, Err* err, bool strip_toolchain = false) const;
bool GetPrivateDepsLabel(const Value &dep, std::string &label,
const Label& current_toolchain, int &whole_status, Err *err) const;
bool is_ohos_components_enabled() const;
const OhosComponent *GetOhosComponent(const std::string& label) const;
const Version& ninja_required_version() const {
return ninja_required_version_;
}
void set_ninja_required_version(Version v) { ninja_required_version_ = v; }
bool no_stamp_files() const { return no_stamp_files_; }
void set_no_stamp_files(bool no_stamp_files) {
no_stamp_files_ = no_stamp_files;
}
int glob_max_results() const { return glob_max_results_; }
void set_glob_max_results(int max_results) {
glob_max_results_ = max_results;
}
const SourceFile& build_config_file() const { return build_config_file_; }
void set_build_config_file(const SourceFile& f) { build_config_file_ = f; }
const SourceFile& arg_file_template_path() const {
return arg_file_template_path_;
}
void set_arg_file_template_path(const SourceFile& f) {
arg_file_template_path_ = f;
}
const SourceDir& build_dir() const { return build_dir_; }
void SetBuildDir(const SourceDir& dir);
Args& build_args() { return build_args_; }
const Args& build_args() const { return build_args_; }
base::FilePath GetFullPath(const SourceFile& file) const;
base::FilePath GetFullPath(const SourceDir& dir) const;
base::FilePath GetFullPath(const std::string& path, bool as_file) const;
base::FilePath GetFullPathSecondary(const SourceFile& file) const;
base::FilePath GetFullPathSecondary(const SourceDir& dir) const;
base::FilePath GetFullPathSecondary(const std::string& path,
bool as_file) const;
void ItemDefined(std::unique_ptr<Item> item) const;
void set_item_defined_callback(ItemDefinedCallback cb) {
item_defined_callback_ = cb;
}
const PrintCallback& print_callback() const { return print_callback_; }
void set_print_callback(const PrintCallback cb) { print_callback_ = cb; }
const PrintCallback swap_print_callback(const PrintCallback cb);
const SourceFileSet* exec_script_allowlist() const {
return exec_script_allowlist_.get();
}
void set_exec_script_allowlist(std::unique_ptr<SourceFileSet> list) {
exec_script_allowlist_ = std::move(list);
}
const OhosComponent *GetOhosComponentByName(const std::string &component_name) const;
bool isOhosIndepCompilerEnable() const;
void set_ohos_components_support(bool enabled) { ohos_components_support_ = enabled; }
bool ResolveTargetLabelWithOhosComponent(const Value& arg,
const SourceDir& current_dir,
const Label& toolchain_label,
Label* label,
Err* err) const;
private:
Label root_target_label_;
std::vector<LabelPattern> root_patterns_;
base::FilePath dotfile_name_;
base::FilePath root_path_;
std::string root_path_utf8_;
base::FilePath secondary_source_path_;
base::FilePath python_path_;
bool python_path_is_relative_to_build_dir_ = false;
OhosComponents *ohos_components_ = nullptr;
Version ninja_required_version_{1, 7, 2};
bool no_stamp_files_ = false;
int glob_max_results_ = 5000;
SourceFile build_config_file_;
SourceFile arg_file_template_path_;
SourceDir build_dir_;
Args build_args_;
ItemDefinedCallback item_defined_callback_;
PrintCallback print_callback_;
std::unique_ptr<SourceFileSet> exec_script_allowlist_;
BuildSettings& operator=(const BuildSettings&) = delete;
bool ohos_components_support_ = false;
};
#endif