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 #include "gn/build_settings.h"
6
7 #include <utility>
8
9 #include "base/files/file_util.h"
10 #include "gn/filesystem_utils.h"
11 #include "gn/ohos_components.h"
12
13 BuildSettings::BuildSettings() = default;
14
BuildSettings(const BuildSettings & other)15 BuildSettings::BuildSettings(const BuildSettings& other)
16 : dotfile_name_(other.dotfile_name_),
17 root_path_(other.root_path_),
18 root_path_utf8_(other.root_path_utf8_),
19 secondary_source_path_(other.secondary_source_path_),
20 python_path_(other.python_path_),
21 ninja_required_version_(other.ninja_required_version_),
22 build_config_file_(other.build_config_file_),
23 arg_file_template_path_(other.arg_file_template_path_),
24 build_dir_(other.build_dir_),
25 build_args_(other.build_args_) {}
26
SetRootTargetLabel(const Label & r)27 void BuildSettings::SetRootTargetLabel(const Label& r) {
28 root_target_label_ = r;
29 }
30
SetRootPatterns(std::vector<LabelPattern> && patterns)31 void BuildSettings::SetRootPatterns(std::vector<LabelPattern>&& patterns) {
32 root_patterns_ = std::move(patterns);
33 }
34
SetRootPath(const base::FilePath & r)35 void BuildSettings::SetRootPath(const base::FilePath& r) {
36 DCHECK(r.value()[r.value().size() - 1] != base::FilePath::kSeparators[0]);
37 root_path_ = r.NormalizePathSeparatorsTo('/');
38 root_path_utf8_ = FilePathToUTF8(root_path_);
39 }
40
SetSecondarySourcePath(const SourceDir & d)41 void BuildSettings::SetSecondarySourcePath(const SourceDir& d) {
42 secondary_source_path_ = GetFullPath(d).NormalizePathSeparatorsTo('/');
43 }
44
SetBuildDir(const SourceDir & d)45 void BuildSettings::SetBuildDir(const SourceDir& d) {
46 build_dir_ = d;
47 }
48
GetFullPath(const SourceFile & file) const49 base::FilePath BuildSettings::GetFullPath(const SourceFile& file) const {
50 return file.Resolve(root_path_).NormalizePathSeparatorsTo('/');
51 }
52
GetFullPath(const SourceDir & dir) const53 base::FilePath BuildSettings::GetFullPath(const SourceDir& dir) const {
54 return dir.Resolve(root_path_).NormalizePathSeparatorsTo('/');
55 }
56
GetFullPath(const std::string & path,bool as_file) const57 base::FilePath BuildSettings::GetFullPath(const std::string& path,
58 bool as_file) const {
59 return ResolvePath(path, as_file, root_path_).NormalizePathSeparatorsTo('/');
60 }
61
GetFullPathSecondary(const SourceFile & file) const62 base::FilePath BuildSettings::GetFullPathSecondary(
63 const SourceFile& file) const {
64 return file.Resolve(secondary_source_path_).NormalizePathSeparatorsTo('/');
65 }
66
GetFullPathSecondary(const SourceDir & dir) const67 base::FilePath BuildSettings::GetFullPathSecondary(const SourceDir& dir) const {
68 return dir.Resolve(secondary_source_path_).NormalizePathSeparatorsTo('/');
69 }
70
GetFullPathSecondary(const std::string & path,bool as_file) const71 base::FilePath BuildSettings::GetFullPathSecondary(const std::string& path,
72 bool as_file) const {
73 return ResolvePath(path, as_file, secondary_source_path_)
74 .NormalizePathSeparatorsTo('/');
75 }
76
ItemDefined(std::unique_ptr<Item> item) const77 void BuildSettings::ItemDefined(std::unique_ptr<Item> item) const {
78 DCHECK(item);
79 if (item_defined_callback_)
80 item_defined_callback_(std::move(item));
81 }
82
83
SetOhosComponentsInfo(OhosComponents * ohos_components)84 void BuildSettings::SetOhosComponentsInfo(OhosComponents *ohos_components)
85 {
86 ohos_components_ = ohos_components;
87 }
88
GetExternalDepsLabel(const Value & external_dep,std::string & label,const Label & current_toolchain,int & whole_status,Err * err) const89 bool BuildSettings::GetExternalDepsLabel(const Value& external_dep, std::string& label,
90 const Label& current_toolchain, int &whole_status, Err* err) const
91 {
92 if (ohos_components_ == nullptr) {
93 *err = Err(external_dep, "You are using OpenHarmony external_deps, but no components information loaded.");
94 return false;
95 }
96 return ohos_components_->GetExternalDepsLabel(external_dep, label, current_toolchain, whole_status, err);
97 }
98
GetPrivateDepsLabel(const Value & dep,std::string & label,const Label & current_toolchain,int & whole_status,Err * err) const99 bool BuildSettings::GetPrivateDepsLabel(const Value& dep, std::string& label,
100 const Label& current_toolchain, int &whole_status, Err* err) const
101 {
102 if (ohos_components_ == nullptr) {
103 *err = Err(dep, "Components information not loaded.");
104 return false;
105 }
106 return ohos_components_->GetPrivateDepsLabel(dep, label, current_toolchain, whole_status, err);
107 }
108
is_ohos_components_enabled() const109 bool BuildSettings::is_ohos_components_enabled() const
110 {
111 if (ohos_components_ != nullptr) {
112 return true;
113 }
114 return false;
115 }
116
GetOhosComponent(const std::string & label) const117 const OhosComponent *BuildSettings::GetOhosComponent(const std::string& label) const
118 {
119 if (ohos_components_ == nullptr) {
120 return nullptr;
121 }
122 return ohos_components_->GetComponentByLabel(label);
123 }
124
GetOhosComponentByName(const std::string & component_name) const125 const OhosComponent *BuildSettings::GetOhosComponentByName(const std::string& component_name) const
126 {
127 if (ohos_components_ == nullptr) {
128 return nullptr;
129 }
130 return ohos_components_->GetComponentByName(component_name);
131 }
132
isOhosIndepCompilerEnable() const133 bool BuildSettings::isOhosIndepCompilerEnable() const {
134 return ohos_components_ && ohos_components_->isOhosIndepCompilerEnable();
135 }
136