Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Unified Diff: tools/gn/substitution_writer.h

Issue 440333002: Support more configurability in GN toolchains (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unsigned check Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/substitution_type.cc ('k') | tools/gn/substitution_writer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/substitution_writer.h
diff --git a/tools/gn/substitution_writer.h b/tools/gn/substitution_writer.h
index cd45566fdb988bf8d1088c81fcaf8b9d652e94cf..219f135635aee87eebb1cc7ea68b72b11931bbbf 100644
--- a/tools/gn/substitution_writer.h
+++ b/tools/gn/substitution_writer.h
@@ -18,11 +18,35 @@ class SourceDir;
class SourceFile;
class SubstitutionList;
class SubstitutionPattern;
+class Target;
+class Tool;
// Help text for script source expansion.
extern const char kSourceExpansion_Help[];
// This class handles writing or applying substitution patterns to strings.
+//
+// There are several different uses:
+//
+// - Source substitutions: These are used to compute action_foreach
+// outputs and arguments. Functions are provided to expand these in terms
+// of both OutputFiles (for writing Ninja files) as well as SourceFiles
+// (for computing lists used by code).
+//
+// - Target substitutions: These are specific to the target+tool combination
+// and are shared between the compiler and linker ones. It includes things
+// like the target_gen_dir.
+//
+// - Compiler substitutions: These are used to compute compiler outputs.
+// It includes all source substitutions (since they depend on the various
+// parts of the source file) as well as the target substitutions.
+//
+// - Linker substitutions: These are used to compute linker outputs. It
+// includes the target substitutions.
+//
+// The compiler and linker specific substitutions do NOT include the various
+// cflags, ldflags, libraries, etc. These are written by the ninja target
+// writer since they depend on traversing the dependency tree.
class SubstitutionWriter {
public:
enum OutputStyle {
@@ -30,15 +54,20 @@ class SubstitutionWriter {
OUTPUT_RELATIVE, // Dirs will be relative to a given directory.
};
- SubstitutionWriter();
- ~SubstitutionWriter();
+ // Writes the pattern to the given stream with no special handling, and with
+ // Ninja variables replacing the patterns.
+ static void WriteWithNinjaVariables(
+ const SubstitutionPattern& pattern,
+ const EscapeOptions& escape_options,
+ std::ostream& out);
+
+ // NOP substitutions ---------------------------------------------------------
// Converts the given SubstitutionList to OutputFiles assuming there are
// no substitutions (it will assert if there are). This is used for cases
// like actions where the outputs are explicit, but the list is stored as
// a SubstitutionList.
static void GetListAsSourceFiles(
- const Settings* settings,
const SubstitutionList& list,
std::vector<SourceFile>* output);
static void GetListAsOutputFiles(
@@ -46,6 +75,8 @@ class SubstitutionWriter {
const SubstitutionList& list,
std::vector<OutputFile>* output);
+ // Source substitutions -----------------------------------------------------
+
// Applies the substitution pattern to a source file, returning the result
// as either a string, a SourceFile or an OutputFile. If the result is
// expected to be a SourceFile or an OutputFile, this will CHECK if the
@@ -115,13 +146,6 @@ class SubstitutionWriter {
const EscapeOptions& escape_options,
std::ostream& out);
- // Writes the pattern to the given stream with no special handling, and with
- // Ninja variables replacing the patterns.
- static void WriteWithNinjaVariables(
- const SubstitutionPattern& pattern,
- const EscapeOptions& escape_options,
- std::ostream& out);
-
// Extracts the given type of substitution related to a source file from the
// given source file. If output_style is OUTPUT_RELATIVE, relative_to
// indicates the directory that the relative directories should be relative
@@ -132,6 +156,75 @@ class SubstitutionWriter {
SubstitutionType type,
OutputStyle output_style,
const SourceDir& relative_to);
+
+ // Target substitutions ------------------------------------------------------
+ //
+ // Handles the target substitutions that apply to both compiler and linker
+ // tools.
+ static OutputFile ApplyPatternToTargetAsOutputFile(
+ const Target* target,
+ const Tool* tool,
+ const SubstitutionPattern& pattern);
+ static void ApplyListToTargetAsOutputFile(
+ const Target* target,
+ const Tool* tool,
+ const SubstitutionList& list,
+ std::vector<OutputFile>* output);
+
+ // This function is slightly different than the other substitution getters
+ // since it can handle failure (since it is designed to be used by the
+ // compiler and linker ones which will fall through if it's not a common tool
+ // one).
+ static bool GetTargetSubstitution(
+ const Target* target,
+ SubstitutionType type,
+ std::string* result);
+ static std::string GetTargetSubstitution(
+ const Target* target,
+ SubstitutionType type);
+
+ // Compiler substitutions ----------------------------------------------------
+ //
+ // A compiler substitution allows both source and tool substitutions. These
+ // are used to compute output names for compiler tools.
+
+ static OutputFile ApplyPatternToCompilerAsOutputFile(
+ const Target* target,
+ const SourceFile& source,
+ const SubstitutionPattern& pattern);
+ static void ApplyListToCompilerAsOutputFile(
+ const Target* target,
+ const SourceFile& source,
+ const SubstitutionList& list,
+ std::vector<OutputFile>* output);
+
+ // Like GetSourceSubstitution but for strings based on the target or
+ // toolchain. This type of result will always be relative to the build
+ // directory.
+ static std::string GetCompilerSubstitution(
+ const Target* target,
+ const SourceFile& source,
+ SubstitutionType type);
+
+ // Linker substitutions ------------------------------------------------------
+
+ static OutputFile ApplyPatternToLinkerAsOutputFile(
+ const Target* target,
+ const Tool* tool,
+ const SubstitutionPattern& pattern);
+ static void ApplyListToLinkerAsOutputFile(
+ const Target* target,
+ const Tool* tool,
+ const SubstitutionList& list,
+ std::vector<OutputFile>* output);
+
+ // Like GetSourceSubstitution but for strings based on the target or
+ // toolchain. This type of result will always be relative to the build
+ // directory.
+ static std::string GetLinkerSubstitution(
+ const Target* target,
+ const Tool* tool,
+ SubstitutionType type);
};
#endif // TOOLS_GN_SUBSTITUTION_WRITER_H_
« no previous file with comments | « tools/gn/substitution_type.cc ('k') | tools/gn/substitution_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698