• 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 
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       ninja_required_version_(other.ninja_required_version_),
21       build_config_file_(other.build_config_file_),
22       arg_file_template_path_(other.arg_file_template_path_),
23       build_dir_(other.build_dir_),
24       build_args_(other.build_args_) {}
25 
SetRootTargetLabel(const Label & r)26 void BuildSettings::SetRootTargetLabel(const Label& r) {
27   root_target_label_ = r;
28 }
29 
SetRootPath(const base::FilePath & r)30 void BuildSettings::SetRootPath(const base::FilePath& r) {
31   DCHECK(r.value()[r.value().size() - 1] != base::FilePath::kSeparators[0]);
32   root_path_ = r.NormalizePathSeparatorsTo('/');
33   root_path_utf8_ = FilePathToUTF8(root_path_);
34 }
35 
SetSecondarySourcePath(const SourceDir & d)36 void BuildSettings::SetSecondarySourcePath(const SourceDir& d) {
37   secondary_source_path_ = GetFullPath(d).NormalizePathSeparatorsTo('/');
38 }
39 
SetBuildDir(const SourceDir & d)40 void BuildSettings::SetBuildDir(const SourceDir& d) {
41   build_dir_ = d;
42 }
43 
GetFullPath(const SourceFile & file) const44 base::FilePath BuildSettings::GetFullPath(const SourceFile& file) const {
45   return file.Resolve(root_path_).NormalizePathSeparatorsTo('/');
46 }
47 
GetFullPath(const SourceDir & dir) const48 base::FilePath BuildSettings::GetFullPath(const SourceDir& dir) const {
49   return dir.Resolve(root_path_).NormalizePathSeparatorsTo('/');
50 }
51 
GetFullPath(const std::string & path,bool as_file) const52 base::FilePath BuildSettings::GetFullPath(const std::string& path,
53                                           bool as_file) const {
54   return ResolvePath(path, as_file, root_path_).NormalizePathSeparatorsTo('/');
55 }
56 
GetFullPathSecondary(const SourceFile & file) const57 base::FilePath BuildSettings::GetFullPathSecondary(
58     const SourceFile& file) const {
59   return file.Resolve(secondary_source_path_).NormalizePathSeparatorsTo('/');
60 }
61 
GetFullPathSecondary(const SourceDir & dir) const62 base::FilePath BuildSettings::GetFullPathSecondary(const SourceDir& dir) const {
63   return dir.Resolve(secondary_source_path_).NormalizePathSeparatorsTo('/');
64 }
65 
GetFullPathSecondary(const std::string & path,bool as_file) const66 base::FilePath BuildSettings::GetFullPathSecondary(const std::string& path,
67                                                    bool as_file) const {
68   return ResolvePath(path, as_file, secondary_source_path_)
69       .NormalizePathSeparatorsTo('/');
70 }
71 
ItemDefined(std::unique_ptr<Item> item) const72 void BuildSettings::ItemDefined(std::unique_ptr<Item> item) const {
73   DCHECK(item);
74   if (item_defined_callback_)
75     item_defined_callback_(std::move(item));
76 }
77