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
12 BuildSettings::BuildSettings() = default;
13
BuildSettings(const BuildSettings & other)14 BuildSettings::BuildSettings(const BuildSettings& other)
15 : dotfile_name_(other.dotfile_name_),
16 root_path_(other.root_path_),
17 root_path_utf8_(other.root_path_utf8_),
18 secondary_source_path_(other.secondary_source_path_),
19 python_path_(other.python_path_),
20 build_config_file_(other.build_config_file_),
21 arg_file_template_path_(other.arg_file_template_path_),
22 build_dir_(other.build_dir_),
23 build_args_(other.build_args_) {}
24
SetRootTargetLabel(const Label & r)25 void BuildSettings::SetRootTargetLabel(const Label& r) {
26 root_target_label_ = r;
27 }
28
SetRootPath(const base::FilePath & r)29 void BuildSettings::SetRootPath(const base::FilePath& r) {
30 DCHECK(r.value()[r.value().size() - 1] != base::FilePath::kSeparators[0]);
31 root_path_ = r.NormalizePathSeparatorsTo('/');
32 root_path_utf8_ = FilePathToUTF8(root_path_);
33 }
34
SetSecondarySourcePath(const SourceDir & d)35 void BuildSettings::SetSecondarySourcePath(const SourceDir& d) {
36 secondary_source_path_ = GetFullPath(d).NormalizePathSeparatorsTo('/');
37 }
38
SetBuildDir(const SourceDir & d)39 void BuildSettings::SetBuildDir(const SourceDir& d) {
40 build_dir_ = d;
41 }
42
GetFullPath(const SourceFile & file) const43 base::FilePath BuildSettings::GetFullPath(const SourceFile& file) const {
44 return file.Resolve(root_path_).NormalizePathSeparatorsTo('/');
45 }
46
GetFullPath(const SourceDir & dir) const47 base::FilePath BuildSettings::GetFullPath(const SourceDir& dir) const {
48 return dir.Resolve(root_path_).NormalizePathSeparatorsTo('/');
49 }
50
GetFullPath(const std::string & path,bool as_file) const51 base::FilePath BuildSettings::GetFullPath(const std::string& path,
52 bool as_file) const {
53 return ResolvePath(path, as_file, root_path_).NormalizePathSeparatorsTo('/');
54 }
55
GetFullPathSecondary(const SourceFile & file) const56 base::FilePath BuildSettings::GetFullPathSecondary(
57 const SourceFile& file) const {
58 return file.Resolve(secondary_source_path_).NormalizePathSeparatorsTo('/');
59 }
60
GetFullPathSecondary(const SourceDir & dir) const61 base::FilePath BuildSettings::GetFullPathSecondary(const SourceDir& dir) const {
62 return dir.Resolve(secondary_source_path_).NormalizePathSeparatorsTo('/');
63 }
64
GetFullPathSecondary(const std::string & path,bool as_file) const65 base::FilePath BuildSettings::GetFullPathSecondary(const std::string& path,
66 bool as_file) const {
67 return ResolvePath(path, as_file, secondary_source_path_)
68 .NormalizePathSeparatorsTo('/');
69 }
70
ItemDefined(std::unique_ptr<Item> item) const71 void BuildSettings::ItemDefined(std::unique_ptr<Item> item) const {
72 DCHECK(item);
73 if (item_defined_callback_)
74 item_defined_callback_(std::move(item));
75 }
76