Commit 93730466 authored by Georg Koppen's avatar Georg Koppen Committed by brizental
Browse files

[android] Modify build system

Bug 40083: Make locale ordering in BuildConfig deterministic

Bug 40042: Add option do overwrite timestamp in extension version

Bug 40059: Use MOZ_BUILD_DATE for versionCode

At the same time we adapt MOZ_BUILD_DATE to our needs where it is
actually used and not in tor-browser-build. This gives us more
flexibility. See: tor-browser-build#40084.

Bug 40067: Fix reproducibility issue in classes2.dex

We make sure our MOZ_BUILD_DATE gets used as a source for showing date
related information on the Fenix about page.

Bug 40071: Show only supported locales

Bug 40064: Use Gecko Beta for Nightly and Debug variants

Bug 40123: Allow building the instrumented tests apks for variants other than debug

This allows to specify the variant of the instrumented tests via
a `testBuildType` gradle argument. It also applies a workaround for
a R8 issue from https://issuetracker.google.com/issues/140851070.

Bug 40143: Use deterministic date in Test apk

The build config was using Date() when generating the Test apk's
versionName.
parent 44cb776b
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -422,3 +422,11 @@ CLAUDE.local.md

# Ignore binary base of Tor Browser
.binaries

# Other files modified at build time
mobile/android/.experimenter.json

# Tor libraries for local builds
mobile/android/fenix/app/tor-expert-bundle.aar
mobile/android/fenix/app/src/main/assets/extensions/{73a6fe31-595d-460b-a920-fcc0f8843232}.xpi
+7 −2
Original line number Diff line number Diff line
@@ -21,7 +21,12 @@ object Config {

    @JvmStatic
    private fun generateDebugVersionName(): String {
        val today = Date()
        val today = if (System.getenv("MOZ_BUILD_DATE") != null) {
            val format = SimpleDateFormat("yyyyMMddHHmmss", Locale.US)
            format.parse(System.getenv("MOZ_BUILD_DATE"))
        } else {
            Date()
        }
        // Append the year (2 digits) and week in year (2 digits). This will make it easier to distinguish versions and
        // identify ancient versions when debugging issues. However this will still keep the same version number during
        // the week so that we do not end up with a lot of versions in tools like Sentry. As an extra this matches the
@@ -60,7 +65,7 @@ object Config {
    private val fennecBaseVersionCode by lazy {
        val format = SimpleDateFormat("yyyyMMddHHmmss", Locale.US)
        val cutoff = format.parse("20141228000000")
        val build = Date()
        val build = if (System.getenv("MOZ_BUILD_DATE") != null) format.parse(System.getenv("MOZ_BUILD_DATE")) else Date()

        Math.floor((build.time - cutoff.time) / (1000.0 * 60.0 * 60.0)).toInt()
    }
+16 −2
Original line number Diff line number Diff line
@@ -290,10 +290,16 @@ androidComponents {
    onVariants(selector().all()) { variant ->
        def buildType = variant.buildType

        // When this is set, a-s doesn't attempt to download NIMBUS_FML.
        if (gradle.mozconfig.substs.NIMBUS_FML) {
            System.setProperty("nimbusFml",  gradle.mozconfig.substs.NIMBUS_FML)
        }

        project.logger.debug("----------------------------------------------")
        project.logger.debug("Variant name:      " + variant.name)
        project.logger.debug("Build type:        " + buildType)
        project.logger.debug("Flavor:            " + variant.flavorName)
        project.logger.debug("nimbusFml:         " + providers.gradleProperty("nimbusFml").getOrNull())

        // This list must stay in sync with the build types that set USE_RELEASE_VERSIONING=true in
        // their buildConfigField. The legacy variant API exposed buildConfigFields on the build type
@@ -782,16 +788,24 @@ def getSupportedLocales() {
    // This isn't running as a task, instead the array is build when the gradle file is parsed.
    // https://github.com/mozilla-mobile/fenix/issues/14175
    def foundLocales = new StringBuilder()
    def languageCodes = []
    foundLocales.append("new String[]{")

    fileTree("src/main/res").visit { FileVisitDetails details ->
        if (details.file.path.endsWith("${File.separator}strings.xml")) {
        if (details.file.path.endsWith("${File.separator}torbrowser_strings.xml")) {
            def languageCode = details.file.parent.tokenize(File.separator).last().replaceAll('values-', '').replaceAll('-r', '-')
            languageCode = (languageCode == "values") ? "en-US" : languageCode
            foundLocales.append("\"").append(languageCode).append("\"").append(",")
            languageCodes.add(languageCode)
        }
    }

    // The order of files in a `FileTree` is not stable, even on a single
    // computer. Thus we need to sort the `languageCode`s. See: fenix#40083.
    languageCodes.sort()
    languageCodes.each {
        foundLocales.append("\"").append(it).append("\"").append(",")
    }

    foundLocales.append("}")
    def foundLocalesString = foundLocales.toString().replaceAll(',}', '}')
    return foundLocalesString
+3 −0
Original line number Diff line number Diff line
@@ -28,3 +28,6 @@

# Keep code generated from Glean Metrics
-keep class org.mozilla.fenix.GleanMetrics.** {  *; }

# Workaround for 'already has mapping' r8 issue (https://issuetracker.google.com/issues/140851070)
-keep class com.google.android.gms.common.internal.BaseGmsClient { *; }
+7 −0
Original line number Diff line number Diff line
#!/bin/bash

echo -e "\033[1;33mThis file is deprecated.\033[0m"
echo "Run ./mach bootstrap and/or define options in your mozconfig from now on."
echo "See documentation at: https://gitlab.torproject.org/tpo/applications/wiki/-/wikis/Development-Information/Firefox-Android/Building"

exit 1
Loading