forked from swiftlang/swift-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-logic.java-common-conventions.gradle.kts
More file actions
108 lines (91 loc) · 3.32 KB
/
build-logic.java-common-conventions.gradle.kts
File metadata and controls
108 lines (91 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift.org project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift.org project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import java.util.*
import java.io.*
import kotlin.system.exitProcess
import kotlinx.serialization.json.*
plugins {
java
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(25)
}
}
repositories {
mavenCentral()
}
fun getSwiftRuntimeLibraryPaths(): List<String> {
val process = ProcessBuilder("swiftc", "-print-target-info")
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start()
val output = process.inputStream.bufferedReader().use { it.readText() }
val exitCode = process.waitFor()
if (exitCode != 0) {
System.err.println("Error executing swiftc -print-target-info")
exitProcess(exitCode)
}
val json = Json.parseToJsonElement(output)
val runtimeLibraryPaths = json.jsonObject["paths"]?.jsonObject?.get("runtimeLibraryPaths")?.jsonArray
return runtimeLibraryPaths?.map { it.jsonPrimitive.content } ?: emptyList()
}
/**
* Find library paths for 'java.library.path' when running or testing projects inside this build.
*/
// TODO: Deduplicate this code with javaLibraryPaths.kt
fun javaLibraryPaths(rootDir: File): List<String> {
val osName = System.getProperty("os.name").lowercase(Locale.getDefault())
val osArch = System.getProperty("os.arch")
val isLinux = osName.contains("linux")
val base = rootDir.path.let { "$it/" }
val projectBuildOutputPath =
if (isLinux) {
if (osArch == "amd64" || osArch == "x86_64")
"$base.build/x86_64-unknown-linux-gnu"
else
"$base.build/${osArch}-unknown-linux-gnu"
} else {
if (osArch == "aarch64")
"$base.build/arm64-apple-macosx"
else
"$base.build/${osArch}-apple-macosx"
}
val parentParentBuildOutputPath =
"../../$projectBuildOutputPath"
val swiftBuildOutputPaths = listOf(
projectBuildOutputPath,
parentParentBuildOutputPath
)
val debugBuildOutputPaths = swiftBuildOutputPaths.map { "$it/debug" }
val releaseBuildOutputPaths = swiftBuildOutputPaths.map { "$it/release" }
val swiftRuntimePaths = getSwiftRuntimeLibraryPaths()
return debugBuildOutputPaths + releaseBuildOutputPaths + swiftRuntimePaths
}
// Configure paths for native (Swift) libraries
tasks.test {
jvmArgs(
"--enable-native-access=ALL-UNNAMED",
// Include the library paths where our dylibs are that we want to load and call
"-Djava.library.path=" + javaLibraryPaths(project.projectDir).joinToString(File.pathSeparator)
)
}
tasks.withType<Test> {
this.testLogging {
this.showStandardStreams = true
}
}
// Validate javadoc for html/syntax/reference correctness but skip "missing" (no comment) warnings
tasks.withType<Javadoc> {
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:all,-missing", "-quiet")
}