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. 4 5 #include "gn/output_file.h" 6 7 #include "gn/filesystem_utils.h" 8 #include "gn/source_file.h" 9 OutputFile(std::string && v)10OutputFile::OutputFile(std::string&& v) : value_(std::move(v)) {} 11 OutputFile(const std::string & v)12OutputFile::OutputFile(const std::string& v) : value_(v) {} 13 OutputFile(const BuildSettings * build_settings,const SourceFile & source_file)14OutputFile::OutputFile(const BuildSettings* build_settings, 15 const SourceFile& source_file) 16 : value_(RebasePath(source_file.value(), 17 build_settings->build_dir(), 18 build_settings->root_path_utf8())) {} 19 AsSourceFile(const BuildSettings * build_settings) const20SourceFile OutputFile::AsSourceFile(const BuildSettings* build_settings) const { 21 DCHECK(!value_.empty()); 22 DCHECK(value_[value_.size() - 1] != '/'); 23 24 std::string path = build_settings->build_dir().value(); 25 path.append(value_); 26 return SourceFile(std::move(path)); 27 } 28 AsSourceDir(const BuildSettings * build_settings) const29SourceDir OutputFile::AsSourceDir(const BuildSettings* build_settings) const { 30 if (!value_.empty()) { 31 // Empty means the root build dir. Otherwise, we expect it to end in a 32 // slash. 33 DCHECK(value_[value_.size() - 1] == '/'); 34 } 35 std::string path = build_settings->build_dir().value(); 36 path.append(value_); 37 NormalizePath(&path); 38 return SourceDir(std::move(path)); 39 } 40