• 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 "tools/gn/scope_per_file_provider.h"
6 
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"
12 
ScopePerFileProvider(Scope * scope)13 ScopePerFileProvider::ScopePerFileProvider(Scope* scope)
14     : ProgrammaticProvider(scope) {
15 }
16 
~ScopePerFileProvider()17 ScopePerFileProvider::~ScopePerFileProvider() {
18 }
19 
GetProgrammaticValue(const base::StringPiece & ident)20 const Value* ScopePerFileProvider::GetProgrammaticValue(
21     const base::StringPiece& ident) {
22   if (ident == variables::kCurrentToolchain)
23     return GetCurrentToolchain();
24   if (ident == variables::kDefaultToolchain)
25     return GetDefaultToolchain();
26   if (ident == variables::kPythonPath)
27     return GetPythonPath();
28 
29   if (ident == variables::kRootBuildDir)
30     return GetRootBuildDir();
31   if (ident == variables::kRootGenDir)
32     return GetRootGenDir();
33   if (ident == variables::kRootOutDir)
34     return GetRootOutDir();
35   if (ident == variables::kTargetGenDir)
36     return GetTargetGenDir();
37   if (ident == variables::kTargetOutDir)
38     return GetTargetOutDir();
39   return NULL;
40 }
41 
GetCurrentToolchain()42 const Value* ScopePerFileProvider::GetCurrentToolchain() {
43   if (!current_toolchain_) {
44     current_toolchain_.reset(new Value(NULL,
45         scope_->settings()->toolchain_label().GetUserVisibleName(false)));
46   }
47   return current_toolchain_.get();
48 }
49 
GetDefaultToolchain()50 const Value* ScopePerFileProvider::GetDefaultToolchain() {
51   if (!default_toolchain_) {
52     default_toolchain_.reset(new Value(NULL,
53         scope_->settings()->default_toolchain_label().GetUserVisibleName(
54             false)));
55   }
56   return default_toolchain_.get();
57 }
58 
GetPythonPath()59 const Value* ScopePerFileProvider::GetPythonPath() {
60   if (!python_path_) {
61     python_path_.reset(new Value(NULL,
62         FilePathToUTF8(scope_->settings()->build_settings()->python_path())));
63   }
64   return python_path_.get();
65 }
66 
GetRootBuildDir()67 const Value* ScopePerFileProvider::GetRootBuildDir() {
68   if (!root_build_dir_) {
69     root_build_dir_.reset(new Value(NULL, DirectoryWithNoLastSlash(
70         scope_->settings()->build_settings()->build_dir())));
71   }
72   return root_build_dir_.get();
73 }
74 
GetRootGenDir()75 const Value* ScopePerFileProvider::GetRootGenDir() {
76   if (!root_gen_dir_) {
77     root_gen_dir_.reset(new Value(NULL,
78         DirectoryWithNoLastSlash(GetToolchainGenDir(scope_->settings()))));
79   }
80   return root_gen_dir_.get();
81 }
82 
GetRootOutDir()83 const Value* ScopePerFileProvider::GetRootOutDir() {
84   if (!root_out_dir_) {
85     root_out_dir_.reset(new Value(NULL,
86         DirectoryWithNoLastSlash(GetToolchainOutputDir(scope_->settings()))));
87   }
88   return root_out_dir_.get();
89 }
90 
GetTargetGenDir()91 const Value* ScopePerFileProvider::GetTargetGenDir() {
92   if (!target_gen_dir_) {
93     target_gen_dir_.reset(new Value(NULL,
94         DirectoryWithNoLastSlash(GetCurrentGenDir(scope_))));
95   }
96   return target_gen_dir_.get();
97 }
98 
GetTargetOutDir()99 const Value* ScopePerFileProvider::GetTargetOutDir() {
100   if (!target_out_dir_) {
101     target_out_dir_.reset(new Value(NULL,
102         DirectoryWithNoLastSlash(GetCurrentOutputDir(scope_))));
103   }
104   return target_out_dir_.get();
105 }
106