Skip to content

[Experimental] Initial draft of external dependencies implementation #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cba0968
external dependencies draft
IlyaGulya Oct 29, 2024
147dca9
extract plugin public api and make test fixtures use it in tests
IlyaGulya Oct 29, 2024
44f8d03
Merge branch 'main' into feature/external-dependencies-single-module-…
IlyaGulya Nov 27, 2024
e5456b5
using command line instead of string manipulation
frankois944 Nov 3, 2024
a2cc7a2
fix local spm
frankois944 Nov 3, 2024
cc493e3
make the plugin working namespace
frankois944 Nov 4, 2024
510232f
WIP: add multi product usage for a SPM repository
frankois944 Nov 4, 2024
2ddda8f
fix test
frankois944 Nov 4, 2024
8c4fb64
fix test
frankois944 Nov 4, 2024
6aeac88
update remote parameter name
frankois944 Nov 5, 2024
f9bae40
add more complex case
frankois944 Nov 5, 2024
85d4204
Add tools version parameter
frankois944 Nov 6, 2024
81bdb72
Change ExperimentalSwiftklibApi level
frankois944 Nov 6, 2024
f384dbc
fix build (my bad)
frankois944 Nov 6, 2024
ff6929d
rollback bad commit
frankois944 Nov 6, 2024
0dca45c
cleaning CompileSwiftTask
frankois944 Nov 6, 2024
bbe6b44
simplify content check
frankois944 Nov 24, 2024
18142b3
remove bad copy/paste
frankois944 Nov 24, 2024
75273f0
use none as check if the List is not blank
frankois944 Nov 24, 2024
32c2848
build the manifest from a template
frankois944 Nov 26, 2024
e418129
update tools version default version: 5.9
frankois944 Nov 26, 2024
e21cd68
update tools version default version: 5.9
frankois944 Nov 26, 2024
6b81f9b
cleanup
IlyaGulya Nov 27, 2024
71c9fa5
run functional tests on PR
IlyaGulya Nov 27, 2024
4d6c27f
don't fail test matrix fast. cancel currently running checks on new c…
IlyaGulya Nov 27, 2024
563219c
upgrade gradle to 8.11.1
IlyaGulya Nov 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release
name: Test

on:
push:
Expand All @@ -11,9 +11,14 @@ on:
permissions:
contents: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
Expand All @@ -30,4 +35,4 @@ jobs:
check-latest: true

- name: Run tests
run: ./gradlew test
run: ./gradlew test functionalTest
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ captures
.externalNativeBuild
.cxx
local.properties
xcuserdata
xcuserdata
.kotlin
21 changes: 12 additions & 9 deletions examples/helloswift/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
kotlin("multiplatform") version "1.9.20"
kotlin("multiplatform") version "2.0.21"
id("io.github.ttypic.swiftklib")
}

Expand All @@ -26,20 +26,23 @@ kotlin {
}
}

@Suppress("UNUSED_VARIABLE")
sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
applyDefaultHierarchyTemplate()

sourceSets.commonTest.dependencies {
implementation(kotlin("test"))
}
}

swiftklib {
create("HelloSwift") {
path = file("native/HelloSwift")
packageName("com.ttypic.objclibs.greeting")

dependencies {
remote("KeychainAccess") {
github("kishikawakatsumi", "KeychainAccess")
versionRange("4.0.0", "5.0.0")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Nov 05 13:59:35 MSK 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Empty file modified examples/helloswift/gradlew
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions examples/helloswift/native/HelloSwift/HelloSwift.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import Foundation
import KeychainAccess

@objc public class KeychainManager: NSObject {
private let keychain = Keychain(service: "test-service")
}

@objc public class HelloWorld : NSObject {
@objc public class func helloWorld() -> String {
Expand Down
7 changes: 5 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[versions]
kotlin = "2.0.0"
kotlin = "2.0.21"

gradlePublishPlugin = "1.2.1"

junit-jupiter = "5.8.0"

kotest = "5.9.1"

autonomousapps-testkit = "0.10"
[libraries]

plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
Expand All @@ -15,7 +15,10 @@ test-junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref =
test-junit-jupiter-launcher = { module = "org.junit.jupiter:junit-jupiter-engine" }
test-kotest-assertions = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }

test-autonomousapps-support = { module = "com.autonomousapps:gradle-testkit-support", version.ref = "autonomousapps-testkit" }
test-autonomousapps-truth = { module = "com.autonomousapps:gradle-testkit-truth", version.ref = "autonomousapps-testkit" }

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
gradle-publish = { id = "com.gradle.plugin-publish", version.ref = "gradlePublishPlugin" }
autonomousapps-testkit = { id = "com.autonomousapps.testkit", version.ref = "autonomousapps-testkit" }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
31 changes: 18 additions & 13 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -83,10 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,26 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
26 changes: 21 additions & 5 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,43 @@ plugins {
id("java-gradle-plugin")
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.gradle.publish)
alias(libs.plugins.autonomousapps.testkit)
}

dependencies {
implementation(gradleApi())
implementation(libs.plugin.kotlin)

testImplementation(gradleTestKit())
testImplementation(libs.test.junit.jupiter)
testImplementation(libs.test.kotest.assertions)
testRuntimeOnly(libs.test.junit.jupiter.launcher)
functionalTestImplementation(libs.test.junit.jupiter)
functionalTestImplementation(libs.test.kotest.assertions)
functionalTestImplementation(project(":plugin"))
functionalTestRuntimeOnly(libs.test.junit.jupiter.launcher)
}

tasks.named<Test>("test") {
gradleTestKitSupport {
withSupportLibrary()
withTruthLibrary()
}

tasks.named<Test>("functionalTest") {
useJUnitPlatform()
systemProperty("com.autonomousapps.test.versions.kotlin", libs.versions.kotlin.get())

beforeTest(closureOf<TestDescriptor> {
logger.lifecycle("Running test: $this")
})
}

version = "0.7.0-SNAPSHOT"
group = "io.github.ttypic"

kotlin {
jvmToolchain(17)
compilerOptions {
optIn.addAll(
"io.github.ttypic.swiftklib.gradle.api.ExperimentalSwiftklibApi"
)
}
}

@Suppress("UnstableApiUsage")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package io.github.ttypic.swiftklib.gradle

import com.autonomousapps.kit.GradleBuilder.build
import com.autonomousapps.kit.truth.TestKitTruth.Companion.assertThat
import io.github.ttypic.swiftklib.gradle.fixture.KotlinSource
import io.github.ttypic.swiftklib.gradle.fixture.SwiftKlibTestFixture
import io.github.ttypic.swiftklib.gradle.fixture.SwiftSource
import org.junit.jupiter.api.Test

class CinteropModulesTest {

@Test
fun `build with imported UIKit framework is successful`() {
assumeMacos()

// Given
val fixture = SwiftKlibTestFixture.builder()
.withSwiftSources(
SwiftSource.of(
content = """
import UIKit
@objc public class TestView: UIView {}
""".trimIndent()
)
)
.withKotlinSources(
KotlinSource.of(
content = """
package test
import test.TestView
val view = TestView()
""".trimIndent()
)
)
.build()

// When
val result = build(fixture.gradleProject.rootDir, "build")

// Then
assertThat(result).task(":library:build").succeeded()
}

@Test
fun `build on linux results in warning about unsupported OS`() {
assumeLinux()

// Given
val fixture = SwiftKlibTestFixture.builder()
.withSwiftSources(
SwiftSource.of(
content = """
import Foundation
@objc public class TestClass: NSObject {}
""".trimIndent()
)
)
.build()

// When
val result = build(fixture.gradleProject.rootDir, "build")

// Then
assertThat(result).output().contains("Current host OS is not macOS. Disabling SwiftKlib plugin")
}
}
Loading
Loading