Bug 1895781 - Run the App Services and Glean auto-publish scripts in settingsEvaluated. r=nalexander

This lets developers set the `autoPublish.*` properties in
`$topsrcdir/mobile/android/{project}/local.properties`. These will
override the `autoPublish.*` properties in
`$topsrcdir/local.properties` if set.

This commit also refactors the `local.properties` loading logic in
`shared-settings.gradle` to match the style used in the previous
commit.

Differential Revision: https://phabricator.services.mozilla.com/D209896
This commit is contained in:
Lina Butler 2024-05-10 06:21:28 +00:00
parent 903581e523
commit a0c36ffb32

View file

@ -201,48 +201,66 @@ def runCmd(cmd, workingDir, successMessage, captureStdout = true) {
// Local Development overrides
//////////////////////////////////////////////////////////////////////////
def localPropertiesFile = new File(gradle.mozconfig.topsrcdir, "local.properties")
if (localPropertiesFile.canRead()) {
def rootLocalProperties = new File(gradle.mozconfig.topsrcdir, "local.properties").with { localPropertiesFile ->
def localProperties = new Properties()
localPropertiesFile.withInputStream { localProperties.load(it) }
if (localPropertiesFile.canRead()) {
localPropertiesFile.withInputStream { localProperties.load(it) }
}
localProperties
}
[
"autoPublish.application-services.dir",
"autoPublish.glean.dir",
].each { key ->
def relativeOrAbsolutePath = localProperties."$key"
if (relativeOrAbsolutePath != null) {
def autoPublishDir = new File(gradle.mozconfig.topsrcdir).toPath().resolve(relativeOrAbsolutePath)
gradle.ext."localProperties.$key" = autoPublishDir.toString()
[
"autoPublish.application-services.dir",
"autoPublish.glean.dir",
].each { key ->
def relativeOrAbsolutePath = rootLocalProperties."$key"
if (relativeOrAbsolutePath != null) {
def autoPublishDir = new File(gradle.mozconfig.topsrcdir).toPath().resolve(relativeOrAbsolutePath)
gradle.ext."localProperties.$key" = autoPublishDir.toString()
}
}
gradle.settingsEvaluated {
if (gradle.hasProperty("localProperties.autoPublish.application-services.dir")) {
// The project that we're configuring now might have overridden
// the path from `$topsrcdir/local.properties`, so we need to
// resolve it again.
def appServicesLocalPath = gradle."localProperties.autoPublish.application-services.dir".with { relativeOrAbsolutePath ->
def absolutePath = rootDir.toPath().resolve(relativeOrAbsolutePath).toString()
gradle."localProperties.autoPublish.application-services.dir" = absolutePath
absolutePath
}
}
}
if (gradle.hasProperty("localProperties.autoPublish.application-services.dir")) {
def appServicesLocalPath = gradle."localProperties.autoPublish.application-services.dir"
logger.lifecycle("settings.gradle> Enabling automatic publication of application-services from: $appServicesLocalPath")
// Windows can't execute .py files directly, so we assume a "manually installed" python,
// which comes with a "py" launcher and respects the shebang line to specify the version.
def publishAppServicesCmd = [];
if (System.properties["os.name"].toLowerCase().contains("windows")) {
publishAppServicesCmd << "py";
logger.lifecycle("settings.gradle> Enabling automatic publication of application-services from: $appServicesLocalPath")
// Windows can't execute .py files directly, so we assume a "manually installed" python,
// which comes with a "py" launcher and respects the shebang line to specify the version.
def publishAppServicesCmd = [];
if (System.properties["os.name"].toLowerCase().contains("windows")) {
publishAppServicesCmd << "py";
}
publishAppServicesCmd << "./automation/publish_to_maven_local_if_modified.py";
runCmd(publishAppServicesCmd, appServicesLocalPath, "Published application-services for local development.", false)
} else {
logger.lifecycle("settings.gradle> Disabled auto-publication of application-services. Enable it by settings 'autoPublish.application-services.dir' in local.properties")
}
publishAppServicesCmd << "./automation/publish_to_maven_local_if_modified.py";
runCmd(publishAppServicesCmd, appServicesLocalPath, "Published application-services for local development.", false)
} else {
logger.lifecycle("settings.gradle> Disabled auto-publication of application-services. Enable it by settings 'autoPublish.application-services.dir' in local.properties")
}
if (gradle.hasProperty("localProperties.autoPublish.glean.dir")) {
def gleanLocalPath = gradle."localProperties.autoPublish.glean.dir"
logger.lifecycle("settings.gradle> Enabling automatic publication of Glean from: $gleanLocalPath")
// As above, hacks to execute .py files on Windows.
def publishGleanCmd = [];
if (System.properties["os.name"].toLowerCase().contains("windows")) {
publishGleanCmd << "py";
if (gradle.hasProperty("localProperties.autoPublish.glean.dir")) {
// As above, absolutize the path.
def gleanLocalPath = gradle."localProperties.autoPublish.glean.dir".with { relativeOrAbsolutePath ->
def absolutePath = rootDir.toPath().resolve(relativeOrAbsolutePath).toString()
gradle."localProperties.autoPublish.glean.dir" = absolutePath
absolutePath
}
logger.lifecycle("settings.gradle> Enabling automatic publication of Glean from: $gleanLocalPath")
// As above, hacks to execute .py files on Windows.
def publishGleanCmd = [];
if (System.properties["os.name"].toLowerCase().contains("windows")) {
publishGleanCmd << "py";
}
publishGleanCmd << "./build-scripts/publish_to_maven_local_if_modified.py";
runCmd(publishGleanCmd, gleanLocalPath, "Published Glean for local development.", false)
} else {
logger.lifecycle("settings.gradle> Disabled auto-publication of Glean. Enable it by settings 'autoPublish.glean.dir' in local.properties")
}
publishGleanCmd << "./build-scripts/publish_to_maven_local_if_modified.py";
runCmd(publishGleanCmd, gleanLocalPath, "Published Glean for local development.", false)
} else {
logger.lifecycle("settings.gradle> Disabled auto-publication of Glean. Enable it by settings 'autoPublish.glean.dir' in local.properties")
}