From 535d001bcc8a2e05b52e048c643afe6e7f26a300 Mon Sep 17 00:00:00 2001 From: Mark Hammond Date: Mon, 23 Dec 2024 14:22:42 -0500 Subject: [PATCH] Getting a-s and m-c almost working with identical gradle files --- build-scripts/component-common.gradle | 9 +- build.gradle | 3 +- megazords/full/android/build.gradle | 180 +++++++++++---------- settings.gradle | 33 ++-- tools/nimbus-gradle-plugin/settings.gradle | 2 +- 5 files changed, 123 insertions(+), 104 deletions(-) diff --git a/build-scripts/component-common.gradle b/build-scripts/component-common.gradle index 5901331f74..9e7550e870 100644 --- a/build-scripts/component-common.gradle +++ b/build-scripts/component-common.gradle @@ -101,6 +101,11 @@ ext.configureUniFFIBindgen = { crateName -> // Call `uniffi-bindgen` to generate the Kotlin bindings def generateUniffiBindings = tasks.register("generateUniffiBindings") { + if (gradle.hasProperty("mozconfig")) { + println("XXX - generateUniffiBindings for crate '$crateName' has been disabled while we work out the monorepo.") + println("XXX - this will cause kotlin compilation errors as it tries to find symbols in the uniffi generated code.") + return + } def megazordNative = configurations.getByName("megazordNative") doFirst { def libraryPath = megazordNative.asFileTree.matching { @@ -130,7 +135,9 @@ ext.configureUniFFIBindgen = { crateName -> def compileTask = tasks["compile${variantName}Kotlin"] compileTask.dependsOn(generateUniffiBindings) - variant.registerJavaGeneratingTask(generateUniffiBindings, megazordNative.singleFile) + if (!gradle.hasProperty("mozconfig")) { // XXX - needs uniffi-bindgen love in m-c + variant.registerJavaGeneratingTask(generateUniffiBindings, megazordNative.singleFile) + } } } } diff --git a/build.gradle b/build.gradle index a16784085c..24931f5ead 100644 --- a/build.gradle +++ b/build.gradle @@ -198,8 +198,7 @@ ext.rustTargets += ext.nativeRustTarget ext.libsRootDir = useDownloadedLibs ? rootProject.buildDir : rootProject.rootDir subprojects { - group = "org.mozilla.appservices" - apply plugin: 'maven-publish' + // Note we apply some plugins to the subprojects in settings.gradle to help with the m-c migration. // Kotlin settings applicable to all modules. afterEvaluate{ diff --git a/megazords/full/android/build.gradle b/megazords/full/android/build.gradle index cf658eebd3..5dab616df1 100644 --- a/megazords/full/android/build.gradle +++ b/megazords/full/android/build.gradle @@ -1,7 +1,10 @@ apply plugin: 'com.android.library' -apply plugin: 'org.mozilla.rust-android-gradle.rust-android' apply plugin: 'kotlin-android' +if (!gradle.hasProperty("mozconfig")) { + apply plugin: 'org.mozilla.rust-android-gradle.rust-android' +} + android { namespace 'org.mozilla.appservices.full_megazord' @@ -69,66 +72,67 @@ dependencies { } } -// Extract JNI dispatch libraries from the JAR into a directory, so that we can then package them -// into our own megazord-desktopLibraries JAR. -def extractLibJniDispatch = tasks.register("extractLibJniDispatch", Copy) { - from zipTree(configurations.jna.singleFile).matching { - include "**/libjnidispatch.*" +if (!gradle.hasProperty("mozconfig")) { + // Extract JNI dispatch libraries from the JAR into a directory, so that we can then package them + // into our own megazord-desktopLibraries JAR. + def extractLibJniDispatch = tasks.register("extractLibJniDispatch", Copy) { + from zipTree(configurations.jna.singleFile).matching { + include "**/libjnidispatch.*" + } + into layout.buildDirectory.dir("libjnidispatch").get() } - into layout.buildDirectory.dir("libjnidispatch").get() -} - -def packageLibsForTest = tasks.register("packageLibsForTest", Jar) { - archiveBaseName = "full-megazord-libsForTests" - from extractLibJniDispatch - from layout.buildDirectory.dir("rustJniLibs/desktop") - dependsOn tasks["cargoBuild${rootProject.ext.nativeRustTarget.capitalize()}"] -} + def packageLibsForTest = tasks.register("packageLibsForTest", Jar) { + archiveBaseName = "full-megazord-libsForTests" -def copyMegazordNative = tasks.register("copyMegazordNative", Copy) { - from layout.buildDirectory.dir("rustJniLibs/desktop") - into layout.buildDirectory.dir("megazordNative") -} + from extractLibJniDispatch + from layout.buildDirectory.dir("rustJniLibs/desktop") + dependsOn tasks["cargoBuild${rootProject.ext.nativeRustTarget.capitalize()}"] + } + def copyMegazordNative = tasks.register("copyMegazordNative", Copy) { + from layout.buildDirectory.dir("rustJniLibs/desktop") + into layout.buildDirectory.dir("megazordNative") + } -artifacts { - // Connect task output to the configurations - libsForTests(packageLibsForTest) - megazordNative(copyMegazordNative) -} + artifacts { + // Connect task output to configurations + libsForTests(packageLibsForTest) + megazordNative(copyMegazordNative) + } -cargo { - // The directory of the Cargo.toml to build. - module = '..' + cargo { + // The directory of the Cargo.toml to build. + module = '..' - // The Android NDK API level to target. - apiLevel = rootProject.config.minSdkVersion + // The Android NDK API level to target. + apiLevel = rootProject.config.minSdkVersion - // Where Cargo writes its outputs. - targetDirectory = '../../../target' + // Where Cargo writes its outputs. + targetDirectory = '../../../target' - libname = 'megazord' + libname = 'megazord' - // The Cargo targets to invoke. The mapping from short name to target - // triple is defined by the `rust-android-gradle` plugin. - targets = rootProject.ext.rustTargets + // The Cargo targets to invoke. The mapping from short name to target + // triple is defined by the `rust-android-gradle` plugin. + targets = rootProject.ext.rustTargets - // Perform release builds (which should have debug info, due to - // `debug = true` in Cargo.toml). - profile = "release" + // Perform release builds (which should have debug info, due to + // `debug = true` in Cargo.toml). + profile = "release" - exec = { spec, toolchain -> - rootProject.ext.cargoExec(spec, toolchain) - // Only used in the full megazord (that is, in this project) at build time. - spec.environment("MEGAZORD_VERSION", config.componentsVersion) - } + exec = { spec, toolchain -> + rootProject.ext.cargoExec(spec, toolchain) + // Only used in the full megazord (that is, in this project) at build time. + spec.environment("MEGAZORD_VERSION", config.componentsVersion) + } - extraCargoBuildArguments = rootProject.ext.extraCargoBuildArguments + extraCargoBuildArguments = rootProject.ext.extraCargoBuildArguments - // Add a build-id so that our code works with simpleperf - // https://bugzilla.mozilla.org/show_bug.cgi?id=1937916 - generateBuildId = true + // Add a build-id so that our code works with simpleperf + // https://bugzilla.mozilla.org/show_bug.cgi?id=1937916 + generateBuildId = true + } } afterEvaluate { @@ -138,57 +142,61 @@ afterEvaluate { variant.productFlavors.each { productFlavor += "${it.name.capitalize()}" } - def buildType = "${variant.buildType.name.capitalize()}" - tasks["merge${productFlavor}${buildType}JniLibFolders"].dependsOn(tasks["cargoBuild"]) + if (!gradle.hasProperty("mozconfig")) { + def buildType = "${variant.buildType.name.capitalize()}" + tasks["merge${productFlavor}${buildType}JniLibFolders"].dependsOn(tasks["cargoBuild"]) + } } } apply from: "$appServicesRootDir/publish.gradle" ext.configurePublish() -afterEvaluate { - publishing { - publications { - // Publish a second package named `full-megazord-libsForTests` to Maven with the - // `libsForTests` output. This contains the same content as our `libsForTests` - // configuration. Publishing it allows the android-components code to depend on it. - libsForTests(MavenPublication) { - artifact tasks['packageLibsForTest'] - artifact file("${projectDir}/../DEPENDENCIES.md"), { - extension "LICENSES.md" - } - pom { - groupId = rootProject.config.componentsGroupId - artifactId = "${project.ext.artifactId}-libsForTests" - description = project.ext.description - // For mavenLocal publishing workflow, increment the version number every publish. - version = rootProject.config.componentsVersion + (rootProject.hasProperty('local') ? '-' + rootProject.property('local') : '') - packaging = "jar" - - licenses { - license { - name = libLicense - url = libLicenseUrl - } +if (!gradle.hasProperty("mozconfig")) { + afterEvaluate { + publishing { + publications { + // Publish a second package named `full-megazord-libsForTests` to Maven with the + // `libsForTests` output. This contains the same content as our `libsForTests` + // configuration. Publishing it allows the android-components code to depend on it. + libsForTests(MavenPublication) { + artifact tasks['packageLibsForTest'] + artifact file("${projectDir}/../DEPENDENCIES.md"), { + extension "LICENSES.md" } + pom { + groupId = rootProject.config.componentsGroupId + artifactId = "${project.ext.artifactId}-libsForTests" + description = project.ext.description + // For mavenLocal publishing workflow, increment the version number every publish. + version = rootProject.config.componentsVersion + (rootProject.hasProperty('local') ? '-' + rootProject.property('local') : '') + packaging = "jar" + + licenses { + license { + name = libLicense + url = libLicenseUrl + } + } - developers { - developer { - name = 'Sync Team' - email = 'sync-team@mozilla.com' + developers { + developer { + name = 'Sync Team' + email = 'sync-team@mozilla.com' + } } - } - scm { - connection = libVcsUrl - developerConnection = libVcsUrl - url = libUrl + scm { + connection = libVcsUrl + developerConnection = libVcsUrl + url = libUrl + } } - } - // This is never the publication we want to use when publishing a - // parent project with us as a child `project()` dependency. - alias = true + // This is never the publication we want to use when publishing a + // parent project with us as a child `project()` dependency. + alias = true + } } } } diff --git a/settings.gradle b/settings.gradle index 2d60c6e448..8cd434f21f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -42,6 +42,10 @@ def setupProject(name, projectProps, appServicesRootDir) { // project(...) gives us a skeleton project that we can't set ext.* on gradle.beforeProject { project -> + // applying this plugin to our sub-projects here makes life much easier for m-c. + // Once in m-c, we can probably just remove all publishing capabilities from these crates entirely? + project.apply plugin: 'maven-publish' + // However, the "afterProject" listener iterates over every project and gives us the actual project // So, once we filter for the project we care about, we can set whatever we want if (project.name == name) { @@ -140,18 +144,19 @@ gradle.projectsLoaded { -> // Wait until root project is "loaded" before we set "config" // Note that since this is set on "rootProject.ext", it will be "in scope" during the evaluation of all projects' // gradle files. This means that they can just access "config.", and it'll function properly - - gradle.rootProject.ext.config = new Config( - // You can use -Plocal=true to help with mavenLocal publishing workflow. - // It makes a fake version number that's smaller than any published version, - // which can be depended on specifically by the ./build-scripts/substitute-local-appservices.gradle - // but which is unlikely to be depended on by accident otherwise. - calcVersion(buildconfig), // version, - calcGroupId(buildconfig), // componentsGroupId - 17, // jvmTargetCompatibility, - 35, // compileSdkVersion, - 21, // minSdkVersion, - 35, // targetSdkVersion, - "27.2.12479018", // ndkVersion - Keep it in sync in TC Dockerfile. - ) + if (!gradle.hasProperty("mozconfig")) { + gradle.rootProject.ext.config = new Config( + // You can use -Plocal=true to help with mavenLocal publishing workflow. + // It makes a fake version number that's smaller than any published version, + // which can be depended on specifically by the ./build-scripts/substitute-local-appservices.gradle + // but which is unlikely to be depended on by accident otherwise. + calcVersion(buildconfig), // version, + calcGroupId(buildconfig), // componentsGroupId + 17, // jvmTargetCompatibility, + 35, // compileSdkVersion, + 21, // minSdkVersion, + 35, // targetSdkVersion, + "27.2.12479018", // ndkVersion - Keep it in sync in TC Dockerfile. + ) + } } diff --git a/tools/nimbus-gradle-plugin/settings.gradle b/tools/nimbus-gradle-plugin/settings.gradle index 269caf97e3..d1d60f15c0 100644 --- a/tools/nimbus-gradle-plugin/settings.gradle +++ b/tools/nimbus-gradle-plugin/settings.gradle @@ -29,8 +29,8 @@ def calcVersion(buildconfig) { } gradle.projectsLoaded { -> - // XXX - the above probably needs to be upgraded to actually use "config"?? // Wait until root project is "loaded" before we set "config" + // XXX - there's no "config" here. This should be upgraded to use the same mechanism as the other components? // Note that since this is set on "rootProject.ext", it will be "in scope" during the evaluation of all projects' // gradle files. This means that they can just access "config.", and it'll function properly gradle.rootProject.ext.library = [