Skip to content
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

Skip plugin initialization on non-macOS targets #39

Merged
merged 2 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 33 additions & 0 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Release

on:
push:
branches:
- main
pull_request:
branches:
- main

permissions:
contents: write

jobs:
test:
strategy:
matrix:
os: [macos-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
if: github.repository == 'ttypic/swift-klib-plugin'
timeout-minutes: 25

steps:
- uses: actions/checkout@v4
- uses: gradle/wrapper-validation-action@v2
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
check-latest: true

- name: Run tests
run: ./gradlew test
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.gradle.api.Project
import org.gradle.api.model.ObjectFactory
import org.gradle.configurationcache.extensions.capitalized
import org.jetbrains.kotlin.gradle.tasks.CInteropProcess
import org.jetbrains.kotlin.konan.target.HostManager

const val EXTENSION_NAME = "swiftklib"

Expand All @@ -22,6 +23,11 @@ class SwiftKlibPlugin : Plugin<Project> {

project.extensions.add(EXTENSION_NAME, swiftKlibEntries)

if (!HostManager.hostIsMac) {
logger.warn("Current host OS is not macOS. Disabling SwiftKlib plugin")
return
}

swiftKlibEntries.all { entry ->
val name: String = entry.name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package io.github.ttypic.swiftklib.gradle

import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.intellij.lang.annotations.Language
import org.junit.jupiter.api.Assumptions.assumeTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.OS
import org.junit.jupiter.api.io.TempDir
import java.io.File

Expand Down Expand Up @@ -35,6 +38,8 @@ class CinteropModulesTest {

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

testBuild(
swiftCode = """
import UIKit
Expand All @@ -53,11 +58,28 @@ class CinteropModulesTest {
}
}


@Test
fun `build on linux results in warning about unsupported OS`() {
assumeLinux()
testBuild {
output.shouldContain("Current host OS is not macOS. Disabling SwiftKlib plugin")
}
}

private fun assumeMacos() {
assumeTrue(OS.MAC.isCurrentOs)
}

private fun assumeLinux() {
assumeTrue(OS.LINUX.isCurrentOs)
}

private fun testBuild(
@Language("swift")
swiftCode: String,
swiftCode: String? = null,
@Language("kotlin")
kotlinCode: String = "",
kotlinCode: String? = null,
swiftklibName: String = "test",
swiftklibPackage: String = "test",
asserter: BuildResult.() -> Unit,
Expand Down Expand Up @@ -120,8 +142,12 @@ class CinteropModulesTest {
swiftLocation.mkdirs()
kotlinLocation.mkdirs()

swiftCodeFile.writeText(swiftCode)
kotlinCodeFile.writeText(kotlinCode)
if (swiftCode != null) {
swiftCodeFile.writeText(swiftCode)
}
if (kotlinCode != null) {
kotlinCodeFile.writeText(kotlinCode)
}

GradleRunner.create()
.withProjectDir(testProjectDir)
Expand Down