Commit 385a310b authored by dpranke's avatar dpranke Committed by Commit bot

Fix an issue in `gn analyze` when building all.

If you ran `gn analyze` on a list of files that changed a build file,
the list of compile targets and output targets should've been returned
unchanged, but if the additional_compile_targets input included "all", the
returned list was left empty.

R=brettw@chromium.org
BUG=648532

Review-Url: https://codereview.chromium.org/2350963006
Cr-Commit-Position: refs/heads/master@{#419866}
parent 63654595
......@@ -34,7 +34,7 @@ struct Inputs {
std::vector<SourceFile> source_vec;
std::vector<Label> compile_vec;
std::vector<Label> test_vec;
bool compile_included_all;
bool compile_included_all = false;
SourceFileSet source_files;
LabelSet compile_labels;
LabelSet test_labels;
......@@ -43,6 +43,7 @@ struct Inputs {
struct Outputs {
std::string status;
std::string error;
bool compile_includes_all = false;
LabelSet compile_labels;
LabelSet test_labels;
LabelSet invalid_labels;
......@@ -203,8 +204,14 @@ std::string OutputsToJSON(const Outputs& outputs,
outputs.invalid_labels);
} else {
WriteString(*value, "status", outputs.status);
WriteLabels(default_toolchain, *value, "compile_targets",
outputs.compile_labels);
if (outputs.compile_includes_all) {
auto compile_targets = base::WrapUnique(new base::ListValue());
compile_targets->AppendString("all");
value->Set("compile_targets", std::move(compile_targets));
} else {
WriteLabels(default_toolchain, *value, "compile_targets",
outputs.compile_labels);
}
WriteLabels(default_toolchain, *value, "test_targets", outputs.test_labels);
}
......@@ -259,7 +266,14 @@ std::string Analyzer::Analyze(const std::string& input, Err* err) const {
// or toolchain defined in that file.
if (AnyBuildFilesWereModified(inputs.source_files)) {
outputs.status = "Found dependency (all)";
outputs.compile_labels = inputs.compile_labels;
if (inputs.compile_included_all) {
outputs.compile_includes_all = true;
} else {
outputs.compile_labels.insert(inputs.compile_labels.begin(),
inputs.compile_labels.end());
outputs.compile_labels.insert(inputs.test_labels.begin(),
inputs.test_labels.end());
}
outputs.test_labels = inputs.test_labels;
return OutputsToJSON(outputs, default_toolchain_, err);
}
......
......@@ -212,7 +212,24 @@ TEST_F(AnalyzerTest, BuildFilesWereModified) {
" \"test_targets\": [ \"//:a\" ]"
"}",
"{"
"\"compile_targets\":[],"
"\"compile_targets\":[\"//:a\"],"
"\"status\":\"Found dependency (all)\","
"\"test_targets\":[\"//:a\"]"
"}");
}
TEST_F(AnalyzerTest, BuildFilesWereModifiedAndCompilingAll) {
// This tests that if a build file is modified, we bail out early with
// "Found dependency (all)" error since we can't handle changes to
// build files yet (crbug.com/555273).
RunBasicTest(
"{"
" \"files\": [ \"//a.cc\", \"//BUILD.gn\" ],"
" \"additional_compile_targets\": [ \"all\" ],"
" \"test_targets\": [ \"//:a\" ]"
"}",
"{"
"\"compile_targets\":[\"all\"],"
"\"status\":\"Found dependency (all)\","
"\"test_targets\":[\"//:a\"]"
"}");
......
......@@ -1284,8 +1284,11 @@ class MetaBuildWrapper(object):
if 'invalid_targets' in gn_outp:
outp['invalid_targets'] = gn_outp['invalid_targets']
if 'compile_targets' in gn_outp:
outp['compile_targets'] = [
label.replace('//', '') for label in gn_outp['compile_targets']]
if 'all' in gn_outp['compile_targets']:
outp['compile_targets'] = ['all']
else:
outp['compile_targets'] = [
label.replace('//', '') for label in gn_outp['compile_targets']]
if 'test_targets' in gn_outp:
outp['test_targets'] = [
labels_to_targets[label] for label in gn_outp['test_targets']]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment