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.
5 #ifndef TOOLS_GN_INPUT_FILE_H_
6 #define TOOLS_GN_INPUT_FILE_H_
10 #include "base/files/file_path.h"
11 #include "base/logging.h"
12 #include "base/macros.h"
13 #include "tools/gn/source_dir.h"
14 #include "tools/gn/source_file.h"
18 explicit InputFile(const SourceFile
& name
);
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_
; }
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_
; }
31 // The physical name tells the actual name on disk, if there is one.
32 const base::FilePath
& physical_name() const { return physical_name_
; }
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
; }
40 const std::string
& contents() const {
41 DCHECK(contents_loaded_
);
45 // For testing and in cases where this input doesn't actually refer to
47 void SetContents(const std::string
& c
);
49 // Loads the given file synchronously, returning true on success. This
50 bool Load(const base::FilePath
& system_path
);
56 base::FilePath physical_name_
;
57 std::string friendly_name_
;
59 bool contents_loaded_
;
60 std::string contents_
;
62 DISALLOW_COPY_AND_ASSIGN(InputFile
);
65 #endif // TOOLS_GN_INPUT_FILE_H_