• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
SetRootPath(const base::FilePath & r)31 void BuildSettings::SetRootPath(const base::FilePath& r) {
32   DCHECK(r.value()[r.value().size() - 1] != base::FilePath::kSeparators[0]);
33   root_path_ = r.NormalizePathSeparatorsTo('/');
34   root_path_utf8_ = FilePathToUTF8(root_path_);
35 }
36 
SetSecondarySourcePath(const SourceDir & d)37 void BuildSettings::SetSecondarySourcePath(const SourceDir& d) {
38   secondary_source_path_ = GetFullPath(d).NormalizePathSeparatorsTo('/');
39 }
40 
SetBuildDir(const SourceDir & d)41 void BuildSettings::SetBuildDir(const SourceDir& d) {
42   build_dir_ = d;
43 }
44 
GetFullPath(const SourceFile & file) const45 base::FilePath BuildSettings::GetFullPath(const SourceFile& file) const {
46   return file.Resolve(root_path_).NormalizePathSeparatorsTo('/');
47 }
48 
GetFullPath(const SourceDir & dir) const49 base::FilePath BuildSettings::GetFullPath(const SourceDir& dir) const {
50   return dir.Resolve(root_path_).NormalizePathSeparatorsTo('/');
51 }
52 
GetFullPath(const std::string & path,bool as_file) const53 base::FilePath BuildSettings::GetFullPath(const std::string& path,
54                                           bool as_file) const {
55   return ResolvePath(path, as_file, root_path_).NormalizePathSeparatorsTo('/');
56 }
57 
GetFullPathSecondary(const SourceFile & file) const58 base::FilePath BuildSettings::GetFullPathSecondary(
59     const SourceFile& file) const {
60   return file.Resolve(secondary_source_path_).NormalizePathSeparatorsTo('/');
61 }
62 
GetFullPathSecondary(const SourceDir & dir) const63 base::FilePath BuildSettings::GetFullPathSecondary(const SourceDir& dir) const {
64   return dir.Resolve(secondary_source_path_).NormalizePathSeparatorsTo('/');
65 }
66 
GetFullPathSecondary(const std::string & path,bool as_file) const67 base::FilePath BuildSettings::GetFullPathSecondary(const std::string& path,
68                                                    bool as_file) const {
69   return ResolvePath(path, as_file, secondary_source_path_)
70       .NormalizePathSeparatorsTo('/');
71 }
72 
ItemDefined(std::unique_ptr<Item> item) const73 void BuildSettings::ItemDefined(std::unique_ptr<Item> item) const {
74   DCHECK(item);
75   if (item_defined_callback_)
76     item_defined_callback_(std::move(item));
77 }
78 
SetOhosComponentsInfo(OhosComponents * ohos_components)79 void BuildSettings::SetOhosComponentsInfo(OhosComponents *ohos_components)
80 {
81   ohos_components_ = ohos_components;
82 }
83 
GetExternalDepsLabel(const Value & external_dep,std::string & label,Err * err) const84 bool BuildSettings::GetExternalDepsLabel(const Value& external_dep, std::string& label, Err* err) const
85 {
86   if (ohos_components_ == nullptr) {
87     *err = Err(external_dep, "You are using OpenHarmony external_deps, but no components information loaded.");
88     return false;
89   }
90   return ohos_components_->GetExternalDepsLabel(external_dep, label, err);
91 }
92 
is_ohos_components_enabled() const93 bool BuildSettings::is_ohos_components_enabled() const
94 {
95   if (ohos_components_ != nullptr) {
96     return true;
97   }
98   return false;
99 }
100 
GetOhosComponent(const std::string & label) const101 const OhosComponent *BuildSettings::GetOhosComponent(const std::string& label) const
102 {
103   if (ohos_components_ == nullptr) {
104     return nullptr;
105   }
106   return ohos_components_->GetComponentByLabel(label);
107 }
108