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_PATH_OUTPUT_H_
6 #define TOOLS_GN_PATH_OUTPUT_H_
11 #include "base/basictypes.h"
12 #include "base/strings/string_piece.h"
13 #include "tools/gn/escape.h"
14 #include "tools/gn/source_dir.h"
15 #include "tools/gn/unique_vector.h"
24 // Writes file names to streams assuming a certain input directory and
25 // escaping rules. This gives us a central place for managing this state.
28 // Controls whether writing directory names include the trailing slash.
29 // Often we don't want the trailing slash when writing out to a command line,
30 // especially on Windows where it's a backslash and might be interpreted as
31 // escaping the thing following it.
33 DIR_INCLUDE_LAST_SLASH
,
37 PathOutput(const SourceDir
& current_dir
, const base::StringPiece
& source_root
,
38 EscapingMode escaping
);
41 // Read-only since inverse_current_dir_ is computed depending on this.
42 EscapingMode
escaping_mode() const { return options_
.mode
; }
44 const SourceDir
& current_dir() const { return current_dir_
; }
46 // Getter/setters for flags inside the escape options.
47 bool inhibit_quoting() const { return options_
.inhibit_quoting
; }
48 void set_inhibit_quoting(bool iq
) { options_
.inhibit_quoting
= iq
; }
49 void set_escape_platform(EscapingPlatform p
) { options_
.platform
= p
; }
51 void WriteFile(std::ostream
& out
, const SourceFile
& file
) const;
52 void WriteFile(std::ostream
& out
, const OutputFile
& file
) const;
53 void WriteFile(std::ostream
& out
, const base::FilePath
& file
) const;
55 // Writes the given OutputFiles with spaces separating them. This will also
56 // write an initial space before the first item.
57 void WriteFiles(std::ostream
& out
,
58 const std::vector
<OutputFile
>& files
) const;
59 void WriteFiles(std::ostream
& out
,
60 const UniqueVector
<OutputFile
>& files
) const;
62 // This variant assumes the dir ends in a trailing slash or is empty.
63 void WriteDir(std::ostream
& out
,
65 DirSlashEnding slash_ending
) const;
67 void WriteDir(std::ostream
& out
,
68 const OutputFile
& file
,
69 DirSlashEnding slash_ending
) const;
71 // Backend for WriteFile and WriteDir. This appends the given file or
72 // directory string to the file.
73 void WritePathStr(std::ostream
& out
, const base::StringPiece
& str
) const;
76 // Takes the given string and writes it out, appending to the inverse
77 // current dir. This assumes leading slashes have been trimmed.
78 void WriteSourceRelativeString(std::ostream
& out
,
79 const base::StringPiece
& str
) const;
81 SourceDir current_dir_
;
83 // Uses system slashes if convert_slashes_to_system_.
84 std::string inverse_current_dir_
;
86 // Since the inverse_current_dir_ depends on some of these, we don't expose
87 // this directly to modification.
88 EscapeOptions options_
;
91 #endif // TOOLS_GN_PATH_OUTPUT_H_