Allow self-sufficient desktop build for Github repository.
Test: OUT_DIR=$HOME/compose/androidx-main/out ALLOW_PUBLIC_REPOS=true \
COMPOSE_DESKTOP_GITHUB_BUILD=true ANDROIDX_PROJECTS=compose \
gradle -Pandroidx.compose.multiplatformEnabled=true \
:compose:desktop:desktop:desktop-samples:run
Change-Id: Ic3bc3ccf802bd507b90ddb696aab2084653b051c
diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle
index 71fdf91..55ed0c2 100644
--- a/buildSrc/build.gradle
+++ b/buildSrc/build.gradle
@@ -2,11 +2,8 @@
buildscript {
project.ext.supportRootFolder = project.projectDir.getParentFile()
- repositories {
- maven {
- url("${supportRootFolder}/../../prebuilts/androidx/external")
- }
- }
+ apply from: "repos.gradle"
+ repos.addMavenRepositories(repositories)
dependencies {
classpath(libs.kotlinGradlePlugin)
diff --git a/buildSrc/out.gradle b/buildSrc/out.gradle
index 4fe58ca..36a2b69 100644
--- a/buildSrc/out.gradle
+++ b/buildSrc/out.gradle
@@ -23,7 +23,7 @@
*/
def outDir = System.env.OUT_DIR
if (outDir == null) {
- outDir = new File("${buildscript.getSourceFile().parent}/../../../out${subdir}")
+ outDir = new File("${buildscript.sourceFile.parent}/../../../out${subdir}")
} else {
outDir = new File(outDir)
}
diff --git a/buildSrc/repos.gradle b/buildSrc/repos.gradle
index a882adba..45f8855 100644
--- a/buildSrc/repos.gradle
+++ b/buildSrc/repos.gradle
@@ -84,6 +84,9 @@
handler.maven {
url("https://plugins.gradle.org/m2/")
}
+ handler.maven {
+ url("https://maven.pkg.jetbrains.space/public/p/compose/dev")
+ }
handler.mavenLocal()
}
def androidPluginRepoOverride = System.getenv("GRADLE_PLUGIN_REPO")
diff --git a/buildSrc/src/main/kotlin/androidx/build/SaveSystemStatsTask.kt b/buildSrc/src/main/kotlin/androidx/build/SaveSystemStatsTask.kt
index 3e46290..dfd3315 100644
--- a/buildSrc/src/main/kotlin/androidx/build/SaveSystemStatsTask.kt
+++ b/buildSrc/src/main/kotlin/androidx/build/SaveSystemStatsTask.kt
@@ -36,6 +36,7 @@
}
@Input
+ @Suppress("DEPRECATION")
fun getTotalMemory(): Long {
val bean = ManagementFactory.getOperatingSystemMXBean() as OperatingSystemMXBean
return bean.getTotalPhysicalMemorySize()
diff --git a/buildSrc/src/main/kotlin/androidx/build/SdkHelper.kt b/buildSrc/src/main/kotlin/androidx/build/SdkHelper.kt
index 9d7d355..00d00a3 100644
--- a/buildSrc/src/main/kotlin/androidx/build/SdkHelper.kt
+++ b/buildSrc/src/main/kotlin/androidx/build/SdkHelper.kt
@@ -54,7 +54,9 @@
* Returns the root project's platform-specific SDK path as a file.
*/
fun Project.getSdkPath(): File {
- if (rootProject.plugins.hasPlugin(AndroidXPlaygroundRootPlugin::class.java)) {
+ if (rootProject.plugins.hasPlugin(AndroidXPlaygroundRootPlugin::class.java) ||
+ System.getenv("COMPOSE_DESKTOP_GITHUB_BUILD") != null
+ ) {
// This is not full checkout, use local settings instead.
// https://developer.android.com/studio/command-line/variables
// check for local.properties first
@@ -74,7 +76,6 @@
}
return getSdkPathFromEnvironmentVariable()
}
-
val os = getOperatingSystem()
return if (os == OperatingSystem.WINDOWS) {
getSdkPathFromEnvironmentVariable()
diff --git a/buildSrc/src/main/kotlin/androidx/build/SupportConfig.kt b/buildSrc/src/main/kotlin/androidx/build/SupportConfig.kt
index a098cf3..fb31998 100644
--- a/buildSrc/src/main/kotlin/androidx/build/SupportConfig.kt
+++ b/buildSrc/src/main/kotlin/androidx/build/SupportConfig.kt
@@ -16,6 +16,7 @@
package androidx.build
+import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.plugins.ExtraPropertiesExtension
import java.io.File
@@ -55,7 +56,15 @@
}
fun Project.getExternalProjectPath(): File {
- return File(project.getCheckoutRoot(), "external")
+ val path = if (System.getenv("COMPOSE_DESKTOP_GITHUB_BUILD") != null)
+ File(System.getenv("OUT_DIR")).also {
+ if (!File(it, "doclava").isDirectory()) {
+ throw GradleException("Please checkout doclava to $it")
+ }
+ }
+ else
+ File(rootProject.projectDir, "../../external")
+ return path.getCanonicalFile()
}
fun Project.getKeystore(): File {
diff --git a/compose/desktop/desktop/build.gradle b/compose/desktop/desktop/build.gradle
index 950f03e..2b99d7a 100644
--- a/compose/desktop/desktop/build.gradle
+++ b/compose/desktop/desktop/build.gradle
@@ -68,8 +68,17 @@
}
}
+File getGoldenPath(Project project) {
+ if (System.getenv("COMPOSE_DESKTOP_GITHUB_BUILD") != null) {
+ def externalPath = SupportConfigKt.getExternalProjectPath(project)
+ return new File(externalPath, "golden")
+ } else {
+ return new File("${rootDir.absolutePath}/../../golden").getCanonicalFile()
+ }
+}
+
tasks.findByName("jvmTest").configure {
- systemProperties["GOLDEN_PATH"] = project.rootDir.absolutePath + "/../../golden"
+ systemProperties["GOLDEN_PATH"] = getGoldenPath(project).toString()
}
androidx {
diff --git a/compose/desktop/desktop/samples/src/jvmMain/kotlin/androidx/compose/desktop/examples/example1/Main.jvm.kt b/compose/desktop/desktop/samples/src/jvmMain/kotlin/androidx/compose/desktop/examples/example1/Main.jvm.kt
index 55405aca..806f096 100644
--- a/compose/desktop/desktop/samples/src/jvmMain/kotlin/androidx/compose/desktop/examples/example1/Main.jvm.kt
+++ b/compose/desktop/desktop/samples/src/jvmMain/kotlin/androidx/compose/desktop/examples/example1/Main.jvm.kt
@@ -98,6 +98,7 @@
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.platform.Font
+import androidx.compose.ui.text.platform.FontLoader
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.style.TextDecoration.Companion.Underline
@@ -110,7 +111,16 @@
private const val title = "Desktop Compose Elements"
-val italicFont = FontFamily(Font("NotoSans-Italic.ttf"))
+val italicFont = try {
+ FontFamily(
+ Font("NotoSans-Italic.ttf").also {
+ // Check that font is loadable.
+ FontLoader().load(it)
+ }
+ )
+} catch (e: Exception) {
+ FontFamily.SansSerif
+}
@OptIn(ExperimentalComposeUiApi::class)
fun main() {
diff --git a/include-composite-deps.gradle b/include-composite-deps.gradle
index ba7bcf1..b368673 100644
--- a/include-composite-deps.gradle
+++ b/include-composite-deps.gradle
@@ -21,13 +21,21 @@
boolean currentBuildIsRootBuild = (gradle.parent == null)
+File getExternalProjectPath() {
+ def scriptDir = file(buildscript.sourceFile.parent)
+ if (System.getenv("COMPOSE_DESKTOP_GITHUB_BUILD") != null) {
+ def path = new File(System.env.OUT_DIR)
+ if (!(new File(path, "doclava").isDirectory())) {
+ throw new GradleException("Please checkout doclava to $path")
+ }
+ return path.getCanonicalFile()
+ } else {
+ return new File(scriptDir, "../../external").getCanonicalFile()
+ }
+}
+
// Add included builds. This only works if this is currently the root build, so this script should
// be applied to several builds and will only enable itself when part of the root build.
if (currentBuildIsRootBuild) {
- String buildScriptDir = buildscript.sourceFile.parent
- File externalRoot = new File(buildScriptDir, "../../external")
-
- includeBuild(new File(externalRoot, "doclava"))
+ includeBuild(new File(getExternalProjectPath(), "doclava"))
}
-
-