• 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 #ifndef TOOLS_GN_SCOPE_PER_FILE_PROVIDER_H_
6 #define TOOLS_GN_SCOPE_PER_FILE_PROVIDER_H_
7 
8 #include <memory>
9 #include <string_view>
10 
11 #include "gn/scope.h"
12 
13 // ProgrammaticProvider for a scope to provide it with per-file built-in
14 // variable support.
15 class ScopePerFileProvider : public Scope::ProgrammaticProvider {
16  public:
17   // allow_target_vars allows the target-related variables to get resolved.
18   // When allow_target_vars is unset, the target-related values will be
19   // undefined to GN script.
20   ScopePerFileProvider(Scope* scope, bool allow_target_vars);
21   ~ScopePerFileProvider() override;
22 
23   // ProgrammaticProvider implementation.
24   const Value* GetProgrammaticValue(std::string_view ident) override;
25 
26  private:
27   const Value* GetCurrentToolchain();
28   const Value* GetDefaultToolchain();
29   const Value* GetGnVersion();
30   const Value* GetPythonPath();
31   const Value* GetRootBuildDir();
32   const Value* GetRootGenDir();
33   const Value* GetRootOutDir();
34   const Value* GetTargetGenDir();
35   const Value* GetTargetOutDir();
36 
37   bool allow_target_vars_;
38 
39   // All values are lazily created.
40   std::unique_ptr<Value> current_toolchain_;
41   std::unique_ptr<Value> default_toolchain_;
42   std::unique_ptr<Value> gn_version_;
43   std::unique_ptr<Value> python_path_;
44   std::unique_ptr<Value> root_build_dir_;
45   std::unique_ptr<Value> root_gen_dir_;
46   std::unique_ptr<Value> root_out_dir_;
47   std::unique_ptr<Value> target_gen_dir_;
48   std::unique_ptr<Value> target_out_dir_;
49 
50   ScopePerFileProvider(const ScopePerFileProvider&) = delete;
51   ScopePerFileProvider& operator=(const ScopePerFileProvider&) = delete;
52 };
53 
54 #endif  // TOOLS_GN_SCOPE_PER_FILE_PROVIDER_H_
55