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

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

Issue 1342183003: Allow GN configs to have sub-configs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « tools/gn/target.cc ('k') | tools/gn/variables.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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/build_settings.h" 6 #include "tools/gn/build_settings.h"
7 #include "tools/gn/config.h" 7 #include "tools/gn/config.h"
8 #include "tools/gn/scheduler.h" 8 #include "tools/gn/scheduler.h"
9 #include "tools/gn/settings.h" 9 #include "tools/gn/settings.h"
10 #include "tools/gn/target.h" 10 #include "tools/gn/target.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 // Set up a dependency chain of a -> b -> c 84 // Set up a dependency chain of a -> b -> c
85 TestTarget a(setup, "//foo:a", Target::EXECUTABLE); 85 TestTarget a(setup, "//foo:a", Target::EXECUTABLE);
86 TestTarget b(setup, "//foo:b", Target::STATIC_LIBRARY); 86 TestTarget b(setup, "//foo:b", Target::STATIC_LIBRARY);
87 TestTarget c(setup, "//foo:c", Target::STATIC_LIBRARY); 87 TestTarget c(setup, "//foo:c", Target::STATIC_LIBRARY);
88 a.private_deps().push_back(LabelTargetPair(&b)); 88 a.private_deps().push_back(LabelTargetPair(&b));
89 b.private_deps().push_back(LabelTargetPair(&c)); 89 b.private_deps().push_back(LabelTargetPair(&c));
90 90
91 // Normal non-inherited config. 91 // Normal non-inherited config.
92 Config config(setup.settings(), Label(SourceDir("//foo/"), "config")); 92 Config config(setup.settings(), Label(SourceDir("//foo/"), "config"));
93 ASSERT_TRUE(config.OnResolved(&err));
93 c.configs().push_back(LabelConfigPair(&config)); 94 c.configs().push_back(LabelConfigPair(&config));
94 95
95 // All dependent config. 96 // All dependent config.
96 Config all(setup.settings(), Label(SourceDir("//foo/"), "all")); 97 Config all(setup.settings(), Label(SourceDir("//foo/"), "all"));
98 ASSERT_TRUE(all.OnResolved(&err));
97 c.all_dependent_configs().push_back(LabelConfigPair(&all)); 99 c.all_dependent_configs().push_back(LabelConfigPair(&all));
98 100
99 // Direct dependent config. 101 // Direct dependent config.
100 Config direct(setup.settings(), Label(SourceDir("//foo/"), "direct")); 102 Config direct(setup.settings(), Label(SourceDir("//foo/"), "direct"));
103 ASSERT_TRUE(direct.OnResolved(&err));
101 c.public_configs().push_back(LabelConfigPair(&direct)); 104 c.public_configs().push_back(LabelConfigPair(&direct));
102 105
103 ASSERT_TRUE(c.OnResolved(&err)); 106 ASSERT_TRUE(c.OnResolved(&err));
104 ASSERT_TRUE(b.OnResolved(&err)); 107 ASSERT_TRUE(b.OnResolved(&err));
105 ASSERT_TRUE(a.OnResolved(&err)); 108 ASSERT_TRUE(a.OnResolved(&err));
106 109
107 // B should have gotten both dependent configs from C. 110 // B should have gotten both dependent configs from C.
108 ASSERT_EQ(2u, b.configs().size()); 111 ASSERT_EQ(2u, b.configs().size());
109 EXPECT_EQ(&all, b.configs()[0].ptr); 112 EXPECT_EQ(&all, b.configs()[0].ptr);
110 EXPECT_EQ(&direct, b.configs()[1].ptr); 113 EXPECT_EQ(&direct, b.configs()[1].ptr);
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 product.private_deps().push_back(LabelTargetPair(&testlib)); 357 product.private_deps().push_back(LabelTargetPair(&testlib));
355 ASSERT_FALSE(product.OnResolved(&err)); 358 ASSERT_FALSE(product.OnResolved(&err));
356 } 359 }
357 360
358 TEST(Target, PublicConfigs) { 361 TEST(Target, PublicConfigs) {
359 TestWithScope setup; 362 TestWithScope setup;
360 Err err; 363 Err err;
361 364
362 Label pub_config_label(SourceDir("//a/"), "pubconfig"); 365 Label pub_config_label(SourceDir("//a/"), "pubconfig");
363 Config pub_config(setup.settings(), pub_config_label); 366 Config pub_config(setup.settings(), pub_config_label);
367 ASSERT_TRUE(pub_config.OnResolved(&err));
364 368
365 // This is the destination target that has a public config. 369 // This is the destination target that has a public config.
366 TestTarget dest(setup, "//a:a", Target::SOURCE_SET); 370 TestTarget dest(setup, "//a:a", Target::SOURCE_SET);
367 dest.public_configs().push_back(LabelConfigPair(&pub_config)); 371 dest.public_configs().push_back(LabelConfigPair(&pub_config));
368 ASSERT_TRUE(dest.OnResolved(&err)); 372 ASSERT_TRUE(dest.OnResolved(&err));
369 373
370 // This target has a public dependency on dest. 374 // This target has a public dependency on dest.
371 TestTarget pub(setup, "//a:pub", Target::SOURCE_SET); 375 TestTarget pub(setup, "//a:pub", Target::SOURCE_SET);
372 pub.public_deps().push_back(LabelTargetPair(&dest)); 376 pub.public_deps().push_back(LabelTargetPair(&dest));
373 ASSERT_TRUE(pub.OnResolved(&err)); 377 ASSERT_TRUE(pub.OnResolved(&err));
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 569
566 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); 570 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
567 571
568 // Target with no settings, no configs, should be a no-op. 572 // Target with no settings, no configs, should be a no-op.
569 EXPECT_TRUE(target.ResolvePrecompiledHeaders(&err)); 573 EXPECT_TRUE(target.ResolvePrecompiledHeaders(&err));
570 574
571 // Config with PCH values. 575 // Config with PCH values.
572 Config config_1(setup.settings(), Label(SourceDir("//foo/"), "c1")); 576 Config config_1(setup.settings(), Label(SourceDir("//foo/"), "c1"));
573 std::string pch_1("pch.h"); 577 std::string pch_1("pch.h");
574 SourceFile pcs_1("//pcs.cc"); 578 SourceFile pcs_1("//pcs.cc");
575 config_1.config_values().set_precompiled_header(pch_1); 579 config_1.own_values().set_precompiled_header(pch_1);
576 config_1.config_values().set_precompiled_source(pcs_1); 580 config_1.own_values().set_precompiled_source(pcs_1);
581 ASSERT_TRUE(config_1.OnResolved(&err));
577 target.configs().push_back(LabelConfigPair(&config_1)); 582 target.configs().push_back(LabelConfigPair(&config_1));
578 583
579 // No PCH info specified on target, but the config specifies one, the 584 // No PCH info specified on target, but the config specifies one, the
580 // values should get copied to the target. 585 // values should get copied to the target.
581 EXPECT_TRUE(target.ResolvePrecompiledHeaders(&err)); 586 EXPECT_TRUE(target.ResolvePrecompiledHeaders(&err));
582 EXPECT_EQ(pch_1, target.config_values().precompiled_header()); 587 EXPECT_EQ(pch_1, target.config_values().precompiled_header());
583 EXPECT_TRUE(target.config_values().precompiled_source() == pcs_1); 588 EXPECT_TRUE(target.config_values().precompiled_source() == pcs_1);
584 589
585 // Now both target and config have matching PCH values. Resolving again 590 // Now both target and config have matching PCH values. Resolving again
586 // should be a no-op since they all match. 591 // should be a no-op since they all match.
587 EXPECT_TRUE(target.ResolvePrecompiledHeaders(&err)); 592 EXPECT_TRUE(target.ResolvePrecompiledHeaders(&err));
588 EXPECT_TRUE(target.config_values().precompiled_header() == pch_1); 593 EXPECT_TRUE(target.config_values().precompiled_header() == pch_1);
589 EXPECT_TRUE(target.config_values().precompiled_source() == pcs_1); 594 EXPECT_TRUE(target.config_values().precompiled_source() == pcs_1);
590 595
591 // Second config with different PCH values. 596 // Second config with different PCH values.
592 Config config_2(setup.settings(), Label(SourceDir("//foo/"), "c2")); 597 Config config_2(setup.settings(), Label(SourceDir("//foo/"), "c2"));
593 std::string pch_2("pch2.h"); 598 std::string pch_2("pch2.h");
594 SourceFile pcs_2("//pcs2.cc"); 599 SourceFile pcs_2("//pcs2.cc");
595 config_2.config_values().set_precompiled_header(pch_2); 600 config_2.own_values().set_precompiled_header(pch_2);
596 config_2.config_values().set_precompiled_source(pcs_2); 601 config_2.own_values().set_precompiled_source(pcs_2);
602 ASSERT_TRUE(config_2.OnResolved(&err));
597 target.configs().push_back(LabelConfigPair(&config_2)); 603 target.configs().push_back(LabelConfigPair(&config_2));
598 604
599 // This should be an error since they don't match. 605 // This should be an error since they don't match.
600 EXPECT_FALSE(target.ResolvePrecompiledHeaders(&err)); 606 EXPECT_FALSE(target.ResolvePrecompiledHeaders(&err));
601 607
602 // Make sure the proper labels are blamed. 608 // Make sure the proper labels are blamed.
603 EXPECT_EQ( 609 EXPECT_EQ(
604 "The target //foo:bar\n" 610 "The target //foo:bar\n"
605 "has conflicting precompiled header settings.\n" 611 "has conflicting precompiled header settings.\n"
606 "\n" 612 "\n"
607 "From //foo:bar\n" 613 "From //foo:bar\n"
608 " header: pch.h\n" 614 " header: pch.h\n"
609 " source: //pcs.cc\n" 615 " source: //pcs.cc\n"
610 "\n" 616 "\n"
611 "From //foo:c2\n" 617 "From //foo:c2\n"
612 " header: pch2.h\n" 618 " header: pch2.h\n"
613 " source: //pcs2.cc", 619 " source: //pcs2.cc",
614 err.help_text()); 620 err.help_text());
615 } 621 }
OLDNEW
« no previous file with comments | « tools/gn/target.cc ('k') | tools/gn/variables.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698