1 // Copyright 2014 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 #include "tools/gn/output_file.h"
7 #include "tools/gn/filesystem_utils.h"
8 #include "tools/gn/source_file.h"
10 OutputFile::OutputFile() : value_() {
13 OutputFile::OutputFile(std::string
&& v
)
17 OutputFile::OutputFile(const std::string
& v
)
21 OutputFile::OutputFile(const BuildSettings
* build_settings
,
22 const SourceFile
& source_file
)
23 : value_(RebasePath(source_file
.value(),
24 build_settings
->build_dir(),
25 build_settings
->root_path_utf8())) {
28 OutputFile::~OutputFile() {
31 SourceFile
OutputFile::AsSourceFile(const BuildSettings
* build_settings
) const {
32 DCHECK(!value_
.empty());
33 DCHECK(value_
[value_
.size() - 1] != '/');
35 std::string path
= build_settings
->build_dir().value();
38 return SourceFile(path
);
41 SourceDir
OutputFile::AsSourceDir(const BuildSettings
* build_settings
) const {
42 if (!value_
.empty()) {
43 // Empty means the root build dir. Otherwise, we expect it to end in a
45 DCHECK(value_
[value_
.size() - 1] == '/');
47 std::string path
= build_settings
->build_dir().value();
50 return SourceDir(path
);