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

Side by Side Diff: tools/gn/filesystem_utils_unittest.cc

Issue 440333002: Support more configurability in GN toolchains (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unsigned check 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/filesystem_utils.cc ('k') | tools/gn/function_get_target_outputs.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/strings/string_util.h" 5 #include "base/strings/string_util.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "tools/gn/filesystem_utils.h" 9 #include "tools/gn/filesystem_utils.h"
10 #include "tools/gn/target.h"
10 11
11 TEST(FilesystemUtils, FileExtensionOffset) { 12 TEST(FilesystemUtils, FileExtensionOffset) {
12 EXPECT_EQ(std::string::npos, FindExtensionOffset("")); 13 EXPECT_EQ(std::string::npos, FindExtensionOffset(""));
13 EXPECT_EQ(std::string::npos, FindExtensionOffset("foo/bar/baz")); 14 EXPECT_EQ(std::string::npos, FindExtensionOffset("foo/bar/baz"));
14 EXPECT_EQ(4u, FindExtensionOffset("foo.")); 15 EXPECT_EQ(4u, FindExtensionOffset("foo."));
15 EXPECT_EQ(4u, FindExtensionOffset("f.o.bar")); 16 EXPECT_EQ(4u, FindExtensionOffset("f.o.bar"));
16 EXPECT_EQ(std::string::npos, FindExtensionOffset("foo.bar/")); 17 EXPECT_EQ(std::string::npos, FindExtensionOffset("foo.bar/"));
17 EXPECT_EQ(std::string::npos, FindExtensionOffset("foo.bar/baz")); 18 EXPECT_EQ(std::string::npos, FindExtensionOffset("foo.bar/baz"));
18 } 19 }
19 20
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 89
89 SourceDir regular2("//foo/bar/"); 90 SourceDir regular2("//foo/bar/");
90 EXPECT_EQ("bar", FindLastDirComponent(regular2)); 91 EXPECT_EQ("bar", FindLastDirComponent(regular2));
91 } 92 }
92 93
93 TEST(FilesystemUtils, EnsureStringIsInOutputDir) { 94 TEST(FilesystemUtils, EnsureStringIsInOutputDir) {
94 SourceDir output_dir("//out/Debug/"); 95 SourceDir output_dir("//out/Debug/");
95 96
96 // Some outside. 97 // Some outside.
97 Err err; 98 Err err;
98 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, "//foo", Value(), &err)); 99 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, "//foo", NULL, &err));
99 EXPECT_TRUE(err.has_error()); 100 EXPECT_TRUE(err.has_error());
100 err = Err(); 101 err = Err();
101 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, "//out/Debugit", Value(), 102 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, "//out/Debugit", NULL,
102 &err)); 103 &err));
103 EXPECT_TRUE(err.has_error()); 104 EXPECT_TRUE(err.has_error());
104 105
105 // Some inside. 106 // Some inside.
106 err = Err(); 107 err = Err();
107 EXPECT_TRUE(EnsureStringIsInOutputDir(output_dir, "//out/Debug/", Value(), 108 EXPECT_TRUE(EnsureStringIsInOutputDir(output_dir, "//out/Debug/", NULL,
108 &err)); 109 &err));
109 EXPECT_FALSE(err.has_error()); 110 EXPECT_FALSE(err.has_error());
110 EXPECT_TRUE(EnsureStringIsInOutputDir(output_dir, "//out/Debug/foo", Value(), 111 EXPECT_TRUE(EnsureStringIsInOutputDir(output_dir, "//out/Debug/foo", NULL,
111 &err)); 112 &err));
112 EXPECT_FALSE(err.has_error()); 113 EXPECT_FALSE(err.has_error());
113 114
114 // Pattern but no template expansions are allowed. 115 // Pattern but no template expansions are allowed.
115 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, "{{source_gen_dir}}", 116 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, "{{source_gen_dir}}",
116 Value(), &err)); 117 NULL, &err));
117 EXPECT_TRUE(err.has_error()); 118 EXPECT_TRUE(err.has_error());
118 } 119 }
119 120
120 TEST(FilesystemUtils, IsPathAbsolute) { 121 TEST(FilesystemUtils, IsPathAbsolute) {
121 EXPECT_TRUE(IsPathAbsolute("/foo/bar")); 122 EXPECT_TRUE(IsPathAbsolute("/foo/bar"));
122 EXPECT_TRUE(IsPathAbsolute("/")); 123 EXPECT_TRUE(IsPathAbsolute("/"));
123 EXPECT_FALSE(IsPathAbsolute("")); 124 EXPECT_FALSE(IsPathAbsolute(""));
124 EXPECT_FALSE(IsPathAbsolute("//")); 125 EXPECT_FALSE(IsPathAbsolute("//"));
125 EXPECT_FALSE(IsPathAbsolute("//foo/bar")); 126 EXPECT_FALSE(IsPathAbsolute("//foo/bar"));
126 127
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 // Should be case-sensitive. 351 // Should be case-sensitive.
351 EXPECT_EQ("/SOURCE/foo/bar/", SourceDirForPath(root, 352 EXPECT_EQ("/SOURCE/foo/bar/", SourceDirForPath(root,
352 base::FilePath("/SOURCE/foo/bar/")).value()); 353 base::FilePath("/SOURCE/foo/bar/")).value());
353 #endif 354 #endif
354 } 355 }
355 356
356 TEST(FilesystemUtils, GetToolchainDirs) { 357 TEST(FilesystemUtils, GetToolchainDirs) {
357 BuildSettings build_settings; 358 BuildSettings build_settings;
358 build_settings.SetBuildDir(SourceDir("//out/Debug/")); 359 build_settings.SetBuildDir(SourceDir("//out/Debug/"));
359 360
361 // The default toolchain.
360 Settings default_settings(&build_settings, ""); 362 Settings default_settings(&build_settings, "");
363 Label default_toolchain_label(SourceDir("//toolchain/"), "default");
364 default_settings.set_toolchain_label(default_toolchain_label);
365 default_settings.set_default_toolchain_label(default_toolchain_label);
366
367 // Default toolchain out dir.
361 EXPECT_EQ("//out/Debug/", 368 EXPECT_EQ("//out/Debug/",
362 GetToolchainOutputDir(&default_settings).value()); 369 GetToolchainOutputDir(&default_settings).value());
370 EXPECT_EQ("//out/Debug/",
371 GetToolchainOutputDir(&build_settings, default_toolchain_label,
372 true).value());
373
374 // Default toolchain gen dir.
363 EXPECT_EQ("//out/Debug/gen/", 375 EXPECT_EQ("//out/Debug/gen/",
364 GetToolchainGenDir(&default_settings).value()); 376 GetToolchainGenDir(&default_settings).value());
377 EXPECT_EQ("gen/",
378 GetToolchainGenDirAsOutputFile(&default_settings).value());
379 EXPECT_EQ("//out/Debug/gen/",
380 GetToolchainGenDir(&build_settings, default_toolchain_label,
381 true).value());
365 382
383 // Check a secondary toolchain.
366 Settings other_settings(&build_settings, "two/"); 384 Settings other_settings(&build_settings, "two/");
385 Label other_toolchain_label(SourceDir("//toolchain/"), "two");
386 default_settings.set_toolchain_label(other_toolchain_label);
387 default_settings.set_default_toolchain_label(default_toolchain_label);
388
389 // Secondary toolchain out dir.
367 EXPECT_EQ("//out/Debug/two/", 390 EXPECT_EQ("//out/Debug/two/",
368 GetToolchainOutputDir(&other_settings).value()); 391 GetToolchainOutputDir(&other_settings).value());
392 EXPECT_EQ("//out/Debug/two/",
393 GetToolchainOutputDir(&build_settings, other_toolchain_label,
394 false).value());
395
396 // Secondary toolchain gen dir.
369 EXPECT_EQ("//out/Debug/two/gen/", 397 EXPECT_EQ("//out/Debug/two/gen/",
370 GetToolchainGenDir(&other_settings).value()); 398 GetToolchainGenDir(&other_settings).value());
399 EXPECT_EQ("two/gen/",
400 GetToolchainGenDirAsOutputFile(&other_settings).value());
401 EXPECT_EQ("//out/Debug/two/gen/",
402 GetToolchainGenDir(&build_settings, other_toolchain_label,
403 false).value());
371 } 404 }
372 405
373 TEST(FilesystemUtils, GetOutDirForSourceDir) { 406 TEST(FilesystemUtils, GetOutDirForSourceDir) {
374 BuildSettings build_settings; 407 BuildSettings build_settings;
375 build_settings.SetBuildDir(SourceDir("//out/Debug/")); 408 build_settings.SetBuildDir(SourceDir("//out/Debug/"));
376 409
377 // Test the default toolchain. 410 // Test the default toolchain.
378 Settings default_settings(&build_settings, ""); 411 Settings default_settings(&build_settings, "");
379 EXPECT_EQ("//out/Debug/obj/", 412 EXPECT_EQ("//out/Debug/obj/",
380 GetOutputDirForSourceDir(&default_settings, 413 GetOutputDirForSourceDir(
381 SourceDir("//")).value()); 414 &default_settings, SourceDir("//")).value());
415 EXPECT_EQ("obj/",
416 GetOutputDirForSourceDirAsOutputFile(
417 &default_settings, SourceDir("//")).value());
418
382 EXPECT_EQ("//out/Debug/obj/foo/bar/", 419 EXPECT_EQ("//out/Debug/obj/foo/bar/",
383 GetOutputDirForSourceDir(&default_settings, 420 GetOutputDirForSourceDir(
384 SourceDir("//foo/bar/")).value()); 421 &default_settings, SourceDir("//foo/bar/")).value());
422 EXPECT_EQ("obj/foo/bar/",
423 GetOutputDirForSourceDirAsOutputFile(
424 &default_settings, SourceDir("//foo/bar/")).value());
385 425
386 // Secondary toolchain. 426 // Secondary toolchain.
387 Settings other_settings(&build_settings, "two/"); 427 Settings other_settings(&build_settings, "two/");
388 EXPECT_EQ("//out/Debug/two/obj/", 428 EXPECT_EQ("//out/Debug/two/obj/",
389 GetOutputDirForSourceDir(&other_settings, SourceDir("//")).value()); 429 GetOutputDirForSourceDir(
430 &other_settings, SourceDir("//")).value());
431 EXPECT_EQ("two/obj/",
432 GetOutputDirForSourceDirAsOutputFile(
433 &other_settings, SourceDir("//")).value());
434
390 EXPECT_EQ("//out/Debug/two/obj/foo/bar/", 435 EXPECT_EQ("//out/Debug/two/obj/foo/bar/",
391 GetOutputDirForSourceDir(&other_settings, 436 GetOutputDirForSourceDir(&other_settings,
392 SourceDir("//foo/bar/")).value()); 437 SourceDir("//foo/bar/")).value());
438 EXPECT_EQ("two/obj/foo/bar/",
439 GetOutputDirForSourceDirAsOutputFile(
440 &other_settings, SourceDir("//foo/bar/")).value());
393 } 441 }
394 442
395 TEST(FilesystemUtils, GetGenDirForSourceDir) { 443 TEST(FilesystemUtils, GetGenDirForSourceDir) {
396 BuildSettings build_settings; 444 BuildSettings build_settings;
397 build_settings.SetBuildDir(SourceDir("//out/Debug/")); 445 build_settings.SetBuildDir(SourceDir("//out/Debug/"));
398 446
399 // Test the default toolchain. 447 // Test the default toolchain.
400 Settings default_settings(&build_settings, ""); 448 Settings default_settings(&build_settings, "");
401 EXPECT_EQ("//out/Debug/gen/", 449 EXPECT_EQ("//out/Debug/gen/",
402 GetGenDirForSourceDir(&default_settings, SourceDir("//")).value()); 450 GetGenDirForSourceDir(
451 &default_settings, SourceDir("//")).value());
452 EXPECT_EQ("gen/",
453 GetGenDirForSourceDirAsOutputFile(
454 &default_settings, SourceDir("//")).value());
455
403 EXPECT_EQ("//out/Debug/gen/foo/bar/", 456 EXPECT_EQ("//out/Debug/gen/foo/bar/",
404 GetGenDirForSourceDir(&default_settings, 457 GetGenDirForSourceDir(
405 SourceDir("//foo/bar/")).value()); 458 &default_settings, SourceDir("//foo/bar/")).value());
459 EXPECT_EQ("gen/foo/bar/",
460 GetGenDirForSourceDirAsOutputFile(
461 &default_settings, SourceDir("//foo/bar/")).value());
406 462
407 // Secondary toolchain. 463 // Secondary toolchain.
408 Settings other_settings(&build_settings, "two/"); 464 Settings other_settings(&build_settings, "two/");
409 EXPECT_EQ("//out/Debug/two/gen/", 465 EXPECT_EQ("//out/Debug/two/gen/",
410 GetGenDirForSourceDir(&other_settings, SourceDir("//")).value()); 466 GetGenDirForSourceDir(
467 &other_settings, SourceDir("//")).value());
468 EXPECT_EQ("two/gen/",
469 GetGenDirForSourceDirAsOutputFile(
470 &other_settings, SourceDir("//")).value());
471
411 EXPECT_EQ("//out/Debug/two/gen/foo/bar/", 472 EXPECT_EQ("//out/Debug/two/gen/foo/bar/",
412 GetGenDirForSourceDir(&other_settings, 473 GetGenDirForSourceDir(
413 SourceDir("//foo/bar/")).value()); 474 &other_settings, SourceDir("//foo/bar/")).value());
475 EXPECT_EQ("two/gen/foo/bar/",
476 GetGenDirForSourceDirAsOutputFile(
477 &other_settings, SourceDir("//foo/bar/")).value());
478 }
479
480 TEST(FilesystemUtils, GetTargetDirs) {
481 BuildSettings build_settings;
482 build_settings.SetBuildDir(SourceDir("//out/Debug/"));
483 Settings settings(&build_settings, "");
484
485 Target a(&settings, Label(SourceDir("//foo/bar/"), "baz"));
486 EXPECT_EQ("//out/Debug/obj/foo/bar/", GetTargetOutputDir(&a).value());
487 EXPECT_EQ("obj/foo/bar/", GetTargetOutputDirAsOutputFile(&a).value());
488 EXPECT_EQ("//out/Debug/gen/foo/bar/", GetTargetGenDir(&a).value());
489 EXPECT_EQ("gen/foo/bar/", GetTargetGenDirAsOutputFile(&a).value());
414 } 490 }
415 491
416 // Tests handling of output dirs when build dir is the same as the root. 492 // Tests handling of output dirs when build dir is the same as the root.
417 TEST(FilesystemUtils, GetDirForEmptyBuildDir) { 493 TEST(FilesystemUtils, GetDirForEmptyBuildDir) {
418 BuildSettings build_settings; 494 BuildSettings build_settings;
419 build_settings.SetBuildDir(SourceDir("//")); 495 build_settings.SetBuildDir(SourceDir("//"));
420 Settings settings(&build_settings, ""); 496 Settings settings(&build_settings, "");
421 497
422 EXPECT_EQ("//", GetToolchainOutputDir(&settings).value()); 498 EXPECT_EQ("//", GetToolchainOutputDir(&settings).value());
423 EXPECT_EQ("//gen/", GetToolchainGenDir(&settings).value()); 499 EXPECT_EQ("//gen/", GetToolchainGenDir(&settings).value());
500 EXPECT_EQ("gen/", GetToolchainGenDirAsOutputFile(&settings).value());
424 EXPECT_EQ("//obj/", 501 EXPECT_EQ("//obj/",
425 GetOutputDirForSourceDir(&settings, SourceDir("//")).value()); 502 GetOutputDirForSourceDir(&settings, SourceDir("//")).value());
426 EXPECT_EQ("//gen/", 503 EXPECT_EQ("obj/",
427 GetGenDirForSourceDir(&settings, SourceDir("//")).value()); 504 GetOutputDirForSourceDirAsOutputFile(
505 &settings, SourceDir("//")).value());
506 EXPECT_EQ("gen/",
507 GetGenDirForSourceDirAsOutputFile(
508 &settings, SourceDir("//")).value());
428 } 509 }
OLDNEW
« no previous file with comments | « tools/gn/filesystem_utils.cc ('k') | tools/gn/function_get_target_outputs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698