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 "base/basictypes.h"
9#include "base/memory/scoped_ptr.h"
10#include "tools/gn/scope.h"
11#include "tools/gn/source_file.h"
12
13// ProgrammaticProvider for a scope to provide it with per-file built-in
14// variable support.
15class ScopePerFileProvider : public Scope::ProgrammaticProvider {
16 public:
17  ScopePerFileProvider(Scope* scope, const SourceFile& source_file);
18  virtual ~ScopePerFileProvider();
19
20  // ProgrammaticProvider implementation.
21  virtual const Value* GetProgrammaticValue(
22      const base::StringPiece& ident) OVERRIDE;
23
24 private:
25  const Value* GetCurrentToolchain();
26  const Value* GetDefaultToolchain();
27  const Value* GetPythonPath();
28  const Value* GetRelativeRootOutputDir();
29  const Value* GetRelativeRootGenDir();
30  const Value* GetRelativeTargetOutputDir();
31  const Value* GetRelativeTargetGenDir();
32
33  static std::string GetRootOutputDirWithNoLastSlash(const Settings* settings);
34  static std::string GetRootGenDirWithNoLastSlash(const Settings* settings);
35
36  std::string GetFileDirWithNoLastSlash() const;
37  std::string GetRelativeRootWithNoLastSlash() const;
38
39  SourceFile source_file_;
40
41  // All values are lazily created.
42  scoped_ptr<Value> current_toolchain_;
43  scoped_ptr<Value> default_toolchain_;
44  scoped_ptr<Value> python_path_;
45  scoped_ptr<Value> relative_root_output_dir_;
46  scoped_ptr<Value> relative_root_gen_dir_;
47  scoped_ptr<Value> relative_target_output_dir_;
48  scoped_ptr<Value> relative_target_gen_dir_;
49
50  DISALLOW_COPY_AND_ASSIGN(ScopePerFileProvider);
51};
52
53#endif  // TOOLS_GN_SCOPE_PER_FILE_PROVIDER_H_
54