| OLD | NEW |
| 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/err.h" | 8 #include "tools/gn/err.h" |
| 9 #include "tools/gn/escape.h" | 9 #include "tools/gn/escape.h" |
| 10 #include "tools/gn/substitution_list.h" | 10 #include "tools/gn/substitution_list.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 166 |
| 167 EXPECT_EQ(".", | 167 EXPECT_EQ(".", |
| 168 GetRelSubst("//baz.txt", SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR)); | 168 GetRelSubst("//baz.txt", SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR)); |
| 169 | 169 |
| 170 #undef GetAbsSubst | 170 #undef GetAbsSubst |
| 171 #undef GetRelSubst | 171 #undef GetRelSubst |
| 172 } | 172 } |
| 173 | 173 |
| 174 TEST(SubstitutionWriter, TargetSubstitutions) { | 174 TEST(SubstitutionWriter, TargetSubstitutions) { |
| 175 TestWithScope setup; | 175 TestWithScope setup; |
| 176 Err err; |
| 176 | 177 |
| 177 Target target(setup.settings(), Label(SourceDir("//foo/bar/"), "baz")); | 178 Target target(setup.settings(), Label(SourceDir("//foo/bar/"), "baz")); |
| 178 target.set_output_type(Target::STATIC_LIBRARY); | 179 target.set_output_type(Target::STATIC_LIBRARY); |
| 179 target.SetToolchain(setup.toolchain()); | 180 target.SetToolchain(setup.toolchain()); |
| 180 target.OnResolved(); | 181 ASSERT_TRUE(target.OnResolved(&err)); |
| 181 | 182 |
| 182 std::string result; | 183 std::string result; |
| 183 EXPECT_TRUE(SubstitutionWriter::GetTargetSubstitution( | 184 EXPECT_TRUE(SubstitutionWriter::GetTargetSubstitution( |
| 184 &target, SUBSTITUTION_LABEL, &result)); | 185 &target, SUBSTITUTION_LABEL, &result)); |
| 185 EXPECT_EQ("//foo/bar:baz", result); | 186 EXPECT_EQ("//foo/bar:baz", result); |
| 186 | 187 |
| 187 EXPECT_TRUE(SubstitutionWriter::GetTargetSubstitution( | 188 EXPECT_TRUE(SubstitutionWriter::GetTargetSubstitution( |
| 188 &target, SUBSTITUTION_ROOT_GEN_DIR, &result)); | 189 &target, SUBSTITUTION_ROOT_GEN_DIR, &result)); |
| 189 EXPECT_EQ("gen", result); | 190 EXPECT_EQ("gen", result); |
| 190 | 191 |
| 191 EXPECT_TRUE(SubstitutionWriter::GetTargetSubstitution( | 192 EXPECT_TRUE(SubstitutionWriter::GetTargetSubstitution( |
| 192 &target, SUBSTITUTION_ROOT_OUT_DIR, &result)); | 193 &target, SUBSTITUTION_ROOT_OUT_DIR, &result)); |
| 193 EXPECT_EQ(".", result); | 194 EXPECT_EQ(".", result); |
| 194 | 195 |
| 195 EXPECT_TRUE(SubstitutionWriter::GetTargetSubstitution( | 196 EXPECT_TRUE(SubstitutionWriter::GetTargetSubstitution( |
| 196 &target, SUBSTITUTION_TARGET_GEN_DIR, &result)); | 197 &target, SUBSTITUTION_TARGET_GEN_DIR, &result)); |
| 197 EXPECT_EQ("gen/foo/bar", result); | 198 EXPECT_EQ("gen/foo/bar", result); |
| 198 | 199 |
| 199 EXPECT_TRUE(SubstitutionWriter::GetTargetSubstitution( | 200 EXPECT_TRUE(SubstitutionWriter::GetTargetSubstitution( |
| 200 &target, SUBSTITUTION_TARGET_OUT_DIR, &result)); | 201 &target, SUBSTITUTION_TARGET_OUT_DIR, &result)); |
| 201 EXPECT_EQ("obj/foo/bar", result); | 202 EXPECT_EQ("obj/foo/bar", result); |
| 202 | 203 |
| 203 EXPECT_TRUE(SubstitutionWriter::GetTargetSubstitution( | 204 EXPECT_TRUE(SubstitutionWriter::GetTargetSubstitution( |
| 204 &target, SUBSTITUTION_TARGET_OUTPUT_NAME, &result)); | 205 &target, SUBSTITUTION_TARGET_OUTPUT_NAME, &result)); |
| 205 EXPECT_EQ("libbaz", result); | 206 EXPECT_EQ("libbaz", result); |
| 206 } | 207 } |
| 207 | 208 |
| 208 TEST(SubstitutionWriter, CompilerSubstitutions) { | 209 TEST(SubstitutionWriter, CompilerSubstitutions) { |
| 209 TestWithScope setup; | 210 TestWithScope setup; |
| 211 Err err; |
| 210 | 212 |
| 211 Target target(setup.settings(), Label(SourceDir("//foo/bar/"), "baz")); | 213 Target target(setup.settings(), Label(SourceDir("//foo/bar/"), "baz")); |
| 212 target.set_output_type(Target::STATIC_LIBRARY); | 214 target.set_output_type(Target::STATIC_LIBRARY); |
| 213 target.SetToolchain(setup.toolchain()); | 215 target.SetToolchain(setup.toolchain()); |
| 214 target.OnResolved(); | 216 ASSERT_TRUE(target.OnResolved(&err)); |
| 215 | 217 |
| 216 // The compiler substitution is just source + target combined. So test one | 218 // The compiler substitution is just source + target combined. So test one |
| 217 // of each of those classes of things to make sure this is hooked up. | 219 // of each of those classes of things to make sure this is hooked up. |
| 218 EXPECT_EQ("file", | 220 EXPECT_EQ("file", |
| 219 SubstitutionWriter::GetCompilerSubstitution( | 221 SubstitutionWriter::GetCompilerSubstitution( |
| 220 &target, SourceFile("//foo/bar/file.txt"), | 222 &target, SourceFile("//foo/bar/file.txt"), |
| 221 SUBSTITUTION_SOURCE_NAME_PART)); | 223 SUBSTITUTION_SOURCE_NAME_PART)); |
| 222 EXPECT_EQ("gen/foo/bar", | 224 EXPECT_EQ("gen/foo/bar", |
| 223 SubstitutionWriter::GetCompilerSubstitution( | 225 SubstitutionWriter::GetCompilerSubstitution( |
| 224 &target, SourceFile("//foo/bar/file.txt"), | 226 &target, SourceFile("//foo/bar/file.txt"), |
| 225 SUBSTITUTION_TARGET_GEN_DIR)); | 227 SUBSTITUTION_TARGET_GEN_DIR)); |
| 226 } | 228 } |
| 227 | 229 |
| 228 TEST(SubstitutionWriter, LinkerSubstitutions) { | 230 TEST(SubstitutionWriter, LinkerSubstitutions) { |
| 229 TestWithScope setup; | 231 TestWithScope setup; |
| 232 Err err; |
| 230 | 233 |
| 231 Target target(setup.settings(), Label(SourceDir("//foo/bar/"), "baz")); | 234 Target target(setup.settings(), Label(SourceDir("//foo/bar/"), "baz")); |
| 232 target.set_output_type(Target::SHARED_LIBRARY); | 235 target.set_output_type(Target::SHARED_LIBRARY); |
| 233 target.SetToolchain(setup.toolchain()); | 236 target.SetToolchain(setup.toolchain()); |
| 234 target.OnResolved(); | 237 ASSERT_TRUE(target.OnResolved(&err)); |
| 235 | 238 |
| 236 const Tool* tool = setup.toolchain()->GetToolForTargetFinalOutput(&target); | 239 const Tool* tool = setup.toolchain()->GetToolForTargetFinalOutput(&target); |
| 237 | 240 |
| 238 // The compiler substitution is just target + OUTPUT_EXTENSION combined. So | 241 // The compiler substitution is just target + OUTPUT_EXTENSION combined. So |
| 239 // test one target one plus the output extension. | 242 // test one target one plus the output extension. |
| 240 EXPECT_EQ(".so", | 243 EXPECT_EQ(".so", |
| 241 SubstitutionWriter::GetLinkerSubstitution( | 244 SubstitutionWriter::GetLinkerSubstitution( |
| 242 &target, tool, SUBSTITUTION_OUTPUT_EXTENSION)); | 245 &target, tool, SUBSTITUTION_OUTPUT_EXTENSION)); |
| 243 EXPECT_EQ("gen/foo/bar", | 246 EXPECT_EQ("gen/foo/bar", |
| 244 SubstitutionWriter::GetLinkerSubstitution( | 247 SubstitutionWriter::GetLinkerSubstitution( |
| 245 &target, tool, SUBSTITUTION_TARGET_GEN_DIR)); | 248 &target, tool, SUBSTITUTION_TARGET_GEN_DIR)); |
| 246 | 249 |
| 247 // Test that we handle paths that end up in the root build dir properly | 250 // Test that we handle paths that end up in the root build dir properly |
| 248 // (no leading "./" or "/"). | 251 // (no leading "./" or "/"). |
| 249 Err err; | |
| 250 SubstitutionPattern pattern; | 252 SubstitutionPattern pattern; |
| 251 ASSERT_TRUE( | 253 ASSERT_TRUE( |
| 252 pattern.Parse("{{root_out_dir}}/{{target_output_name}}.so", NULL, &err)); | 254 pattern.Parse("{{root_out_dir}}/{{target_output_name}}.so", NULL, &err)); |
| 253 | 255 |
| 254 OutputFile output = SubstitutionWriter::ApplyPatternToLinkerAsOutputFile( | 256 OutputFile output = SubstitutionWriter::ApplyPatternToLinkerAsOutputFile( |
| 255 &target, tool, pattern); | 257 &target, tool, pattern); |
| 256 EXPECT_EQ("./libbaz.so", output.value()); | 258 EXPECT_EQ("./libbaz.so", output.value()); |
| 257 } | 259 } |
| OLD | NEW |