| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <sstream> | 6 #include <sstream> |
| 7 | 7 |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "tools/gn/file_template.h" | 9 #include "tools/gn/file_template.h" |
| 10 #include "tools/gn/ninja_action_target_writer.h" | 10 #include "tools/gn/ninja_action_target_writer.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 FileTemplate output_template = writer.GetOutputTemplate(); | 26 FileTemplate output_template = writer.GetOutputTemplate(); |
| 27 | 27 |
| 28 SourceFile source("//foo/bar.in"); | 28 SourceFile source("//foo/bar.in"); |
| 29 std::vector<OutputFile> output_files; | 29 std::vector<OutputFile> output_files; |
| 30 writer.WriteOutputFilesForBuildLine(output_template, source, &output_files); | 30 writer.WriteOutputFilesForBuildLine(output_template, source, &output_files); |
| 31 | 31 |
| 32 EXPECT_EQ(" gen/a$ bbar.h gen/bar.cc", out.str()); | 32 EXPECT_EQ(" gen/a$ bbar.h gen/bar.cc", out.str()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 TEST(NinjaActionTargetWriter, WriteOutputFilesForBuildLineWithDepfile) { | |
| 36 TestWithScope setup; | |
| 37 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | |
| 38 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | |
| 39 | |
| 40 target.action_values().set_depfile( | |
| 41 SourceFile("//out/Debug/gen/{{source_name_part}}.d")); | |
| 42 target.action_values().outputs().push_back( | |
| 43 SourceFile("//out/Debug/gen/{{source_name_part}}.h")); | |
| 44 target.action_values().outputs().push_back( | |
| 45 SourceFile("//out/Debug/gen/{{source_name_part}}.cc")); | |
| 46 | |
| 47 std::ostringstream out; | |
| 48 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); | |
| 49 | |
| 50 FileTemplate output_template = writer.GetOutputTemplate(); | |
| 51 | |
| 52 SourceFile source("//foo/bar.in"); | |
| 53 std::vector<OutputFile> output_files; | |
| 54 writer.WriteOutputFilesForBuildLine(output_template, source, &output_files); | |
| 55 | |
| 56 EXPECT_EQ(" gen/bar.d gen/bar.h gen/bar.cc", out.str()); | |
| 57 } | |
| 58 | |
| 59 TEST(NinjaActionTargetWriter, WriteArgsSubstitutions) { | 35 TEST(NinjaActionTargetWriter, WriteArgsSubstitutions) { |
| 60 TestWithScope setup; | 36 TestWithScope setup; |
| 61 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 37 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
| 62 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 38 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
| 63 | 39 |
| 64 std::ostringstream out; | 40 std::ostringstream out; |
| 65 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); | 41 NinjaActionTargetWriter writer(&target, setup.toolchain(), out); |
| 66 | 42 |
| 67 std::vector<std::string> args; | 43 std::vector<std::string> args; |
| 68 args.push_back("-i"); | 44 args.push_back("-i"); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 #if defined(OS_WIN) | 286 #if defined(OS_WIN) |
| 311 "\"--out=foo$ bar${source_name_part}.o\"\n" | 287 "\"--out=foo$ bar${source_name_part}.o\"\n" |
| 312 #else | 288 #else |
| 313 "--out=foo\\$ bar${source_name_part}.o\n" | 289 "--out=foo\\$ bar${source_name_part}.o\n" |
| 314 #endif | 290 #endif |
| 315 " description = ACTION //foo:bar()\n" | 291 " description = ACTION //foo:bar()\n" |
| 316 " restat = 1\n" | 292 " restat = 1\n" |
| 317 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " | 293 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " |
| 318 "../../foo/included.txt\n" | 294 "../../foo/included.txt\n" |
| 319 "\n" | 295 "\n" |
| 320 "build gen/input1.d input1.out: __foo_bar___rule ../../foo/input1.txt" | 296 "build input1.out: __foo_bar___rule ../../foo/input1.txt" |
| 321 " | obj/foo/bar.inputdeps.stamp\n" | 297 " | obj/foo/bar.inputdeps.stamp\n" |
| 322 " source = ../../foo/input1.txt\n" | 298 " source = ../../foo/input1.txt\n" |
| 323 " source_name_part = input1\n" | 299 " source_name_part = input1\n" |
| 324 " depfile = gen/input1.d\n" | 300 " depfile = gen/input1.d\n" |
| 325 "build gen/input2.d input2.out: __foo_bar___rule ../../foo/input2.txt" | 301 "build input2.out: __foo_bar___rule ../../foo/input2.txt" |
| 326 " | obj/foo/bar.inputdeps.stamp\n" | 302 " | obj/foo/bar.inputdeps.stamp\n" |
| 327 " source = ../../foo/input2.txt\n" | 303 " source = ../../foo/input2.txt\n" |
| 328 " source_name_part = input2\n" | 304 " source_name_part = input2\n" |
| 329 " depfile = gen/input2.d\n" | 305 " depfile = gen/input2.d\n" |
| 330 "\n" | 306 "\n" |
| 331 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; | 307 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; |
| 332 EXPECT_EQ(expected_linux, out.str()); | 308 EXPECT_EQ(expected_linux, out.str()); |
| 333 } | 309 } |
| 334 | 310 |
| 335 // Windows. | 311 // Windows. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 351 " rspfile = __foo_bar___rule.$unique_name.rsp\n" | 327 " rspfile = __foo_bar___rule.$unique_name.rsp\n" |
| 352 " rspfile_content = C$:/python/python.exe ../../foo/script.py -i " | 328 " rspfile_content = C$:/python/python.exe ../../foo/script.py -i " |
| 353 #if defined(OS_WIN) | 329 #if defined(OS_WIN) |
| 354 "${source} \"--out=foo$ bar${source_name_part}.o\"\n" | 330 "${source} \"--out=foo$ bar${source_name_part}.o\"\n" |
| 355 #else | 331 #else |
| 356 "${source} --out=foo\\$ bar${source_name_part}.o\n" | 332 "${source} --out=foo\\$ bar${source_name_part}.o\n" |
| 357 #endif | 333 #endif |
| 358 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " | 334 "build obj/foo/bar.inputdeps.stamp: stamp ../../foo/script.py " |
| 359 "../../foo/included.txt\n" | 335 "../../foo/included.txt\n" |
| 360 "\n" | 336 "\n" |
| 361 "build gen/input1.d input1.out: __foo_bar___rule ../../foo/input1.txt" | 337 "build input1.out: __foo_bar___rule ../../foo/input1.txt" |
| 362 " | obj/foo/bar.inputdeps.stamp\n" | 338 " | obj/foo/bar.inputdeps.stamp\n" |
| 363 " unique_name = 0\n" | 339 " unique_name = 0\n" |
| 364 " source = ../../foo/input1.txt\n" | 340 " source = ../../foo/input1.txt\n" |
| 365 " source_name_part = input1\n" | 341 " source_name_part = input1\n" |
| 366 " depfile = gen/input1.d\n" | 342 " depfile = gen/input1.d\n" |
| 367 "build gen/input2.d input2.out: __foo_bar___rule ../../foo/input2.txt" | 343 "build input2.out: __foo_bar___rule ../../foo/input2.txt" |
| 368 " | obj/foo/bar.inputdeps.stamp\n" | 344 " | obj/foo/bar.inputdeps.stamp\n" |
| 369 " unique_name = 1\n" | 345 " unique_name = 1\n" |
| 370 " source = ../../foo/input2.txt\n" | 346 " source = ../../foo/input2.txt\n" |
| 371 " source_name_part = input2\n" | 347 " source_name_part = input2\n" |
| 372 " depfile = gen/input2.d\n" | 348 " depfile = gen/input2.d\n" |
| 373 "\n" | 349 "\n" |
| 374 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; | 350 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; |
| 375 EXPECT_EQ(expected_win, out.str()); | 351 EXPECT_EQ(expected_win, out.str()); |
| 376 } | 352 } |
| 377 } | 353 } |
| OLD | NEW |