Home | History | Annotate | Download | only in gn
      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_BUILD_SETTINGS_H_
      6 #define TOOLS_GN_BUILD_SETTINGS_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/callback.h"
     10 #include "base/files/file_path.h"
     11 #include "tools/gn/item_tree.h"
     12 #include "tools/gn/scope.h"
     13 #include "tools/gn/source_dir.h"
     14 #include "tools/gn/source_file.h"
     15 #include "tools/gn/target_manager.h"
     16 #include "tools/gn/toolchain_manager.h"
     17 
     18 // Settings for one build, which is one toplevel output directory. There
     19 // may be multiple Settings objects that refer to this, one for each toolchain.
     20 class BuildSettings {
     21  public:
     22   typedef base::Callback<void(const Target*)> TargetResolvedCallback;
     23 
     24   BuildSettings();
     25   ~BuildSettings();
     26 
     27   // Absolute path of the source root on the local system. Everything is
     28   // relative to this.
     29   const base::FilePath& root_path() const { return root_path_; }
     30   void set_root_path(const base::FilePath& r) { root_path_ = r; }
     31 
     32   // When nonempty, specifies a parallel directory higherarchy in which to
     33   // search for buildfiles if they're not found in the root higherarchy. This
     34   // allows us to keep buildfiles in a separate tree during development.
     35   const base::FilePath& secondary_source_path() const {
     36     return secondary_source_path_;
     37   }
     38   void SetSecondarySourcePath(const SourceDir& d);
     39 
     40   // Path of the python executable to run scripts with.
     41   base::FilePath python_path() const { return python_path_; }
     42   void set_python_path(const base::FilePath& p) { python_path_ = p; }
     43 
     44   const SourceFile& build_config_file() const { return build_config_file_; }
     45   void set_build_config_file(const SourceFile& f) { build_config_file_ = f; }
     46 
     47   // The build directory is the root of all output files. The default toolchain
     48   // files go into here, and non-default toolchains will have separate
     49   // toolchain-specific root directories inside this.
     50   const SourceDir& build_dir() const { return build_dir_; }
     51   void SetBuildDir(const SourceDir& dir);
     52 
     53   // The inverse of relative_build_dir, ending with a separator.
     54   // Example: relative_build_dir_ = "out/Debug/" this will be "../../"
     55   const std::string& build_to_source_dir_string() const {
     56     return build_to_source_dir_string_;
     57   }
     58 
     59   // These accessors do not return const objects since the resulting objects
     60   // are threadsafe. In this setting, we use constness primarily to ensure
     61   // that the Settings object is used in a threadsafe manner. Although this
     62   // violates the concept of logical constness, that's less important in our
     63   // application, and actually implementing this in a way that preserves
     64   // logical constness is cumbersome.
     65   ItemTree& item_tree() const { return item_tree_; }
     66   TargetManager& target_manager() const { return target_manager_; }
     67   ToolchainManager& toolchain_manager() const { return toolchain_manager_; }
     68 
     69   // Returns the full absolute OS path cooresponding to the given file in the
     70   // root source tree.
     71   base::FilePath GetFullPath(const SourceFile& file) const;
     72   base::FilePath GetFullPath(const SourceDir& dir) const;
     73 
     74   // Returns the absolute OS path inside the secondary source path. Will return
     75   // an empty FilePath if the secondary source path is empty. When loading a
     76   // buildfile, the GetFullPath should always be consulted first.
     77   base::FilePath GetFullPathSecondary(const SourceFile& file) const;
     78   base::FilePath GetFullPathSecondary(const SourceDir& dir) const;
     79 
     80   // This is the callback to execute when a target is marked resolved. If we
     81   // don't need to do anything, this will be null. When a target is resolved,
     82   // this callback should be posted to the scheduler pool so the work is
     83   // distributed properly.
     84   const TargetResolvedCallback& target_resolved_callback() const {
     85     return target_resolved_callback_;
     86   }
     87   void set_target_resolved_callback(const TargetResolvedCallback& cb) {
     88     target_resolved_callback_ = cb;
     89   }
     90 
     91  private:
     92   base::FilePath root_path_;
     93   base::FilePath secondary_source_path_;
     94   base::FilePath python_path_;
     95 
     96   SourceFile build_config_file_;
     97   SourceDir build_dir_;
     98   std::string build_to_source_dir_string_;
     99 
    100   TargetResolvedCallback target_resolved_callback_;
    101 
    102   // See getters above.
    103   mutable ItemTree item_tree_;
    104   mutable TargetManager target_manager_;
    105   mutable ToolchainManager toolchain_manager_;
    106 
    107   DISALLOW_COPY_AND_ASSIGN(BuildSettings);
    108 };
    109 
    110 #endif  // TOOLS_GN_BUILD_SETTINGS_H_
    111