| 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 "tools/gn/substitution_writer.h" | 5 #include "tools/gn/substitution_writer.h" |
| 6 | 6 |
| 7 #include "tools/gn/build_settings.h" | 7 #include "tools/gn/build_settings.h" |
| 8 #include "tools/gn/escape.h" | 8 #include "tools/gn/escape.h" |
| 9 #include "tools/gn/filesystem_utils.h" | 9 #include "tools/gn/filesystem_utils.h" |
| 10 #include "tools/gn/output_file.h" | 10 #include "tools/gn/output_file.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 } | 228 } |
| 229 return result_value; | 229 return result_value; |
| 230 } | 230 } |
| 231 | 231 |
| 232 // static | 232 // static |
| 233 OutputFile SubstitutionWriter::ApplyPatternToSourceAsOutputFile( | 233 OutputFile SubstitutionWriter::ApplyPatternToSourceAsOutputFile( |
| 234 const Settings* settings, | 234 const Settings* settings, |
| 235 const SubstitutionPattern& pattern, | 235 const SubstitutionPattern& pattern, |
| 236 const SourceFile& source) { | 236 const SourceFile& source) { |
| 237 SourceFile result_as_source = ApplyPatternToSource(settings, pattern, source); | 237 SourceFile result_as_source = ApplyPatternToSource(settings, pattern, source); |
| 238 CHECK(result_as_source.is_source_absolute()) | |
| 239 << "The result of the pattern \"" | |
| 240 << pattern.AsString() | |
| 241 << "\" was not an absolute path beginning in \"//\"."; | |
| 242 return OutputFile(settings->build_settings(), result_as_source); | 238 return OutputFile(settings->build_settings(), result_as_source); |
| 243 } | 239 } |
| 244 | 240 |
| 245 // static | 241 // static |
| 246 void SubstitutionWriter::ApplyListToSource( | 242 void SubstitutionWriter::ApplyListToSource( |
| 247 const Settings* settings, | 243 const Settings* settings, |
| 248 const SubstitutionList& list, | 244 const SubstitutionList& list, |
| 249 const SourceFile& source, | 245 const SourceFile& source, |
| 250 std::vector<SourceFile>* output) { | 246 std::vector<SourceFile>* output) { |
| 251 for (const auto& item : list.list()) | 247 for (const auto& item : list.list()) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 case SUBSTITUTION_SOURCE_DIR: | 347 case SUBSTITUTION_SOURCE_DIR: |
| 352 if (source.is_system_absolute()) | 348 if (source.is_system_absolute()) |
| 353 return DirectoryWithNoLastSlash(source.GetDir()); | 349 return DirectoryWithNoLastSlash(source.GetDir()); |
| 354 to_rebase = DirectoryWithNoLastSlash(source.GetDir()); | 350 to_rebase = DirectoryWithNoLastSlash(source.GetDir()); |
| 355 break; | 351 break; |
| 356 | 352 |
| 357 case SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR: | 353 case SUBSTITUTION_SOURCE_ROOT_RELATIVE_DIR: |
| 358 if (source.is_system_absolute()) | 354 if (source.is_system_absolute()) |
| 359 return DirectoryWithNoLastSlash(source.GetDir()); | 355 return DirectoryWithNoLastSlash(source.GetDir()); |
| 360 return RebaseSourceAbsolutePath( | 356 return RebaseSourceAbsolutePath( |
| 361 DirectoryWithNoLastSlash(source.GetDir()), SourceDir("//")); | 357 DirectoryWithNoLastSlash(source.GetDir()), SourceDir("//"), |
| 358 settings->build_settings()->root_path()); |
| 362 | 359 |
| 363 case SUBSTITUTION_SOURCE_GEN_DIR: | 360 case SUBSTITUTION_SOURCE_GEN_DIR: |
| 364 to_rebase = DirectoryWithNoLastSlash( | 361 to_rebase = DirectoryWithNoLastSlash( |
| 365 GetGenDirForSourceDir(settings, source.GetDir())); | 362 GetGenDirForSourceDir(settings, source.GetDir())); |
| 366 break; | 363 break; |
| 367 | 364 |
| 368 case SUBSTITUTION_SOURCE_OUT_DIR: | 365 case SUBSTITUTION_SOURCE_OUT_DIR: |
| 369 to_rebase = DirectoryWithNoLastSlash( | 366 to_rebase = DirectoryWithNoLastSlash( |
| 370 GetOutputDirForSourceDir(settings, source.GetDir())); | 367 GetOutputDirForSourceDir(settings, source.GetDir())); |
| 371 break; | 368 break; |
| 372 | 369 |
| 373 default: | 370 default: |
| 374 NOTREACHED() | 371 NOTREACHED() |
| 375 << "Unsupported substitution for this function: " | 372 << "Unsupported substitution for this function: " |
| 376 << kSubstitutionNames[type]; | 373 << kSubstitutionNames[type]; |
| 377 return std::string(); | 374 return std::string(); |
| 378 } | 375 } |
| 379 | 376 |
| 380 // If we get here, the result is a path that should be made relative or | 377 // If we get here, the result is a path that should be made relative or |
| 381 // absolute according to the output_style. Other cases (just file name or | 378 // absolute according to the output_style. Other cases (just file name or |
| 382 // extension extraction) will have been handled via early return above. | 379 // extension extraction) will have been handled via early return above. |
| 383 if (output_style == OUTPUT_ABSOLUTE) | 380 if (output_style == OUTPUT_ABSOLUTE) |
| 384 return to_rebase; | 381 return to_rebase; |
| 385 return RebaseSourceAbsolutePath(to_rebase, relative_to); | 382 return RebaseSourceAbsolutePath(to_rebase, relative_to, |
| 383 settings->build_settings()->root_path()); |
| 386 } | 384 } |
| 387 | 385 |
| 388 // static | 386 // static |
| 389 OutputFile SubstitutionWriter::ApplyPatternToTargetAsOutputFile( | 387 OutputFile SubstitutionWriter::ApplyPatternToTargetAsOutputFile( |
| 390 const Target* target, | 388 const Target* target, |
| 391 const Tool* tool, | 389 const Tool* tool, |
| 392 const SubstitutionPattern& pattern) { | 390 const SubstitutionPattern& pattern) { |
| 393 std::string result_value; | 391 std::string result_value; |
| 394 for (const auto& subrange : pattern.ranges()) { | 392 for (const auto& subrange : pattern.ranges()) { |
| 395 if (subrange.type == SUBSTITUTION_LITERAL) { | 393 if (subrange.type == SUBSTITUTION_LITERAL) { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 // does not include the dot but the tool's does. | 547 // does not include the dot but the tool's does. |
| 550 if (target->output_extension().empty()) | 548 if (target->output_extension().empty()) |
| 551 return tool->default_output_extension(); | 549 return tool->default_output_extension(); |
| 552 return std::string(".") + target->output_extension(); | 550 return std::string(".") + target->output_extension(); |
| 553 | 551 |
| 554 default: | 552 default: |
| 555 NOTREACHED(); | 553 NOTREACHED(); |
| 556 return std::string(); | 554 return std::string(); |
| 557 } | 555 } |
| 558 } | 556 } |
| OLD | NEW |