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

Unified Diff: tools/gn/substitution_writer.cc

Issue 2387763002: Support for source_target_relative expansion in GN (Closed)
Patch Set: Reimplemented as source_target_relative Created 4 years, 2 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
Index: tools/gn/substitution_writer.cc
diff --git a/tools/gn/substitution_writer.cc b/tools/gn/substitution_writer.cc
index ce574856c7aaf123dde1869920a2670f0d89c698..2c1e3d1f710e2a1b2fb6d5e829fe89914f1bcb1d 100644
--- a/tools/gn/substitution_writer.cc
+++ b/tools/gn/substitution_writer.cc
@@ -105,6 +105,12 @@ const char kSourceExpansion_Help[] =
" directory than the build.gn file.\n"
" \"//foo/bar/baz.txt\" => \"obj/foo/bar\"\n"
"\n"
+ " {{source_target_relative}}\n"
+ " The path to the source file relative to the target's directory.\n"
+ " This will generally be used for replicating the source directory\n"
+ " layout in the output directory.\n"
+ " \"//foo/bar/baz.txt\" => \"baz.txt\"\n"
brettw 2016/10/05 19:47:50 Can this comment mention this only works in action
Petr Hosek 2016/10/11 00:59:49 Done.
+ "\n"
"(*) Note on directories\n"
"\n"
" Paths containing directories (except the source_root_relative_dir)\n"
@@ -203,11 +209,12 @@ void SubstitutionWriter::GetListAsOutputFiles(
// static
SourceFile SubstitutionWriter::ApplyPatternToSource(
+ const Target* target,
const Settings* settings,
const SubstitutionPattern& pattern,
const SourceFile& source) {
std::string result_value = ApplyPatternToSourceAsString(
- settings, pattern, source);
+ target, settings, pattern, source);
CHECK(!result_value.empty() && result_value[0] == '/')
<< "The result of the pattern \""
<< pattern.AsString()
@@ -217,6 +224,7 @@ SourceFile SubstitutionWriter::ApplyPatternToSource(
// static
std::string SubstitutionWriter::ApplyPatternToSourceAsString(
+ const Target* target,
const Settings* settings,
const SubstitutionPattern& pattern,
const SourceFile& source) {
@@ -226,7 +234,7 @@ std::string SubstitutionWriter::ApplyPatternToSourceAsString(
result_value.append(subrange.literal);
} else {
result_value.append(
- GetSourceSubstitution(settings, source, subrange.type,
+ GetSourceSubstitution(target, settings, source, subrange.type,
OUTPUT_ABSOLUTE, SourceDir()));
}
}
@@ -235,78 +243,89 @@ std::string SubstitutionWriter::ApplyPatternToSourceAsString(
// static
OutputFile SubstitutionWriter::ApplyPatternToSourceAsOutputFile(
+ const Target* target,
const Settings* settings,
const SubstitutionPattern& pattern,
const SourceFile& source) {
- SourceFile result_as_source = ApplyPatternToSource(settings, pattern, source);
+ SourceFile result_as_source = ApplyPatternToSource(
+ target, settings, pattern, source);
return OutputFile(settings->build_settings(), result_as_source);
}
// static
void SubstitutionWriter::ApplyListToSource(
+ const Target* target,
const Settings* settings,
const SubstitutionList& list,
const SourceFile& source,
std::vector<SourceFile>* output) {
for (const auto& item : list.list())
- output->push_back(ApplyPatternToSource(settings, item, source));
+ output->push_back(ApplyPatternToSource(target, settings, item, source));
}
// static
void SubstitutionWriter::ApplyListToSourceAsString(
+ const Target* target,
const Settings* settings,
const SubstitutionList& list,
const SourceFile& source,
std::vector<std::string>* output) {
for (const auto& item : list.list())
- output->push_back(ApplyPatternToSourceAsString(settings, item, source));
+ output->push_back(ApplyPatternToSourceAsString(
+ target, settings, item, source));
}
// static
void SubstitutionWriter::ApplyListToSourceAsOutputFile(
+ const Target* target,
const Settings* settings,
const SubstitutionList& list,
const SourceFile& source,
std::vector<OutputFile>* output) {
for (const auto& item : list.list())
- output->push_back(ApplyPatternToSourceAsOutputFile(settings, item, source));
+ output->push_back(ApplyPatternToSourceAsOutputFile(
+ target, settings, item, source));
}
// static
void SubstitutionWriter::ApplyListToSources(
+ const Target* target,
const Settings* settings,
const SubstitutionList& list,
const std::vector<SourceFile>& sources,
std::vector<SourceFile>* output) {
output->clear();
for (const auto& source : sources)
- ApplyListToSource(settings, list, source, output);
+ ApplyListToSource(target, settings, list, source, output);
}
// static
void SubstitutionWriter::ApplyListToSourcesAsString(
+ const Target* target,
const Settings* settings,
const SubstitutionList& list,
const std::vector<SourceFile>& sources,
std::vector<std::string>* output) {
output->clear();
for (const auto& source : sources)
- ApplyListToSourceAsString(settings, list, source, output);
+ ApplyListToSourceAsString(target, settings, list, source, output);
}
// static
void SubstitutionWriter::ApplyListToSourcesAsOutputFile(
+ const Target* target,
const Settings* settings,
const SubstitutionList& list,
const std::vector<SourceFile>& sources,
std::vector<OutputFile>* output) {
output->clear();
for (const auto& source : sources)
- ApplyListToSourceAsOutputFile(settings, list, source, output);
+ ApplyListToSourceAsOutputFile(target, settings, list, source, output);
}
// static
void SubstitutionWriter::WriteNinjaVariablesForSource(
+ const Target* target,
const Settings* settings,
const SourceFile& source,
const std::vector<SubstitutionType>& types,
@@ -321,7 +340,8 @@ void SubstitutionWriter::WriteNinjaVariablesForSource(
out << " " << kSubstitutionNinjaNames[type] << " = ";
EscapeStringToStream(
out,
- GetSourceSubstitution(settings, source, type, OUTPUT_RELATIVE,
+ GetSourceSubstitution(target, settings, source, type,
+ OUTPUT_RELATIVE,
settings->build_settings()->build_dir()),
escape_options);
out << std::endl;
@@ -331,6 +351,7 @@ void SubstitutionWriter::WriteNinjaVariablesForSource(
// static
std::string SubstitutionWriter::GetSourceSubstitution(
+ const Target* target,
const Settings* settings,
const SourceFile& source,
SubstitutionType type,
@@ -373,6 +394,13 @@ std::string SubstitutionWriter::GetSourceSubstitution(
BuildDirContext(settings), source.GetDir(), BuildDirType::OBJ));
break;
+ case SUBSTITUTION_SOURCE_TARGET_RELATIVE:
+ if (target)
brettw 2016/10/05 19:47:50 Chrome-style says this condition needs {}
Petr Hosek 2016/10/11 00:59:49 Done.
+ return RebasePath(source.value(), target->label().dir(),
+ settings->build_settings()->root_path_utf8());
+ to_rebase = source.value();
brettw 2016/10/05 19:47:50 In the "else" case here, I think it would be bette
Petr Hosek 2016/10/11 00:59:49 Done.
+ break;
+
default:
NOTREACHED()
<< "Unsupported substitution for this function: "
@@ -509,7 +537,7 @@ std::string SubstitutionWriter::GetCompilerSubstitution(
// Fall-through to the source ones.
return GetSourceSubstitution(
- target->settings(), source, type, OUTPUT_RELATIVE,
+ target, target->settings(), source, type, OUTPUT_RELATIVE,
target->settings()->build_settings()->build_dir());
}

Powered by Google App Engine
This is Rietveld 408576698