[K/N][Tests] Migrate framework and objcexport tests
^KT-61259
This commit is contained in:
committed by
Space Team
parent
f00a145dd7
commit
025771460c
@@ -1087,11 +1087,6 @@ if (PlatformInfo.isAppleTarget(project)) {
|
||||
it.extraOpts '-Xforeign-exception-mode', "objc-wrap"
|
||||
}
|
||||
|
||||
createInterop("objcGh3343") {
|
||||
it.defFile 'framework/gh3343/objclib.def'
|
||||
it.headers "$projectDir/framework/gh3343/objclib.h"
|
||||
it.linkerOpts "-lobjcgh3343"
|
||||
}
|
||||
createInterop("objcKt43517") {
|
||||
it.defFile 'framework/kt43517/kt43517.def'
|
||||
}
|
||||
@@ -1877,356 +1872,6 @@ Task frameworkTest(String name, Closure<FrameworkTest> configurator) {
|
||||
}
|
||||
}
|
||||
|
||||
Task objcExportTest(
|
||||
Task allTask,
|
||||
String suffix,
|
||||
List<String> frameworkOpts,
|
||||
List<String> swiftOpts,
|
||||
Boolean isStaticFramework,
|
||||
Boolean needLazyHeaderCheck
|
||||
) {
|
||||
needLazyHeaderCheck = needLazyHeaderCheck && !PlatformInfo.isK2(project) // generating lazy headers is NYI in K2
|
||||
final String name = "testObjCExport$suffix"
|
||||
final String frameworkName = "Kt$suffix"
|
||||
final String expectedLazyHeaderName = "expectedLazy${suffix}.h"
|
||||
final Task task = frameworkTest(name) {
|
||||
final String dir = "$testOutputFramework/$name"
|
||||
final File lazyHeader = file("$dir/$target-lazy.h")
|
||||
lazyHeader.delete() // Clean up after previous runs
|
||||
|
||||
doLast {
|
||||
// Check lazy header.
|
||||
if (needLazyHeaderCheck) {
|
||||
final String expectedLazyHeaderDir = file("objcexport/")
|
||||
final File expectedLazyHeader = new File(expectedLazyHeaderDir, expectedLazyHeaderName)
|
||||
|
||||
if (!expectedLazyHeader.exists() || expectedLazyHeader.readLines() != lazyHeader.readLines()) {
|
||||
exec {
|
||||
commandLine 'diff', '-u', expectedLazyHeader, lazyHeader
|
||||
ignoreExitValue = true
|
||||
}
|
||||
|
||||
copy {
|
||||
from(lazyHeader)
|
||||
into(expectedLazyHeaderDir)
|
||||
rename { expectedLazyHeaderName }
|
||||
}
|
||||
|
||||
throw new Error("$expectedLazyHeader file patched;\nRun gradlew ${allTask.path} --continue and don't forget to commit the patch")
|
||||
}
|
||||
}
|
||||
|
||||
// Check bundle ID.
|
||||
final String frameworkPath = "$dir/$target/Kt.framework"
|
||||
final Pattern pattern = ~"<key>CFBundleIdentifier</key>\n\\s*<string>foo.bar</string>"
|
||||
final String plistPath = (target.family == Family.OSX) ?
|
||||
"$frameworkPath/Resources/Info.plist" :
|
||||
"$frameworkPath/Info.plist"
|
||||
final String plistContent = file(plistPath).text
|
||||
if (!pattern.matcher(plistContent).find()) {
|
||||
throw new Error("Unexpected Info.plist content:\n$plistContent")
|
||||
}
|
||||
}
|
||||
|
||||
def libraryName = frameworkName + "Library"
|
||||
def noEnumEntriesLibraryName = frameworkName + "NoEnumEntriesLibrary"
|
||||
File exportedKlibArtifact = null
|
||||
konanArtifacts {
|
||||
library(libraryName, targets: [target.name]) {
|
||||
srcDir "objcexport/library"
|
||||
artifactName "test-$libraryName"
|
||||
delegate.getByTarget(target.name).configure{
|
||||
UtilsKt.dependsOnDist(it)
|
||||
}
|
||||
|
||||
extraOpts "-Xshort-module-name=MyLibrary"
|
||||
extraOpts "-module-name", "org.jetbrains.kotlin.native.test-library"
|
||||
}
|
||||
library(noEnumEntriesLibraryName, targets: [target.name]) {
|
||||
srcDir "objcexport/noEnumEntries"
|
||||
artifactName "test-no-enum-entries-$libraryName"
|
||||
delegate.getByTarget(target.name).configure{
|
||||
UtilsKt.dependsOnDist(it)
|
||||
}
|
||||
|
||||
exportedKlibArtifact = getArtifactByTarget(target.name)
|
||||
extraOpts "-Xshort-module-name=NoEnumEntriesLibrary"
|
||||
extraOpts "-module-name", "org.jetbrains.kotlin.native.test-no-enum-entries-library"
|
||||
extraOpts "-XXLanguage:-EnumEntries"
|
||||
}
|
||||
}
|
||||
codesign = !isStaticFramework
|
||||
framework(frameworkName) {
|
||||
sources = ['objcexport']
|
||||
libraries = [libraryName, noEnumEntriesLibraryName]
|
||||
artifact = 'Kt'
|
||||
isStatic = isStaticFramework
|
||||
if (needLazyHeaderCheck) {
|
||||
opts += "-Xemit-lazy-objc-header=$lazyHeader"
|
||||
}
|
||||
opts += [
|
||||
"-Xexport-kdoc",
|
||||
"-Xbinary=bundleId=foo.bar",
|
||||
"-Xexport-library=$exportedKlibArtifact",
|
||||
"-module-name", "Kt"
|
||||
]
|
||||
opts += frameworkOpts
|
||||
}
|
||||
swiftSources = ['objcexport']
|
||||
swiftExtraOpts = swiftOpts
|
||||
if (isNoopGC) {
|
||||
swiftExtraOpts += ["-D", "NOOP_GC"]
|
||||
}
|
||||
if (isAggressiveGC) {
|
||||
swiftExtraOpts += ["-D", "AGGRESSIVE_GC"]
|
||||
}
|
||||
}
|
||||
allTask.dependsOn(task)
|
||||
return task
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (PlatformInfo.isAppleTarget(project)) {
|
||||
final Task ObjCExportAllTask = tasks.create("testObjCExportAll")
|
||||
objcExportTest(
|
||||
ObjCExportAllTask,
|
||||
'',
|
||||
[],
|
||||
[],
|
||||
false,
|
||||
true
|
||||
)
|
||||
objcExportTest(
|
||||
ObjCExportAllTask,
|
||||
'NoGenerics',
|
||||
["-Xno-objc-generics"],
|
||||
[ '-D', 'NO_GENERICS' ],
|
||||
false,
|
||||
true
|
||||
)
|
||||
objcExportTest(
|
||||
ObjCExportAllTask,
|
||||
'LegacySuspendUnit',
|
||||
["-Xbinary=unitSuspendFunctionObjCExport=legacy"],
|
||||
[ '-D', 'LEGACY_SUSPEND_UNIT_FUNCTION_EXPORT' ],
|
||||
false,
|
||||
true
|
||||
)
|
||||
objcExportTest(
|
||||
ObjCExportAllTask,
|
||||
'NoSwiftMemberNameMangling',
|
||||
["-Xbinary=objcExportDisableSwiftMemberNameMangling=true"],
|
||||
[ '-D', 'DISABLE_MEMBER_NAME_MANGLING' ],
|
||||
false,
|
||||
false
|
||||
)
|
||||
objcExportTest(
|
||||
ObjCExportAllTask,
|
||||
'NoInterfaceMemberNameMangling',
|
||||
["-Xbinary=objcExportIgnoreInterfaceMethodCollisions=true"],
|
||||
[ '-D', 'DISABLE_INTERFACE_METHOD_NAME_MANGLING' ],
|
||||
false,
|
||||
false
|
||||
)
|
||||
|
||||
objcExportTest(
|
||||
ObjCExportAllTask,
|
||||
'Static',
|
||||
["-Xbinary=objcExportSuspendFunctionLaunchThreadRestriction=none"],
|
||||
[ '-D', 'ALLOW_SUSPEND_ANY_THREAD' ],
|
||||
true,
|
||||
false
|
||||
)
|
||||
|
||||
|
||||
frameworkTest('testValuesGenericsFramework') {
|
||||
framework('ValuesGenerics') {
|
||||
sources = ['objcexport/values.kt', 'framework/values_generics']
|
||||
}
|
||||
swiftSources = ['framework/values_generics/']
|
||||
}
|
||||
|
||||
frameworkTest("testStdlibFramework") {
|
||||
framework('Stdlib') {
|
||||
sources = ['framework/stdlib']
|
||||
}
|
||||
swiftSources = ['framework/stdlib/']
|
||||
}
|
||||
|
||||
if (cacheTesting != null && cacheTesting.isDynamic) {
|
||||
// testMultipleFrameworks disabled until https://youtrack.jetbrains.com/issue/KT-34262 is fixed.
|
||||
} else frameworkTest("testMultipleFrameworks") {
|
||||
framework('First') {
|
||||
sources = ['framework/multiple/framework1', 'framework/multiple/shared']
|
||||
}
|
||||
framework('Second') {
|
||||
sources = ['framework/multiple/framework2', 'framework/multiple/shared']
|
||||
}
|
||||
swiftSources = ['framework/multiple']
|
||||
}
|
||||
|
||||
frameworkTest("testMultipleFrameworksStatic") {
|
||||
// this test doesn't work with caches.
|
||||
if (cacheTesting != null && !runtimeAssertionsPanic) {
|
||||
// See https://youtrack.jetbrains.com/issue/KT-34261.
|
||||
expectedExitStatus = 134
|
||||
}
|
||||
|
||||
framework('FirstStatic') {
|
||||
artifact = 'First'
|
||||
sources = ['framework/multiple/framework1', 'framework/multiple/shared']
|
||||
isStatic = true
|
||||
opts = ['-Xstatic-framework', "-Xpre-link-caches=enable"]
|
||||
}
|
||||
framework('SecondStatic') {
|
||||
artifact = 'Second'
|
||||
sources = ['framework/multiple/framework2', 'framework/multiple/shared']
|
||||
isStatic = true
|
||||
opts = ['-Xstatic-framework', "-Xpre-link-caches=enable"]
|
||||
}
|
||||
codesign = false
|
||||
swiftSources = ['framework/multiple']
|
||||
}
|
||||
|
||||
frameworkTest("testGh3343Framework") {
|
||||
framework('Gh3343') {
|
||||
sources = ['framework/gh3343']
|
||||
libraries = ['objcGh3343']
|
||||
}
|
||||
swiftSources = ['framework/gh3343/']
|
||||
}
|
||||
|
||||
frameworkTest("testKt42397Framework") {
|
||||
enabled = !project.globalTestArgs.contains('-opt')
|
||||
framework("Kt42397") {
|
||||
sources = ['framework/kt42397']
|
||||
}
|
||||
swiftSources = ['framework/kt42397']
|
||||
}
|
||||
|
||||
frameworkTest("testKt43517Framework") {
|
||||
framework('Kt43517') {
|
||||
sources = ['framework/kt43517']
|
||||
libraries = ['objcKt43517']
|
||||
}
|
||||
swiftSources = ['framework/kt43517/']
|
||||
}
|
||||
|
||||
frameworkTest("testStackTraceFramework") {
|
||||
enabled = !project.globalTestArgs.contains('-opt')
|
||||
framework('Stacktrace') {
|
||||
sources = ['framework/stacktrace']
|
||||
opts = ['-g']
|
||||
}
|
||||
swiftSources = ['framework/stacktrace/']
|
||||
}
|
||||
|
||||
frameworkTest("testStackTraceBridgesFramework") {
|
||||
enabled = !project.globalTestArgs.contains('-opt')
|
||||
framework('StacktraceBridges') {
|
||||
sources = ['framework/stacktraceBridges']
|
||||
opts = ['-g']
|
||||
}
|
||||
swiftSources = ['framework/stacktraceBridges/']
|
||||
}
|
||||
|
||||
|
||||
frameworkTest("testStackTraceByLibbacktraceFramework") {
|
||||
enabled = !project.globalTestArgs.contains('-opt')
|
||||
framework('StacktraceByLibbacktrace') {
|
||||
sources = ['framework/stacktraceByLibbacktrace']
|
||||
opts = ['-g', '-Xbinary=sourceInfoType=libbacktrace']
|
||||
}
|
||||
swiftSources = ['framework/stacktraceByLibbacktrace/']
|
||||
}
|
||||
|
||||
frameworkTest("testAbstractInstantiationFramework") {
|
||||
framework('AbstractInstantiation') {
|
||||
sources = ['framework/abstractInstantiation']
|
||||
}
|
||||
swiftSources = ['framework/abstractInstantiation/']
|
||||
expectedExitStatus = 134
|
||||
}
|
||||
|
||||
frameworkTest("testFrameworkBundleId") {
|
||||
def currentTarget = project.target.name
|
||||
enabled = currentTarget.startsWith("mac")
|
||||
|
||||
framework("Foo") {
|
||||
sources = ["framework/bundle_id/main.kt", "framework/bundle_id/lib.kt"]
|
||||
opts = ["-Xbinary=bundleVersion=FooBundleVersion", "-Xbinary=bundleShortVersionString=FooBundleShortVersionString"]
|
||||
}
|
||||
swiftSources = []
|
||||
|
||||
doLast {
|
||||
def frameworkPath = "$testOutputFramework/testFrameworkBundleId/$target/Foo.framework"
|
||||
def bundleIdPattern = ~"<key>CFBundleIdentifier</key>\n\\s*<string>Foo</string>"
|
||||
def bundleShortVersionStringPattern = ~"<key>CFBundleShortVersionString</key>\n\\s*<string>FooBundleShortVersionString</string>"
|
||||
def bundleVersionPattern = ~"<key>CFBundleVersion</key>\n\\s*<string>FooBundleVersion</string>"
|
||||
def plistContent = file("$frameworkPath/Resources/Info.plist").text
|
||||
if (!bundleIdPattern.matcher(plistContent).find()) {
|
||||
throw new Error("Unexpected CFBundleIdentifier in Info.plist:\n$plistContent")
|
||||
}
|
||||
if (!bundleShortVersionStringPattern.matcher(plistContent).find()) {
|
||||
throw new Error("Unexpected CFBundleShortVersionString in Info.plist:\n$plistContent")
|
||||
}
|
||||
if (!bundleVersionPattern.matcher(plistContent).find()) {
|
||||
throw new Error("Unexpected CFBundleVersion in Info.plist:\n$plistContent")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frameworkTest("testForwardDeclarationsFramework") {
|
||||
framework('ForwardDeclarations') {
|
||||
sources = ['framework/forwardDeclarations']
|
||||
libraries = ['frameworkForwardDeclarations']
|
||||
}
|
||||
swiftSources = ['framework/forwardDeclarations/']
|
||||
}
|
||||
|
||||
frameworkTest("testFrameworkUsesFoundationModule") {
|
||||
framework("Bar") {
|
||||
sources = ["framework/use_foundation_module/framework.kt"]
|
||||
}
|
||||
swiftSources = []
|
||||
doLast {
|
||||
def frameworkPath = "$testOutputFramework/testFrameworkUsesFoundationModule/$target/Bar.framework"
|
||||
def moduleMapContent = file("$frameworkPath/Modules/module.modulemap").text
|
||||
def useFoundationPattern = ~"use Foundation"
|
||||
if (!useFoundationPattern.matcher(moduleMapContent).find()) {
|
||||
throw new Error("Expected use of Foundation module:\n$moduleMapContent")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frameworkTest("testKt56233Framework") {
|
||||
framework("Kt56233") {
|
||||
sources = ['framework/kt56233']
|
||||
}
|
||||
swiftSources = ['framework/kt56233']
|
||||
if (isAggressiveGC) {
|
||||
swiftExtraOpts += ["-D", "AGGRESSIVE_GC"]
|
||||
}
|
||||
}
|
||||
|
||||
frameworkTest("testKt57791Framework") {
|
||||
framework("Kt57791") {
|
||||
sources = ['framework/kt57791']
|
||||
}
|
||||
swiftSources = ['framework/kt57791']
|
||||
}
|
||||
|
||||
frameworkTest("testPermanentObjectsFramework") {
|
||||
enabled = !isNoopGC // Requires gc to actually happen.
|
||||
framework("PermanentObjects") {
|
||||
sources = ['framework/permanentObjects']
|
||||
opts = ['-opt-in=kotlin.native.internal.InternalForKotlinNative']
|
||||
}
|
||||
swiftSources = ['framework/permanentObjects']
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register("override_konan_properties0", KonanDriverTest) {
|
||||
disabled = isAggressiveGC // No need to test with different GC schedulers
|
||||
def overrides = PlatformInfo.isWindows()
|
||||
|
||||
Reference in New Issue
Block a user