Skip to content

Commit

Permalink
Support pool for action_foreach
Browse files Browse the repository at this point in the history
This is follow up of pool support in action
https://codereview.chromium.org/2926013002

Using action pool can remove some overhead of many running process.
Pool support of action_foreach gives better control for some python generator step when using goma.
e.g. https://codereview.chromium.org/2726103005

Bug: 695864
Change-Id: Ibd0bbaffc59513db42119138520aee3505762eee
Reviewed-on: https://chromium-review.googlesource.com/882625
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Commit-Queue: Takuto Ikuta <tikuta@google.com>
Cr-Commit-Position: refs/heads/master@{#531844}
  • Loading branch information
atetubou authored and Commit Bot committed Jan 25, 2018
1 parent c8e779e commit 4c48a35
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tools/gn/ninja_action_target_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ void NinjaActionTargetWriter::WriteSourceRules(
WriteDepfile(sources[i]);
out_ << std::endl;
}
if (target_->action_values().pool().ptr) {
out_ << " pool = ";
out_ << target_->action_values().pool().ptr->GetNinjaName(
settings_->default_toolchain_label());
out_ << std::endl;
}
}
}

Expand Down
51 changes: 51 additions & 0 deletions tools/gn/ninja_action_target_writer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,54 @@ TEST(NinjaActionTargetWriter, ForEachWithResponseFile) {
"build obj/foo/bar.stamp: stamp input1.out\n";
EXPECT_EQ(expected_linux, out.str());
}

TEST(NinjaActionTargetWriter, ForEachWithPool) {
Err err;
TestWithScope setup;

Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
target.set_output_type(Target::ACTION_FOREACH);

target.sources().push_back(SourceFile("//foo/input1.txt"));
target.action_values().set_script(SourceFile("//foo/script.py"));

Pool pool(setup.settings(),
Label(SourceDir("//foo/"), "pool", setup.toolchain()->label().dir(),
setup.toolchain()->label().name()));
pool.set_depth(5);
target.action_values().set_pool(LabelPtrPair<Pool>(&pool));

target.SetToolchain(setup.toolchain());
ASSERT_TRUE(target.OnResolved(&err));

// Make sure we get interesting substitutions for both the args and the
// response file contents.
target.action_values().args() =
SubstitutionList::MakeForTest("{{source}}", "{{source_file_part}}");
target.action_values().outputs() =
SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out");

setup.build_settings()->set_python_path(
base::FilePath(FILE_PATH_LITERAL("/usr/bin/python")));

std::ostringstream out;
NinjaActionTargetWriter writer(&target, out);
writer.Run();

const char expected_linux[] =
"rule __foo_bar___rule\n"
// These come from the args.
" command = /usr/bin/python ../../foo/script.py ${in} "
"${source_file_part}\n"
" description = ACTION //foo:bar()\n"
" restat = 1\n"
"\n"
"build input1.out: __foo_bar___rule ../../foo/input1.txt"
" | ../../foo/script.py\n"
// Substitution for the args.
" source_file_part = input1.txt\n"
" pool = foo_pool\n"
"\n"
"build obj/foo/bar.stamp: stamp input1.out\n";
EXPECT_EQ(expected_linux, out.str());
}

0 comments on commit 4c48a35

Please sign in to comment.