mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This introduces a new substitution for use in the CAS tests. The plain variant of the target frontend invokes the tool with the variant target triple and resource dir only. This allows us to properly invoke the frontend for the CAS tests.
67 lines
2.9 KiB
Swift
67 lines
2.9 KiB
Swift
// REQUIRES: swift_swift_parser
|
|
|
|
// RUN: %empty-directory(%t)
|
|
// RUN: split-file %s %t
|
|
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %t/macro.swift
|
|
|
|
// RUN: %target-swift-frontend -typecheck -module-load-mode prefer-serialized -module-name MyApp -module-cache-path %t/clang-module-cache -O \
|
|
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
|
|
// RUN: %t/main.swift -swift-version 5 -external-plugin-path %t#%swift-plugin-server 2> %t/diag1.txt
|
|
|
|
// RUN: %target-swift-frontend -scan-dependencies -module-load-mode prefer-serialized -module-name MyApp -module-cache-path %t/clang-module-cache -O \
|
|
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
|
|
// RUN: %t/main.swift -o %t/deps.json -swift-version 5 -cache-compile-job -cas-path %t/cas -external-plugin-path %t#%swift-plugin-server
|
|
|
|
// RUN: %{python} %S/Inputs/SwiftDepsExtractor.py %t/deps.json MyApp casFSRootID > %t/fs.casid
|
|
// RUN: %cache-tool -cas-path %t/cas -cache-tool-action print-include-tree-list @%t/fs.casid | %FileCheck %s --check-prefix=FS
|
|
|
|
// FS: MacroDefinition
|
|
|
|
// RUN: %{python} %S/../../utils/swift-build-modules.py --cas %t/cas %swift_frontend_plain %t/deps.json -o %t/MyApp.cmd
|
|
|
|
// RUN: %target-swift-frontend-plain -diagnostic-style=swift \
|
|
// RUN: -emit-module -o %t/Test.swiftmodule -cache-compile-job -cas-path %t/cas \
|
|
// RUN: -swift-version 5 -module-name MyApp -O \
|
|
// RUN: -external-plugin-path %t#%swift-plugin-server \
|
|
// RUN: -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
|
|
// RUN: %t/main.swift @%t/MyApp.cmd -serialize-diagnostics-path %t/Test.diag 2> %t/diag2.txt
|
|
|
|
// RUN: diff %t/diag1.txt %t/diag2.txt
|
|
|
|
//--- macro.swift
|
|
import SwiftDiagnostics
|
|
import SwiftOperators
|
|
import SwiftSyntax
|
|
import SwiftSyntaxBuilder
|
|
@_spi(ExperimentalLanguageFeature) import SwiftSyntaxMacros
|
|
|
|
public struct CallDeprecatedMacro: ExpressionMacro {
|
|
public static func expansion(
|
|
of macro: some FreestandingMacroExpansionSyntax,
|
|
in context: some MacroExpansionContext
|
|
) throws -> ExprSyntax {
|
|
return "testDeprecated()"
|
|
}
|
|
}
|
|
|
|
public struct ToMyWarningMacro: ExpressionMacro {
|
|
public static func expansion(
|
|
of macro: some FreestandingMacroExpansionSyntax,
|
|
in context: some MacroExpansionContext
|
|
) throws -> ExprSyntax {
|
|
return "#myWarning(\"\")"
|
|
}
|
|
}
|
|
|
|
//--- main.swift
|
|
@freestanding(expression) macro myWarning(_ message: String) = #externalMacro(module: "MacroDefinition", type: "CallDeprecatedMacro")
|
|
@freestanding(expression) macro toMyWarning(_ message: String) = #externalMacro(module: "MacroDefinition", type: "ToMyWarningMacro")
|
|
|
|
@available(*, deprecated)
|
|
func testDeprecated() {}
|
|
|
|
func testDiscardableStringify(x: Int) {
|
|
#toMyWarning("this is a warning")
|
|
#myWarning("this is a warning")
|
|
}
|