Skip to content

Commit

Permalink
add Config
Browse files Browse the repository at this point in the history
  • Loading branch information
mhammond committed Jan 16, 2025
1 parent e23059e commit a8e7017
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 29 deletions.
14 changes: 7 additions & 7 deletions build-scripts/component-common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
ndkVersion rootProject.ext.build.ndkVersion
compileSdkVersion rootProject.ext.build.compileSdkVersion

defaultConfig {
minSdkVersion rootProject.ext.build['minSdkVersion']
targetSdkVersion rootProject.ext.build['targetSdkVersion']
ndkVersion config.ndkVersion
compileSdkVersion config.compileSdkVersion

minSdkVersion config.minSdkVersion
targetSdkVersion config.targetSdkVersion

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
buildConfigField("String", "LIBRARY_VERSION", "\"${rootProject.ext.library.version}\"")
buildConfigField("String", "LIBRARY_VERSION", "\"${config.componentsVersion}\"")
}

buildTypes {
Expand All @@ -39,7 +39,7 @@ android {
}

kotlin {
jvmToolchain(rootProject.ext.build.jvmTargetCompatibility)
jvmToolchain(rootProject.config.jvmTargetCompatibility)
}

dependencies {
Expand Down
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

buildscript {
ext.build = [
ndkVersion: "27.2.12479018", // Keep it in sync in TC Dockerfile.

// In general, we should aim to keep these in sync with AC
compileSdkVersion: 35,
targetSdkVersion: 35,
Expand Down
21 changes: 10 additions & 11 deletions megazords/full/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ apply plugin: 'kotlin-android'
android {
namespace 'org.mozilla.appservices.full_megazord'

ndkVersion rootProject.ext.build.ndkVersion
compileSdkVersion rootProject.ext.build.compileSdkVersion

defaultConfig {
minSdkVersion rootProject.ext.build['minSdkVersion']
targetSdkVersion rootProject.ext.build['targetSdkVersion']
ndkVersion config.ndkVersion
compileSdkVersion config.compileSdkVersion
minSdkVersion config.minSdkVersion
targetSdkVersion config.targetSdkVersion

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
buildConfigField("String", "LIBRARY_VERSION", "\"${rootProject.ext.library.version}\"")
buildConfigField("String", "LIBRARY_VERSION", "\"${config.componentsVersion}\"")
}

buildTypes {
Expand All @@ -29,7 +28,7 @@ android {
}

kotlin {
jvmToolchain(rootProject.ext.build.jvmTargetCompatibility)
jvmToolchain(rootProject.config.jvmTargetCompatibility)
}

// Configurations are a somewhat mysterious Gradle concept. For our purposes, we can treat them
Expand Down Expand Up @@ -104,7 +103,7 @@ cargo {
module = '..'

// The Android NDK API level to target.
apiLevel = rootProject.ext.build['minSdkVersion']
apiLevel = rootProject.config.minSdkVersion

// Where Cargo writes its outputs.
targetDirectory = '../../../target'
Expand All @@ -122,7 +121,7 @@ cargo {
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", rootProject.ext.library.version)
spec.environment("MEGAZORD_VERSION", config.componentsVersion)
}

extraCargoBuildArguments = rootProject.ext.extraCargoBuildArguments
Expand Down Expand Up @@ -159,11 +158,11 @@ afterEvaluate {
extension "LICENSES.md"
}
pom {
groupId = rootProject.ext.library.groupId
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.ext.library.version + (rootProject.hasProperty('local') ? '-' + rootProject.property('local') : '')
version = rootProject.config.componentsVersion + (rootProject.hasProperty('local') ? '-' + rootProject.property('local') : '')
packaging = "jar"

licenses {
Expand Down
4 changes: 2 additions & 2 deletions publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def libUrl = properties.libUrl
def libVcsUrl = properties.libVcsUrl

ext.configurePublish = {
def theGroupId = rootProject.ext.library.groupId
def theGroupId = rootProject.config.componentsGroupId
def theArtifactId = project.ext.artifactId
def theDescription = project.ext.description

Expand Down Expand Up @@ -42,7 +42,7 @@ ext.configurePublish = {
// For mavenLocal publishing workflow, increment the version number every publish.
// We only do this to the .pom file and not in $MEGAZORD_VERSION, because otherwise we
// would need to rebuild the megazord .so on every publish, even if nothing else had changed.
version = rootProject.ext.library.version + (rootProject.hasProperty('local') ? '-' + rootProject.property('local') : '')
version = rootProject.config.componentsVersion + (rootProject.hasProperty('local') ? '-' + rootProject.property('local') : '')
packaging = "aar"

license {
Expand Down
51 changes: 47 additions & 4 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def setupProject(name, projectProps, appServicesRootDir) {
// Expose the rest of the project properties, mostly for validation reasons.
project.ext.configProps = projectProps
project.ext.appServicesRootDir = appServicesRootDir

if (gradle.hasProperty("mozconfig")) {
project.buildDir = "${gradle.mozconfig.topobjdir}/gradle/build/app-services/android/$name"
}
}
}
}
Expand Down Expand Up @@ -98,17 +102,56 @@ def calcGroupId(buildconfig) {
}
}

// This is a copy of the `Config` object used in moz-central (but with the addition of ndkVersion for UniFFI)
// This is only used when not in mozilla-central - on m-c the existing Config class is used.
// In the short term we should keep them in sync.
// Once in moz-central we should remove this.
class Config {
// This "componentsVersion" number is defined in "version.txt" and should follow
// semantic versioning (MAJOR.MINOR.PATCH). See https://semver.org/
public final String componentsVersion
public final String componentsGroupId
public final Integer jvmTargetCompatibility
public final Integer compileSdkVersion
public final Integer minSdkVersion
public final Integer targetSdkVersion
public final String ndkVersion

Config(
String componentsVersion,
String componentsGroupId,
Integer jvmTargetCompatibility,
Integer compileSdkVersion,
Integer minSdkVersion,
Integer targetSdkVersion,
String ndkVersion
) {
this.componentsVersion = componentsVersion
this.componentsGroupId = componentsGroupId
this.jvmTargetCompatibility = jvmTargetCompatibility
this.compileSdkVersion = compileSdkVersion
this.minSdkVersion = minSdkVersion
this.targetSdkVersion = targetSdkVersion
this.ndkVersion = ndkVersion
}
}

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.<value>", and it'll function properly
gradle.rootProject.ext.library = [

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.
version: calcVersion(buildconfig),
groupId: calcGroupId(buildconfig),
]
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.
)
}
6 changes: 3 additions & 3 deletions tools/nimbus-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ repositories {
// any tokens (values wrapped in `@`s) with the value for that key in the tokens object.
processResources {
filter ReplaceTokens, tokens: [
'project.version': rootProject.ext.library.version
'project.version': rootProject.config.componentsVersion
]
}

Expand Down Expand Up @@ -91,10 +91,10 @@ publishing {
from components.java

pom {
groupId = rootProject.ext.library.groupId
groupId = rootProject.config.componentsGroupId
artifactId = archivesBaseName
description = project.ext.description
version = rootProject.ext.library.version + (rootProject.hasProperty('local') ? '-' + rootProject.property('local') : '')
version = rootProject.config.componentsVersion + (rootProject.hasProperty('local') ? '-' + rootProject.property('local') : '')

licenses {
license {
Expand Down
1 change: 1 addition & 0 deletions tools/nimbus-gradle-plugin/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ 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"
// 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.<value>", and it'll function properly
Expand Down

0 comments on commit a8e7017

Please sign in to comment.