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_INPUT_FILE_H_
      6 #define TOOLS_GN_INPUT_FILE_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/files/file_path.h"
     12 #include "base/logging.h"
     13 #include "tools/gn/source_dir.h"
     14 #include "tools/gn/source_file.h"
     15 
     16 class InputFile {
     17  public:
     18   InputFile(const SourceFile& name);
     19 
     20   ~InputFile();
     21 
     22   // The virtual name passed into the constructor. This does not take into
     23   // account whether the file was loaded from the secondary source tree (see
     24   // BuildSettings secondary_source_path).
     25   const SourceFile& name() const { return name_; }
     26 
     27   // The directory is just a cached version of name()->GetDir() but we get this
     28   // a lot so computing it once up front saves a bunch of work.
     29   const SourceDir& dir() const { return dir_; }
     30 
     31   // The physical name tells the actual name on disk, if there is one.
     32   const base::FilePath& physical_name() const { return physical_name_; }
     33 
     34   // The friendly name can be set to override the name() in cases where there
     35   // is no name (like SetContents is used instead) or if the name doesn't
     36   // make sense. This will be displayed in error messages.
     37   const std::string& friendly_name() const { return friendly_name_; }
     38   void set_friendly_name(const std::string& f) { friendly_name_ = f; }
     39 
     40   const std::string& contents() const {
     41     DCHECK(contents_loaded_);
     42     return contents_;
     43   }
     44 
     45   // For testing and in cases where this input doesn't actually refer to
     46   // "a file".
     47   void SetContents(const std::string& c);
     48 
     49   // Loads the given file synchronously, returning true on success. This
     50   bool Load(const base::FilePath& system_path);
     51 
     52  private:
     53   SourceFile name_;
     54   SourceDir dir_;
     55 
     56   base::FilePath physical_name_;
     57   std::string friendly_name_;
     58 
     59   bool contents_loaded_;
     60   std::string contents_;
     61 
     62   DISALLOW_COPY_AND_ASSIGN(InputFile);
     63 };
     64 
     65 #endif  // TOOLS_GN_INPUT_FILE_H_
     66