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

Unified Diff: tools/gn/ninja_action_target_writer_unittest.cc

Issue 429423002: Refactor GN source expansions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/ninja_action_target_writer.cc ('k') | tools/gn/ninja_copy_target_writer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/ninja_action_target_writer_unittest.cc
diff --git a/tools/gn/ninja_action_target_writer_unittest.cc b/tools/gn/ninja_action_target_writer_unittest.cc
index 18ae7e4e3d3d739a700969f0d32cb16a722691d1..7e0572037f2d67dcce41c4852c27605c42d5d24c 100644
--- a/tools/gn/ninja_action_target_writer_unittest.cc
+++ b/tools/gn/ninja_action_target_writer_unittest.cc
@@ -6,60 +6,28 @@
#include <sstream>
#include "testing/gtest/include/gtest/gtest.h"
-#include "tools/gn/file_template.h"
#include "tools/gn/ninja_action_target_writer.h"
+#include "tools/gn/substitution_list.h"
#include "tools/gn/test_with_scope.h"
TEST(NinjaActionTargetWriter, WriteOutputFilesForBuildLine) {
TestWithScope setup;
setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
-
- target.action_values().outputs().push_back(
- "//out/Debug/gen/a b{{source_name_part}}.h");
- target.action_values().outputs().push_back(
+ target.action_values().outputs() = SubstitutionList::MakeForTest(
+ "//out/Debug/gen/a b{{source_name_part}}.h",
"//out/Debug/gen/{{source_name_part}}.cc");
std::ostringstream out;
NinjaActionTargetWriter writer(&target, setup.toolchain(), out);
- FileTemplate output_template = FileTemplate::GetForTargetOutputs(&target);
-
SourceFile source("//foo/bar.in");
std::vector<OutputFile> output_files;
- writer.WriteOutputFilesForBuildLine(output_template, source, &output_files);
+ writer.WriteOutputFilesForBuildLine(source, &output_files);
EXPECT_EQ(" gen/a$ bbar.h gen/bar.cc", out.str());
}
-TEST(NinjaActionTargetWriter, WriteArgsSubstitutions) {
- TestWithScope setup;
- setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
- Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
-
- std::ostringstream out;
- NinjaActionTargetWriter writer(&target, setup.toolchain(), out);
-
- std::vector<std::string> args;
- args.push_back("-i");
- args.push_back("{{source}}");
- args.push_back("--out=foo bar{{source_name_part}}.o");
- FileTemplate args_template(setup.settings(), args,
- FileTemplate::OUTPUT_RELATIVE,
- setup.settings()->build_settings()->build_dir());
-
- writer.WriteArgsSubstitutions(SourceFile("//foo/b ar.in"), args_template);
-#if defined(OS_WIN)
- EXPECT_EQ(" source = \"../../foo/b$ ar.in\"\n"
- " source_name_part = \"b$ ar\"\n",
- out.str());
-#else
- EXPECT_EQ(" source = ../../foo/b\\$ ar.in\n"
- " source_name_part = b\\$ ar\n",
- out.str());
-#endif
-}
-
// Makes sure that we write sources as input dependencies for actions with
// both sources and inputs (ACTION_FOREACH treats the sources differently).
TEST(NinjaActionTargetWriter, ActionWithSources) {
@@ -73,7 +41,8 @@ TEST(NinjaActionTargetWriter, ActionWithSources) {
target.sources().push_back(SourceFile("//foo/source.txt"));
target.inputs().push_back(SourceFile("//foo/included.txt"));
- target.action_values().outputs().push_back("//out/Debug/foo.out");
+ target.action_values().outputs() =
+ SubstitutionList::MakeForTest("//out/Debug/foo.out");
// Posix.
{
@@ -151,12 +120,11 @@ TEST(NinjaActionTargetWriter, ForEach) {
target.action_values().set_script(SourceFile("//foo/script.py"));
- target.action_values().args().push_back("-i");
- target.action_values().args().push_back("{{source}}");
- target.action_values().args().push_back(
+ target.action_values().args() = SubstitutionList::MakeForTest(
+ "-i",
+ "{{source}}",
"--out=foo bar{{source_name_part}}.o");
-
- target.action_values().outputs().push_back(
+ target.action_values().outputs() = SubstitutionList::MakeForTest(
"//out/Debug/{{source_name_part}}.out");
target.inputs().push_back(SourceFile("//foo/included.txt"));
@@ -173,7 +141,7 @@ TEST(NinjaActionTargetWriter, ForEach) {
const char expected_linux[] =
"rule __foo_bar___rule\n"
- " command = /usr/bin/python ../../foo/script.py -i ${source} "
+ " command = /usr/bin/python ../../foo/script.py -i ${in} "
// Escaping is different between Windows and Posix.
#if defined(OS_WIN)
"\"--out=foo$ bar${source_name_part}.o\"\n"
@@ -187,11 +155,9 @@ TEST(NinjaActionTargetWriter, ForEach) {
"\n"
"build input1.out: __foo_bar___rule ../../foo/input1.txt | "
"obj/foo/bar.inputdeps.stamp\n"
- " source = ../../foo/input1.txt\n"
" source_name_part = input1\n"
"build input2.out: __foo_bar___rule ../../foo/input2.txt | "
"obj/foo/bar.inputdeps.stamp\n"
- " source = ../../foo/input2.txt\n"
" source_name_part = input2\n"
"\n"
"build obj/foo/bar.stamp: "
@@ -223,9 +189,9 @@ TEST(NinjaActionTargetWriter, ForEach) {
" rspfile = __foo_bar___rule.$unique_name.rsp\n"
" rspfile_content = C$:/python/python.exe ../../foo/script.py -i "
#if defined(OS_WIN)
- "${source} \"--out=foo$ bar${source_name_part}.o\"\n"
+ "${in} \"--out=foo$ bar${source_name_part}.o\"\n"
#else
- "${source} --out=foo\\$ bar${source_name_part}.o\n"
+ "${in} --out=foo\\$ bar${source_name_part}.o\n"
#endif
"build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py "
"../../foo/included.txt obj/foo/dep.stamp\n"
@@ -233,12 +199,10 @@ TEST(NinjaActionTargetWriter, ForEach) {
"build input1.out: __foo_bar___rule ../../foo/input1.txt | "
"obj/foo/bar.inputdeps.stamp\n"
" unique_name = 0\n"
- " source = ../../foo/input1.txt\n"
" source_name_part = input1\n"
"build input2.out: __foo_bar___rule ../../foo/input2.txt | "
"obj/foo/bar.inputdeps.stamp\n"
" unique_name = 1\n"
- " source = ../../foo/input2.txt\n"
" source_name_part = input2\n"
"\n"
"build obj/foo/bar.stamp: "
@@ -257,15 +221,18 @@ TEST(NinjaActionTargetWriter, ForEachWithDepfile) {
target.sources().push_back(SourceFile("//foo/input2.txt"));
target.action_values().set_script(SourceFile("//foo/script.py"));
- target.action_values().set_depfile(
- SourceFile("//out/Debug/gen/{{source_name_part}}.d"));
- target.action_values().args().push_back("-i");
- target.action_values().args().push_back("{{source}}");
- target.action_values().args().push_back(
- "--out=foo bar{{source_name_part}}.o");
+ SubstitutionPattern depfile;
+ Err err;
+ ASSERT_TRUE(
+ depfile.Parse("//out/Debug/gen/{{source_name_part}}.d", NULL, &err));
+ target.action_values().set_depfile(depfile);
- target.action_values().outputs().push_back(
+ target.action_values().args() = SubstitutionList::MakeForTest(
+ "-i",
+ "{{source}}",
+ "--out=foo bar{{source_name_part}}.o");
+ target.action_values().outputs() = SubstitutionList::MakeForTest(
"//out/Debug/{{source_name_part}}.out");
target.inputs().push_back(SourceFile("//foo/included.txt"));
@@ -282,7 +249,7 @@ TEST(NinjaActionTargetWriter, ForEachWithDepfile) {
const char expected_linux[] =
"rule __foo_bar___rule\n"
- " command = /usr/bin/python ../../foo/script.py -i ${source} "
+ " command = /usr/bin/python ../../foo/script.py -i ${in} "
#if defined(OS_WIN)
"\"--out=foo$ bar${source_name_part}.o\"\n"
#else
@@ -295,12 +262,10 @@ TEST(NinjaActionTargetWriter, ForEachWithDepfile) {
"\n"
"build input1.out: __foo_bar___rule ../../foo/input1.txt"
" | obj/foo/bar.inputdeps.stamp\n"
- " source = ../../foo/input1.txt\n"
" source_name_part = input1\n"
" depfile = gen/input1.d\n"
"build input2.out: __foo_bar___rule ../../foo/input2.txt"
" | obj/foo/bar.inputdeps.stamp\n"
- " source = ../../foo/input2.txt\n"
" source_name_part = input2\n"
" depfile = gen/input2.d\n"
"\n"
@@ -327,9 +292,9 @@ TEST(NinjaActionTargetWriter, ForEachWithDepfile) {
" rspfile = __foo_bar___rule.$unique_name.rsp\n"
" rspfile_content = C$:/python/python.exe ../../foo/script.py -i "
#if defined(OS_WIN)
- "${source} \"--out=foo$ bar${source_name_part}.o\"\n"
+ "${in} \"--out=foo$ bar${source_name_part}.o\"\n"
#else
- "${source} --out=foo\\$ bar${source_name_part}.o\n"
+ "${in} --out=foo\\$ bar${source_name_part}.o\n"
#endif
"build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py "
"../../foo/included.txt\n"
@@ -337,13 +302,11 @@ TEST(NinjaActionTargetWriter, ForEachWithDepfile) {
"build input1.out: __foo_bar___rule ../../foo/input1.txt"
" | obj/foo/bar.inputdeps.stamp\n"
" unique_name = 0\n"
- " source = ../../foo/input1.txt\n"
" source_name_part = input1\n"
" depfile = gen/input1.d\n"
"build input2.out: __foo_bar___rule ../../foo/input2.txt"
" | obj/foo/bar.inputdeps.stamp\n"
" unique_name = 1\n"
- " source = ../../foo/input2.txt\n"
" source_name_part = input2\n"
" depfile = gen/input2.d\n"
"\n"
« no previous file with comments | « tools/gn/ninja_action_target_writer.cc ('k') | tools/gn/ninja_copy_target_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698