| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef TOOLS_GN_SCOPE_PER_FILE_PROVIDER_H_ | 5 #ifndef TOOLS_GN_SCOPE_PER_FILE_PROVIDER_H_ |
| 6 #define TOOLS_GN_SCOPE_PER_FILE_PROVIDER_H_ | 6 #define TOOLS_GN_SCOPE_PER_FILE_PROVIDER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "tools/gn/scope.h" | 10 #include "tools/gn/scope.h" |
| 11 #include "tools/gn/source_file.h" | 11 #include "tools/gn/source_file.h" |
| 12 | 12 |
| 13 // ProgrammaticProvider for a scope to provide it with per-file built-in | 13 // ProgrammaticProvider for a scope to provide it with per-file built-in |
| 14 // variable support. | 14 // variable support. |
| 15 class ScopePerFileProvider : public Scope::ProgrammaticProvider { | 15 class ScopePerFileProvider : public Scope::ProgrammaticProvider { |
| 16 public: | 16 public: |
| 17 ScopePerFileProvider(Scope* scope, const SourceFile& source_file); | 17 ScopePerFileProvider(Scope* scope, const SourceFile& source_file); |
| 18 virtual ~ScopePerFileProvider(); | 18 virtual ~ScopePerFileProvider(); |
| 19 | 19 |
| 20 // ProgrammaticProvider implementation. | 20 // ProgrammaticProvider implementation. |
| 21 virtual const Value* GetProgrammaticValue( | 21 virtual const Value* GetProgrammaticValue( |
| 22 const base::StringPiece& ident) OVERRIDE; | 22 const base::StringPiece& ident) OVERRIDE; |
| 23 | 23 |
| 24 // Returns the value to expose to script for the given thing. These values | |
| 25 // are acually set globally, but are put here so we can keep all logic | |
| 26 // for converting paths to built-in values in this one file. | |
| 27 static Value GetRootOutputDir(const Settings* settings); | |
| 28 static Value GetRootGenDir(const Settings* settings); | |
| 29 | |
| 30 // Variable names. These two should be set globally independent of the file | |
| 31 // being processed. | |
| 32 static const char* kRootOutputDirName; | |
| 33 static const char* kRootGenDirName; | |
| 34 | |
| 35 // Variable names. These are provided by this class as needed. | |
| 36 static const char* kDefaultToolchain; | |
| 37 static const char* kPythonPath; | |
| 38 static const char* kToolchain; | |
| 39 static const char* kTargetOutputDirName; | |
| 40 static const char* kTargetGenDirName; | |
| 41 static const char* kRelativeRootOutputDirName; | |
| 42 static const char* kRelativeRootGenDirName; | |
| 43 static const char* kRelativeTargetOutputDirName; | |
| 44 static const char* kRelativeTargetGenDirName; | |
| 45 | |
| 46 private: | 24 private: |
| 25 const Value* GetCurrentToolchain(); |
| 47 const Value* GetDefaultToolchain(); | 26 const Value* GetDefaultToolchain(); |
| 48 const Value* GetPythonPath(); | 27 const Value* GetPythonPath(); |
| 49 const Value* GetToolchain(); | |
| 50 const Value* GetTargetOutputDir(); | |
| 51 const Value* GetTargetGenDir(); | |
| 52 const Value* GetRelativeRootOutputDir(); | 28 const Value* GetRelativeRootOutputDir(); |
| 53 const Value* GetRelativeRootGenDir(); | 29 const Value* GetRelativeRootGenDir(); |
| 54 const Value* GetRelativeTargetOutputDir(); | 30 const Value* GetRelativeTargetOutputDir(); |
| 55 const Value* GetRelativeTargetGenDir(); | 31 const Value* GetRelativeTargetGenDir(); |
| 56 | 32 |
| 57 static std::string GetRootOutputDirWithNoLastSlash(const Settings* settings); | 33 static std::string GetRootOutputDirWithNoLastSlash(const Settings* settings); |
| 58 static std::string GetRootGenDirWithNoLastSlash(const Settings* settings); | 34 static std::string GetRootGenDirWithNoLastSlash(const Settings* settings); |
| 59 | 35 |
| 60 std::string GetFileDirWithNoLastSlash() const; | 36 std::string GetFileDirWithNoLastSlash() const; |
| 61 std::string GetRelativeRootWithNoLastSlash() const; | 37 std::string GetRelativeRootWithNoLastSlash() const; |
| 62 | 38 |
| 63 SourceFile source_file_; | 39 SourceFile source_file_; |
| 64 | 40 |
| 65 // All values are lazily created. | 41 // All values are lazily created. |
| 42 scoped_ptr<Value> current_toolchain_; |
| 66 scoped_ptr<Value> default_toolchain_; | 43 scoped_ptr<Value> default_toolchain_; |
| 67 scoped_ptr<Value> python_path_; | 44 scoped_ptr<Value> python_path_; |
| 68 scoped_ptr<Value> toolchain_; | |
| 69 scoped_ptr<Value> target_output_dir_; | |
| 70 scoped_ptr<Value> target_gen_dir_; | |
| 71 scoped_ptr<Value> relative_root_output_dir_; | 45 scoped_ptr<Value> relative_root_output_dir_; |
| 72 scoped_ptr<Value> relative_root_gen_dir_; | 46 scoped_ptr<Value> relative_root_gen_dir_; |
| 73 scoped_ptr<Value> relative_target_output_dir_; | 47 scoped_ptr<Value> relative_target_output_dir_; |
| 74 scoped_ptr<Value> relative_target_gen_dir_; | 48 scoped_ptr<Value> relative_target_gen_dir_; |
| 75 | 49 |
| 76 DISALLOW_COPY_AND_ASSIGN(ScopePerFileProvider); | 50 DISALLOW_COPY_AND_ASSIGN(ScopePerFileProvider); |
| 77 }; | 51 }; |
| 78 | 52 |
| 79 #endif // TOOLS_GN_SCOPE_PER_FILE_PROVIDER_H_ | 53 #endif // TOOLS_GN_SCOPE_PER_FILE_PROVIDER_H_ |
| OLD | NEW |