### Install Skip CLI and Create Project Source: https://context7.com/skiptools/skip/llms.txt Installs the Skip CLI tool using Homebrew, verifies the installation and checks for dependencies, and creates a new Skip project. This is the initial setup step for using Skip. ```bash # Install Skip CLI tool brew install skiptools/skip/skip # Verify installation and check dependencies skip checkup # Create a new Skip project skip create ``` -------------------------------- ### Use SkipLink Command Plugin (Bash) Source: https://context7.com/skiptools/skip/llms.txt Demonstrates how to invoke the 'SkipLink' command plugin using Swift Package Manager. This plugin creates symbolic links from the project directory to the transpiled Kotlin output, aiding in code browsing and debugging. ```bash # Run the SkipLink command plugin via SwiftPM swift package plugin --allow-writing-to-package-directory SkipLink --target MyModule # This creates: # MySkipApp/ # └── SkipLink/ # └── MyModule -> ~/Library/Developer/Xcode/DerivedData/.../skipstone/ ``` -------------------------------- ### Implement GradleHarness for Gradle Output Processing Source: https://context7.com/skiptools/skip/llms.txt Illustrates how to implement the `GradleHarness` protocol to process Gradle command output. This includes scanning for errors, mapping Kotlin compilation errors back to Swift source locations using source maps, and locating plugin output folders. ```swift import SkipDrive // Custom harness implementation for handling Gradle output struct MyGradleHarness: GradleHarness { // Scan Gradle output for errors and convert to Xcode-compatible format func scanGradleOutput(line1: String, line2: String) { // Parse Kotlin compilation errors // e.g.: "e: file:///path/to/File.kt:12:13 Compile Error" if let issue = parseKotlinIssue(line1: line1, line2: line2) { // Map back to Swift source if possible if let swiftLocation = try? issue.location?.findSourceMapLine() { print(GradleIssue( kind: issue.kind, message: issue.message, location: swiftLocation ).xcodeMessageString) } print(issue.xcodeMessageString) } } } // Using the harness to find plugin output folder let harness = MyGradleHarness() let outputFolder = try harness.pluginOutputFolder( moduleName: "MyModule", linkingInto: URL(fileURLWithPath: "Skip/build") ) print("Transpiled output at: (outputFolder.path)") // Execute Gradle with the harness try await harness.gradleExec( in: URL(fileURLWithPath: "/path/to/project"), moduleName: "MyModule", packageName: "my-package", arguments: ["build"] ) ``` -------------------------------- ### Initialize and Use GradleDriver for Kotlin Builds Source: https://context7.com/skiptools/skip/llms.txt Shows how to initialize and use the `GradleDriver` from the `SkipDrive` library to manage Gradle builds for transpiled Kotlin code. It includes version validation, launching Gradle processes, and handling build output. ```swift import SkipDrive // Initialize the Gradle driver (validates versions automatically) let driver = try await GradleDriver() // Check Gradle and Kotlin versions print("Gradle version: (driver.gradleVersion)") // e.g., "8.5.0" print("Kotlin version: (driver.kotlinVersion)") // e.g., "1.9.20" // Execute a Gradle build in a project directory let projectDir = URL(fileURLWithPath: "/path/to/android/project") let (output, parseResults) = try await driver.launchGradleProcess( in: projectDir, module: "MyModule", actions: ["assembleDebug"], arguments: [], environment: ProcessInfo.processInfo.environmentWithDefaultToolPaths, daemon: true, rerunTasks: false, exitHandler: { result in switch result.exitStatus { case .terminated(let code): print("Gradle finished with exit code: (code)") default: print("Gradle terminated abnormally") } } ) // Stream and process output lines for try await line in output { print(line.line) } ``` -------------------------------- ### Stream and Execute Processes with Skip Utilities (Swift) Source: https://context7.com/skiptools/skip/llms.txt Provides utilities for asynchronously streaming subprocess output line by line and synchronously executing processes. Handles subprocess exit statuses and retrieves UTF-8 output. Requires the SkipDrive framework. ```swift import SkipDrive // Stream output from a subprocess line by line let output = Process.streamLines( command: ["gradle", "--version"], environment: ProcessInfo.processInfo.environment, includeStdErr: true, onExit: { result in guard case .terminated(0) = result.exitStatus else { throw ProcessResult.Error.nonZeroExit(result) } } ) // Process each line asynchronously for try await line in output { print(line.line) if line.err { print("(stderr)") } } // Execute and get result synchronously let result = try Process.popen( arguments: ["gradle", "tasks", "--all"], environment: ProcessInfo.processInfo.environmentWithDefaultToolPaths ) // Get UTF-8 output let stdout = try result.utf8Output() print(stdout) // Check for non-zero exit with output let output = try await Process.checkNonZeroExit( args: "skip", "checkup" ) print(output) ``` -------------------------------- ### Run Transpiled Kotlin Tests with XCGradleHarness Source: https://context7.com/skiptools/skip/llms.txt The XCGradleHarness protocol extends GradleHarness for XCTest, allowing Skip projects to run transpiled Kotlin tests via JUnit and report results to Xcode. It supports local JVM testing with Robolectric and connected device/emulator testing. Dependencies include XCTest and SkipTest. It takes an optional device parameter for specifying a target device. ```swift import XCTest import SkipTest // Test class that runs transpiled Kotlin tests final class MyModuleTests: XCTestCase, XCGradleHarness { // Run tests using Robolectric (local JVM, no device needed) func testSkipModule() async throws { try await runGradleTests() } // Run tests on a connected Android device/emulator func testOnDevice() async throws { // Uses ANDROID_SERIAL env var or first available device try await runGradleTests(device: "") } // Run tests on a specific device by serial number func testSpecificDevice() async throws { try await runGradleTests(device: "emulator-5554") } } // Environment configuration for CI/CD // Set SKIP_GRADLE_TEST_TARGET to override test target // e.g., "connectedDebugAndroidTest" for emulator testing // export SKIP_GRADLE_TEST_TARGET=connectedDebugAndroidTest ``` -------------------------------- ### Configure Skip Build Plugin in Package.swift (Swift) Source: https://context7.com/skiptools/skip/llms.txt Demonstrates how to integrate the 'skipstone' build plugin into a Swift Package Manager project. This plugin automatically transpiles Swift source files to Kotlin during Xcode/SwiftPM builds. It requires the Skip package to be added as a dependency. ```swift // Package.swift configuration for Skip build plugin let package = Package( name: "MySkipApp", platforms: [.iOS(.v16), .macOS(.v13)], products: [ .library(name: "MyModule", targets: ["MyModule"]) ], dependencies: [ .package(url: "https://github.com/skiptools/skip.git", from: "1.7.0") ], targets: [ // Main module with Skip transpilation .target( name: "MyModule", dependencies: [], plugins: [ .plugin(name: "skipstone", package: "skip") ] ), // Test module for running Kotlin tests .testTarget( name: "MyModuleTests", dependencies: [ "MyModule", .product(name: "SkipTest", package: "skip") ], plugins: [ .plugin(name: "skipstone", package: "skip") ] ) ] ) // Project structure: // MySkipApp/ // └── Package.swift // └── Sources/ // └── MyModule/ // └── MyModule.swift // └── Skip/ // └── skip.yml # Skip configuration file (required) // // Build output: // .build/plugins/outputs/myskipapp/MyModule/skipstone/ // └── MyModule/ // └── src/main/kotlin/ // └── my/module/MyModule.kt ``` -------------------------------- ### Map Kotlin Code Locations to Swift Source with SourceLocation and SourceMap Source: https://context7.com/skiptools/skip/llms.txt The SourceLocation and SourceMap types facilitate mapping transpiled Kotlin code locations back to their original Swift source files. The Skip transpiler generates `.sourcemap` files containing this mapping information. Dependencies include SkipDrive. It takes a Kotlin SourceLocation and uses a source map to find the corresponding Swift SourceLocation. ```swift import SkipDrive // Create a source location from a Kotlin error let kotlinLocation = SourceLocation( path: "/path/to/output/MyModule/src/main/kotlin/my/module/MyFile.kt", position: SourceLocation.Position(line: 42, column: 15) ) // Find the corresponding Swift source location via source map if let swiftLocation = try? kotlinLocation.findSourceMapLine() { print("Original Swift location: (swiftLocation.path):(swiftLocation.position.line)") // Output: "/path/to/source/MyFile.swift:28" } // The source map JSON structure (generated by Skip transpiler) // .MyFile.sourcemap contains entries like: // { // "entries": [ // { // "sourceFile": { "path": "/source/MyFile.swift" }, // "sourceRange": { "start": { "line": 28, "column": 0 }, "end": { "line": 30, "column": 0 } }, // "range": { "start": { "line": 42, "column": 0 }, "end": { "line": 45, "column": 0 } } // } // ] // } ``` -------------------------------- ### Add Skip as Swift Package Dependency Source: https://context7.com/skiptools/skip/llms.txt Demonstrates how to add Skip as a package dependency in a Swift project's Package.swift file. It specifies the platform targets and includes Skip as a plugin dependency for build targets, enabling the transpilation workflow. ```swift // Package.swift // swift-tools-version: 5.9 import PackageDescription let package = Package( name: "MyApp", platforms: [.iOS(.v16), .macOS(.v13)], dependencies: [ .package(url: "https://github.com/skiptools/skip.git", from: "1.7.0") ], targets: [ .target( name: "MyModule", dependencies: [], plugins: [.plugin(name: "skipstone", package: "skip")] ), .testTarget( name: "MyModuleTests", dependencies: ["MyModule", "SkipTest"], plugins: [.plugin(name: "skipstone", package: "skip")] ) ] ) ``` -------------------------------- ### Parse JUnit XML Test Results with TestSuite and TestCase Source: https://context7.com/skiptools/skip/llms.txt The TestSuite and TestCase structs are used to parse JUnit XML test result files generated by Gradle. This allows Skip to report individual test outcomes, including failures and source locations, to Xcode's test navigator. Dependencies include SkipDrive. It takes a URL to the XML file as input and outputs parsed test suite and test case information. ```swift import SkipDrive // Parse JUnit XML test results from Gradle output let testResultsURL = URL(fileURLWithPath: ".build/MyModule/test-results/test") let xmlFile = testResultsURL.appendingPathComponent("TEST-my.module.MyTests.xml") let testSuites = try GradleDriver.TestSuite.parse(contentsOf: xmlFile) // Process test results for suite in testSuites { print("Suite: (suite.name)") print("Tests: (suite.tests), Failures: (suite.failures), Skipped: (suite.skipped)") print("Duration: (suite.time)s") for testCase in suite.testCases { let status = testCase.failures.isEmpty ? "PASSED" : "FAILED" print(" (status): (testCase.name) ((testCase.time)s)") for failure in testCase.failures { print(" Error: (failure.message)") if let type = failure.type { print(" Type: (type)") } if let stackTrace = failure.contents { print(" Stack trace:\n(stackTrace)") } } } // Access captured stdout/stderr if let stdout = suite.systemOut { print("Stdout: (stdout)") } } ``` -------------------------------- ### Access SkipDrive Version with skipVersion Constant Source: https://context7.com/skiptools/skip/llms.txt The `skipVersion` constant provides the current version of the SkipDrive library for programmatic access. This is useful for compatibility checks or logging purposes. Dependencies include SkipDrive. It exposes the version as a string and can be used to instantiate a Version object for comparisons. ```swift import SkipDrive // Access the current Skip version print("Skip version: (skipVersion)") // Output: "1.7.0" // Use for compatibility checks or logging func checkSkipVersion() { let version = try? Version(versionString: skipVersion) if let v = version, v >= Version(1, 7, 0) { print("Using Skip (v.major).(v.minor).(v.patch)") } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.