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/config_values_extractors_unittest.cc

Issue 2940873002: Implement tracking of BUILD.gn files used to define target, toolchain or (Closed)
Patch Set: Fix compilation after rebase. Created 3 years, 5 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/config_unittest.cc ('k') | tools/gn/filesystem_utils_unittest.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <sstream> 5 #include <sstream>
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "tools/gn/config.h" 8 #include "tools/gn/config.h"
9 #include "tools/gn/config_values_extractors.h" 9 #include "tools/gn/config_values_extractors.h"
10 #include "tools/gn/target.h" 10 #include "tools/gn/target.h"
(...skipping 17 matching lines...) Expand all
28 28
29 TEST(ConfigValuesExtractors, IncludeOrdering) { 29 TEST(ConfigValuesExtractors, IncludeOrdering) {
30 TestWithScope setup; 30 TestWithScope setup;
31 Err err; 31 Err err;
32 32
33 // Construct a chain of dependencies: target -> dep1 -> dep2 33 // Construct a chain of dependencies: target -> dep1 -> dep2
34 // Add representative values: cflags (opaque, always copied) and include_dirs 34 // Add representative values: cflags (opaque, always copied) and include_dirs
35 // (uniquified) to each one so we can check what comes out the other end. 35 // (uniquified) to each one so we can check what comes out the other end.
36 36
37 // Set up dep2, direct and all dependent configs. 37 // Set up dep2, direct and all dependent configs.
38 Config dep2_all(setup.settings(), Label(SourceDir("//dep2/"), "all")); 38 Config dep2_all(setup.settings(), Label(SourceDir("//dep2/"), "all"), {});
39 dep2_all.own_values().cflags().push_back("--dep2-all"); 39 dep2_all.own_values().cflags().push_back("--dep2-all");
40 dep2_all.own_values().include_dirs().push_back(SourceDir("//dep2/all/")); 40 dep2_all.own_values().include_dirs().push_back(SourceDir("//dep2/all/"));
41 ASSERT_TRUE(dep2_all.OnResolved(&err)); 41 ASSERT_TRUE(dep2_all.OnResolved(&err));
42 42
43 Config dep2_direct(setup.settings(), Label(SourceDir("//dep2/"), "direct")); 43 Config dep2_direct(setup.settings(), Label(SourceDir("//dep2/"), "direct"),
44 {});
44 dep2_direct.own_values().cflags().push_back("--dep2-direct"); 45 dep2_direct.own_values().cflags().push_back("--dep2-direct");
45 dep2_direct.own_values().include_dirs().push_back( 46 dep2_direct.own_values().include_dirs().push_back(
46 SourceDir("//dep2/direct/")); 47 SourceDir("//dep2/direct/"));
47 ASSERT_TRUE(dep2_direct.OnResolved(&err)); 48 ASSERT_TRUE(dep2_direct.OnResolved(&err));
48 49
49 Target dep2(setup.settings(), Label(SourceDir("//dep2/"), "dep2")); 50 Target dep2(setup.settings(), Label(SourceDir("//dep2/"), "dep2"), {});
50 dep2.set_output_type(Target::SOURCE_SET); 51 dep2.set_output_type(Target::SOURCE_SET);
51 dep2.visibility().SetPublic(); 52 dep2.visibility().SetPublic();
52 dep2.SetToolchain(setup.toolchain()); 53 dep2.SetToolchain(setup.toolchain());
53 dep2.all_dependent_configs().push_back(LabelConfigPair(&dep2_all)); 54 dep2.all_dependent_configs().push_back(LabelConfigPair(&dep2_all));
54 dep2.public_configs().push_back(LabelConfigPair(&dep2_direct)); 55 dep2.public_configs().push_back(LabelConfigPair(&dep2_direct));
55 56
56 // Set up dep1, direct and all dependent configs. Also set up a subconfig 57 // Set up dep1, direct and all dependent configs. Also set up a subconfig
57 // on "dep1_all" to test sub configs. 58 // on "dep1_all" to test sub configs.
58 Config dep1_all_sub(setup.settings(), Label(SourceDir("//dep1"), "allch")); 59 Config dep1_all_sub(setup.settings(), Label(SourceDir("//dep1"), "allch"),
60 {});
59 dep1_all_sub.own_values().cflags().push_back("--dep1-all-sub"); 61 dep1_all_sub.own_values().cflags().push_back("--dep1-all-sub");
60 ASSERT_TRUE(dep1_all_sub.OnResolved(&err)); 62 ASSERT_TRUE(dep1_all_sub.OnResolved(&err));
61 63
62 Config dep1_all(setup.settings(), Label(SourceDir("//dep1/"), "all")); 64 Config dep1_all(setup.settings(), Label(SourceDir("//dep1/"), "all"), {});
63 dep1_all.own_values().cflags().push_back("--dep1-all"); 65 dep1_all.own_values().cflags().push_back("--dep1-all");
64 dep1_all.own_values().include_dirs().push_back(SourceDir("//dep1/all/")); 66 dep1_all.own_values().include_dirs().push_back(SourceDir("//dep1/all/"));
65 dep1_all.configs().push_back(LabelConfigPair(&dep1_all_sub)); 67 dep1_all.configs().push_back(LabelConfigPair(&dep1_all_sub));
66 ASSERT_TRUE(dep1_all.OnResolved(&err)); 68 ASSERT_TRUE(dep1_all.OnResolved(&err));
67 69
68 Config dep1_direct(setup.settings(), Label(SourceDir("//dep1/"), "direct")); 70 Config dep1_direct(setup.settings(), Label(SourceDir("//dep1/"), "direct"),
71 {});
69 dep1_direct.own_values().cflags().push_back("--dep1-direct"); 72 dep1_direct.own_values().cflags().push_back("--dep1-direct");
70 dep1_direct.own_values().include_dirs().push_back( 73 dep1_direct.own_values().include_dirs().push_back(
71 SourceDir("//dep1/direct/")); 74 SourceDir("//dep1/direct/"));
72 ASSERT_TRUE(dep1_direct.OnResolved(&err)); 75 ASSERT_TRUE(dep1_direct.OnResolved(&err));
73 76
74 Target dep1(setup.settings(), Label(SourceDir("//dep1/"), "dep1")); 77 Target dep1(setup.settings(), Label(SourceDir("//dep1/"), "dep1"), {});
75 dep1.set_output_type(Target::SOURCE_SET); 78 dep1.set_output_type(Target::SOURCE_SET);
76 dep1.visibility().SetPublic(); 79 dep1.visibility().SetPublic();
77 dep1.SetToolchain(setup.toolchain()); 80 dep1.SetToolchain(setup.toolchain());
78 dep1.all_dependent_configs().push_back(LabelConfigPair(&dep1_all)); 81 dep1.all_dependent_configs().push_back(LabelConfigPair(&dep1_all));
79 dep1.public_configs().push_back(LabelConfigPair(&dep1_direct)); 82 dep1.public_configs().push_back(LabelConfigPair(&dep1_direct));
80 dep1.private_deps().push_back(LabelTargetPair(&dep2)); 83 dep1.private_deps().push_back(LabelTargetPair(&dep2));
81 84
82 // Set up target, direct and all dependent configs. 85 // Set up target, direct and all dependent configs.
83 Config target_all(setup.settings(), Label(SourceDir("//target/"), "all")); 86 Config target_all(setup.settings(), Label(SourceDir("//target/"), "all"), {});
84 target_all.own_values().cflags().push_back("--target-all"); 87 target_all.own_values().cflags().push_back("--target-all");
85 target_all.own_values().include_dirs().push_back(SourceDir("//target/all/")); 88 target_all.own_values().include_dirs().push_back(SourceDir("//target/all/"));
86 ASSERT_TRUE(target_all.OnResolved(&err)); 89 ASSERT_TRUE(target_all.OnResolved(&err));
87 90
88 Config target_direct(setup.settings(), 91 Config target_direct(setup.settings(),
89 Label(SourceDir("//target/"), "direct")); 92 Label(SourceDir("//target/"), "direct"), {});
90 target_direct.own_values().cflags().push_back("--target-direct"); 93 target_direct.own_values().cflags().push_back("--target-direct");
91 target_direct.own_values().include_dirs().push_back( 94 target_direct.own_values().include_dirs().push_back(
92 SourceDir("//target/direct/")); 95 SourceDir("//target/direct/"));
93 ASSERT_TRUE(target_direct.OnResolved(&err)); 96 ASSERT_TRUE(target_direct.OnResolved(&err));
94 97
95 // This config is applied directly to target. 98 // This config is applied directly to target.
96 Config target_config(setup.settings(), 99 Config target_config(setup.settings(),
97 Label(SourceDir("//target/"), "config")); 100 Label(SourceDir("//target/"), "config"), {});
98 target_config.own_values().cflags().push_back("--target-config"); 101 target_config.own_values().cflags().push_back("--target-config");
99 target_config.own_values().include_dirs().push_back( 102 target_config.own_values().include_dirs().push_back(
100 SourceDir("//target/config/")); 103 SourceDir("//target/config/"));
101 ASSERT_TRUE(target_config.OnResolved(&err)); 104 ASSERT_TRUE(target_config.OnResolved(&err));
102 105
103 Target target(setup.settings(), Label(SourceDir("//target/"), "target")); 106 Target target(setup.settings(), Label(SourceDir("//target/"), "target"), {});
104 target.set_output_type(Target::SOURCE_SET); 107 target.set_output_type(Target::SOURCE_SET);
105 target.SetToolchain(setup.toolchain()); 108 target.SetToolchain(setup.toolchain());
106 target.all_dependent_configs().push_back(LabelConfigPair(&target_all)); 109 target.all_dependent_configs().push_back(LabelConfigPair(&target_all));
107 target.public_configs().push_back(LabelConfigPair(&target_direct)); 110 target.public_configs().push_back(LabelConfigPair(&target_direct));
108 target.configs().push_back(LabelConfigPair(&target_config)); 111 target.configs().push_back(LabelConfigPair(&target_config));
109 target.private_deps().push_back(LabelTargetPair(&dep1)); 112 target.private_deps().push_back(LabelTargetPair(&dep1));
110 113
111 // Additionally add some values directly on "target". 114 // Additionally add some values directly on "target".
112 target.config_values().cflags().push_back("--target"); 115 target.config_values().cflags().push_back("--target");
113 target.config_values().include_dirs().push_back( 116 target.config_values().include_dirs().push_back(
(...skipping 15 matching lines...) Expand all
129 132
130 // Verify include dirs by serializing. 133 // Verify include dirs by serializing.
131 std::ostringstream include_out; 134 std::ostringstream include_out;
132 IncludeWriter include_writer; 135 IncludeWriter include_writer;
133 RecursiveTargetConfigToStream<SourceDir, IncludeWriter>( 136 RecursiveTargetConfigToStream<SourceDir, IncludeWriter>(
134 &target, &ConfigValues::include_dirs, include_writer, include_out); 137 &target, &ConfigValues::include_dirs, include_writer, include_out);
135 EXPECT_EQ(include_out.str(), 138 EXPECT_EQ(include_out.str(),
136 "//target/ //target/config/ //target/all/ //target/direct/ " 139 "//target/ //target/config/ //target/all/ //target/direct/ "
137 "//dep1/all/ //dep2/all/ //dep1/direct/ "); 140 "//dep1/all/ //dep2/all/ //dep1/direct/ ");
138 } 141 }
OLDNEW
« no previous file with comments | « tools/gn/config_unittest.cc ('k') | tools/gn/filesystem_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698