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 "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/err.h" | 9 #include "tools/gn/err.h" |
10 #include "tools/gn/escape.h" | 10 #include "tools/gn/escape.h" |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 | 271 |
272 // Output extensions can be overridden. | 272 // Output extensions can be overridden. |
273 target.set_output_extension("extension"); | 273 target.set_output_extension("extension"); |
274 EXPECT_EQ(".extension", | 274 EXPECT_EQ(".extension", |
275 SubstitutionWriter::GetLinkerSubstitution( | 275 SubstitutionWriter::GetLinkerSubstitution( |
276 &target, tool, SUBSTITUTION_OUTPUT_EXTENSION)); | 276 &target, tool, SUBSTITUTION_OUTPUT_EXTENSION)); |
277 target.set_output_extension(""); | 277 target.set_output_extension(""); |
278 EXPECT_EQ("", | 278 EXPECT_EQ("", |
279 SubstitutionWriter::GetLinkerSubstitution( | 279 SubstitutionWriter::GetLinkerSubstitution( |
280 &target, tool, SUBSTITUTION_OUTPUT_EXTENSION)); | 280 &target, tool, SUBSTITUTION_OUTPUT_EXTENSION)); |
| 281 |
| 282 // Output directory is tested in a separate test below. |
281 } | 283 } |
| 284 |
| 285 TEST(SubstitutionWriter, OutputDir) { |
| 286 TestWithScope setup; |
| 287 Err err; |
| 288 |
| 289 // This tool has an output directory pattern and uses that for the |
| 290 // output name. |
| 291 Tool tool; |
| 292 SubstitutionPattern out_dir_pattern; |
| 293 ASSERT_TRUE(out_dir_pattern.Parse("{{root_out_dir}}/{{target_output_name}}", |
| 294 nullptr, &err)); |
| 295 tool.set_default_output_dir(out_dir_pattern); |
| 296 tool.SetComplete(); |
| 297 |
| 298 // Default target with no output dir overrides. |
| 299 Target target(setup.settings(), Label(SourceDir("//foo/"), "baz")); |
| 300 target.set_output_type(Target::EXECUTABLE); |
| 301 target.SetToolchain(setup.toolchain()); |
| 302 ASSERT_TRUE(target.OnResolved(&err)); |
| 303 |
| 304 // The output should expand the default from the patterns in the tool. |
| 305 SubstitutionPattern output_name; |
| 306 ASSERT_TRUE(output_name.Parse("{{output_dir}}/{{target_output_name}}.exe", |
| 307 nullptr, &err)); |
| 308 EXPECT_EQ("./baz/baz.exe", |
| 309 SubstitutionWriter::ApplyPatternToLinkerAsOutputFile( |
| 310 &target, &tool, output_name).value()); |
| 311 |
| 312 // Override the output name to the root build dir. |
| 313 target.set_output_dir(SourceDir("//out/Debug/")); |
| 314 EXPECT_EQ("./baz.exe", |
| 315 SubstitutionWriter::ApplyPatternToLinkerAsOutputFile( |
| 316 &target, &tool, output_name).value()); |
| 317 |
| 318 // Override the output name to a new subdirectory. |
| 319 target.set_output_dir(SourceDir("//out/Debug/foo/bar")); |
| 320 EXPECT_EQ("foo/bar/baz.exe", |
| 321 SubstitutionWriter::ApplyPatternToLinkerAsOutputFile( |
| 322 &target, &tool, output_name).value()); |
| 323 } |
OLD | NEW |