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 16class 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 const std::string& contents() const { 35 DCHECK(contents_loaded_); 36 return contents_; 37 } 38 39 // For testing and in cases where this input doesn't actually refer to 40 // "a file". 41 void SetContents(const std::string& c); 42 43 // Loads the given file synchronously, returning true on success. This 44 bool Load(const base::FilePath& system_path); 45 46 private: 47 SourceFile name_; 48 SourceDir dir_; 49 50 base::FilePath physical_name_; 51 52 bool contents_loaded_; 53 std::string contents_; 54 55 DISALLOW_COPY_AND_ASSIGN(InputFile); 56}; 57 58#endif // TOOLS_GN_INPUT_FILE_H_ 59