Add the ability to code generated prepopulated static nested structs
[chromium-blink-merge.git] / tools / gn / scope_per_file_provider.cc
blobd2dea11e6457e6eb89a7625b80cce1a2cb7c2441
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.
5 #include "tools/gn/scope_per_file_provider.h"
7 #include "tools/gn/filesystem_utils.h"
8 #include "tools/gn/settings.h"
9 #include "tools/gn/source_file.h"
10 #include "tools/gn/value.h"
11 #include "tools/gn/variables.h"
13 ScopePerFileProvider::ScopePerFileProvider(Scope* scope,
14 bool allow_target_vars)
15 : ProgrammaticProvider(scope),
16 allow_target_vars_(allow_target_vars) {
19 ScopePerFileProvider::~ScopePerFileProvider() {
22 const Value* ScopePerFileProvider::GetProgrammaticValue(
23 const base::StringPiece& ident) {
24 if (ident == variables::kCurrentToolchain)
25 return GetCurrentToolchain();
26 if (ident == variables::kDefaultToolchain)
27 return GetDefaultToolchain();
28 if (ident == variables::kPythonPath)
29 return GetPythonPath();
31 if (ident == variables::kRootBuildDir)
32 return GetRootBuildDir();
33 if (ident == variables::kRootGenDir)
34 return GetRootGenDir();
35 if (ident == variables::kRootOutDir)
36 return GetRootOutDir();
38 if (allow_target_vars_) {
39 if (ident == variables::kTargetGenDir)
40 return GetTargetGenDir();
41 if (ident == variables::kTargetOutDir)
42 return GetTargetOutDir();
44 return nullptr;
47 const Value* ScopePerFileProvider::GetCurrentToolchain() {
48 if (!current_toolchain_) {
49 current_toolchain_.reset(new Value(
50 nullptr,
51 scope_->settings()->toolchain_label().GetUserVisibleName(false)));
53 return current_toolchain_.get();
56 const Value* ScopePerFileProvider::GetDefaultToolchain() {
57 if (!default_toolchain_) {
58 default_toolchain_.reset(new Value(
59 nullptr,
60 scope_->settings()->default_toolchain_label().GetUserVisibleName(
61 false)));
63 return default_toolchain_.get();
66 const Value* ScopePerFileProvider::GetPythonPath() {
67 if (!python_path_) {
68 python_path_.reset(new Value(
69 nullptr,
70 FilePathToUTF8(scope_->settings()->build_settings()->python_path())));
72 return python_path_.get();
75 const Value* ScopePerFileProvider::GetRootBuildDir() {
76 if (!root_build_dir_) {
77 root_build_dir_.reset(new Value(
78 nullptr, DirectoryWithNoLastSlash(
79 scope_->settings()->build_settings()->build_dir())));
81 return root_build_dir_.get();
84 const Value* ScopePerFileProvider::GetRootGenDir() {
85 if (!root_gen_dir_) {
86 root_gen_dir_.reset(new Value(
87 nullptr,
88 DirectoryWithNoLastSlash(GetToolchainGenDir(scope_->settings()))));
90 return root_gen_dir_.get();
93 const Value* ScopePerFileProvider::GetRootOutDir() {
94 if (!root_out_dir_) {
95 root_out_dir_.reset(new Value(
96 nullptr,
97 DirectoryWithNoLastSlash(GetToolchainOutputDir(scope_->settings()))));
99 return root_out_dir_.get();
102 const Value* ScopePerFileProvider::GetTargetGenDir() {
103 if (!target_gen_dir_) {
104 target_gen_dir_.reset(
105 new Value(nullptr, DirectoryWithNoLastSlash(GetCurrentGenDir(scope_))));
107 return target_gen_dir_.get();
110 const Value* ScopePerFileProvider::GetTargetOutDir() {
111 if (!target_out_dir_) {
112 target_out_dir_.reset(new Value(
113 nullptr, DirectoryWithNoLastSlash(GetCurrentOutputDir(scope_))));
115 return target_out_dir_.get();