Moving the buildDir for the buildSrc project to be in the out/ dir
So it's one less location where state can be stored
This makes it easier to diff, backup, and restore build state
Bug: 129866415
Test: OUT_DIR=/tmp/out DIST_DIR=/tmp/out/dist ./gradlew buildOnServer && ls /tmp/out/dist/top-of-tree-m2repository-partially-dejetified-dist.zip
Test: ./cleanBuild.sh assembleDebug && ls ../../out/dist
Test: git clean -fdx && ./gradlew projects && ((stat buildSrc/build && echo failed: buildSrc/build must not exist) || true)
Test: DIST_DIR=/tmp/out/dist ./gradlew misspelledTaskName # and see that there's a stacktrace
Test: ./gradlew misspelledTaskName # and see that there's no stacktrace
Change-Id: I8b1030f092a6bf6eacfeca799630e7e0d5424aa9
diff --git a/build.gradle b/build.gradle
index 53e1f07b..0a3add8 100644
--- a/build.gradle
+++ b/build.gradle
@@ -42,7 +42,7 @@
repos.addMavenRepositories(repositories)
-init.setupRepoOutAndBuildNumber()
+init.setupRepoOutAndStartParam()
init.configureSubProjects()
diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle
index 6afb3a1..2729399 100644
--- a/buildSrc/build.gradle
+++ b/buildSrc/build.gradle
@@ -24,7 +24,11 @@
}
}
}
-def runningInBuildServer = System.env.DIST_DIR != null && System.env.OUT_DIR != null
+
+apply from: "out.gradle"
+init.chooseOutDir()
+
+def runningInBuildServer = System.env.DIST_DIR != null
if (runningInBuildServer) {
System.setProperty("kotlin.compiler.execution.strategy", "in-process")
}
diff --git a/buildSrc/init.gradle b/buildSrc/init.gradle
index d12671f..a88cee3 100644
--- a/buildSrc/init.gradle
+++ b/buildSrc/init.gradle
@@ -24,32 +24,10 @@
throw new RuntimeException("variable supportRootFolder is not set. you must set it before" +
" including this script")
}
-def init = new Properties()
-ext.init = init
+apply from: "${supportRoot}/buildSrc/out.gradle"
rootProject.ext.versionChecker = new GMavenVersionChecker(rootProject.logger)
apply from: "${supportRoot}/buildSrc/dependencies.gradle"
-def setupRepoOutAndBuildNumber() {
- /*
- * The OUT_DIR is a temporary directory you can use to put things during the build.
- */
- if (BuildServerConfigurationKt.isRunningOnBuildServer()) {
- buildDir = new File(System.env.OUT_DIR + '/gradle/frameworks/support/build')
- .getCanonicalFile()
- // the build server should always print out full stack traces for any failures.
- gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS
- } else {
- buildDir = file("${ext.supportRootFolder}/../../out/host/gradle/frameworks/support/build")
- }
- subprojects {
- // Change buildDir first so that all plugins pick up the new value.
- project.buildDir = new File("$project.parent.buildDir/../$project.name/build")
- }
- ext.supportRepoOut = new File(buildDir, 'support_repo')
- ext.supportRepoOut.mkdirs()
- ext.docsDir = new File(buildDir, 'javadoc')
-}
-
def configureSubProjects() {
subprojects {
repos.addMavenRepositories(repositories)
@@ -170,5 +148,12 @@
}
}
-ext.init.setupRepoOutAndBuildNumber = this.&setupRepoOutAndBuildNumber
+def setupRepoOutAndStartParam() {
+ ext.init.chooseOutDir()
+ if (BuildServerConfigurationKt.isRunningOnBuildServer()) {
+ gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS
+ }
+}
+
+ext.init.setupRepoOutAndStartParam = this.&setupRepoOutAndStartParam
ext.init.configureSubProjects = this.&configureSubProjects
diff --git a/buildSrc/out.gradle b/buildSrc/out.gradle
new file mode 100644
index 0000000..7a7b027
--- /dev/null
+++ b/buildSrc/out.gradle
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+def init = new Properties()
+ext.init = init
+
+def chooseOutDir() {
+ /*
+ * The OUT_DIR is a temporary directory you can use to put things during the build.
+ */
+ buildDir = new File(System.env.OUT_DIR + "/$project.name/build")
+ .getCanonicalFile()
+ subprojects {
+ // Change buildDir first so that all plugins pick up the new value.
+ project.buildDir = new File("$project.parent.buildDir/../$project.name/build")
+ }
+ ext.supportRepoOut = new File(buildDir, 'support_repo')
+ ext.supportRepoOut.mkdirs()
+ ext.docsDir = new File(buildDir, 'javadoc')
+}
+
+ext.init.chooseOutDir = this.&chooseOutDir
diff --git a/buildSrc/src/main/kotlin/androidx/build/BuildServerConfiguration.kt b/buildSrc/src/main/kotlin/androidx/build/BuildServerConfiguration.kt
index 0b6b568..490b619 100644
--- a/buildSrc/src/main/kotlin/androidx/build/BuildServerConfiguration.kt
+++ b/buildSrc/src/main/kotlin/androidx/build/BuildServerConfiguration.kt
@@ -20,7 +20,7 @@
import org.gradle.api.Project
import java.io.File
-fun isRunningOnBuildServer() = System.getenv("DIST_DIR") != null && System.getenv("OUT_DIR") != null
+fun isRunningOnBuildServer() = System.getenv("DIST_DIR") != null
/**
* @return build id string for current build
@@ -59,4 +59,4 @@
private fun getRootDirectory(project: Project): File {
val actualRootProject = if (project.isRoot) project else project.rootProject
return actualRootProject.extensions.extraProperties.get("supportRootFolder") as File
-}
\ No newline at end of file
+}
diff --git a/cleanBuild.sh b/cleanBuild.sh
index 5ac9302..90d0861 100755
--- a/cleanBuild.sh
+++ b/cleanBuild.sh
@@ -27,9 +27,8 @@
export OUT_DIR=../../out
function removeCaches() {
- rm -rf .gradle
+ rm -rf .gradle
rm -rf buildSrc/.gradle
- rm -rf buildSrc/build
rm -f local.properties
rm -rf ../../out
}
diff --git a/gradlew b/gradlew
index 81ab28a..1cf59b6 100755
--- a/gradlew
+++ b/gradlew
@@ -11,6 +11,10 @@
if [ -n "$OUT_DIR" ] ; then
export GRADLE_USER_HOME="$OUT_DIR/.gradle"
export LINT_PRINT_STACKTRACE=true
+else
+ SCRIPT_PATH="$(cd $(dirname $0) && pwd)"
+ CHECKOUT_ROOT="$(cd $SCRIPT_PATH/../.. && pwd)"
+ export OUT_DIR="$CHECKOUT_ROOT/out"
fi
# ----------------------------------------------------------------------------
@@ -70,6 +74,8 @@
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+# --------- androidx specific code needed for lint and java. ------------------
+
# Pick the correct fullsdk for this OS.
if [ $darwin == "true" ]; then
plat="darwin"
@@ -80,10 +86,12 @@
# Temporary solution for custom, private lint rules https://issuetracker.google.com/issues/65248347
# Gradle automatically invokes 'jar' task on 'buildSrc/' projects so this will always be available.
-export ANDROID_LINT_JARS="$APP_HOME/buildSrc/lint-checks/build/libs/lint-checks.jar"
+export ANDROID_LINT_JARS="$OUT_DIR/buildSrc/lint-checks/build/libs/lint-checks.jar"
# override JAVA_HOME, because CI machines have it and it points to very old JDK
export JAVA_HOME="$APP_HOME/../../prebuilts/jdk/jdk8/$plat-x86"
+# ----------------------------------------------------------------------------
+
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
diff --git a/navigation/integration-tests/safeargs-testapp/buildSrc/build.gradle b/navigation/integration-tests/safeargs-testapp/buildSrc/build.gradle
index 3a2b772..aee6ff6 100644
--- a/navigation/integration-tests/safeargs-testapp/buildSrc/build.gradle
+++ b/navigation/integration-tests/safeargs-testapp/buildSrc/build.gradle
@@ -18,9 +18,7 @@
apply from: "$supportRootFolder/buildSrc/repos.gradle"
repos.addMavenRepositories(repositories)
-ext.runningInBuildServer = System.env.DIST_DIR != null && System.env.OUT_DIR != null
-ext.repoDir = runningInBuildServer ? new File(System.env.OUT_DIR + '/gradle/frameworks/support/build') :
- new File("$supportRootFolder/../../out/host/gradle/frameworks/support/build")
+ext.repoDir = runningInBuildServer ? new File(System.env.OUT_DIR + '/support/build')
task createArchive(type: Exec) {
inputs.files(fileTree(dir: "$supportRootFolder/navigation",
@@ -40,4 +38,4 @@
compile project(":moar-buildSrc")
}
-tasks["build"].dependsOn unzip
\ No newline at end of file
+tasks["build"].dependsOn unzip