File: shared-settings.gradle

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (185 lines) | stat: -rw-r--r-- 8,000 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


import org.yaml.snakeyaml.Yaml

import java.time.format.DateTimeFormatter

buildscript {
    if (!gradle.root.hasProperty("mozconfig")){
        apply from: file('./gradle/mozconfig.gradle')
    } else {
        gradle.ext.mozconfig = gradle.root.mozconfig
        gradle.ext.configureMavenRepositories = gradle.root.ext.configureMavenRepositories
    }

    repositories {
        gradle.configureMavenRepositories(delegate)
    }

    dependencies {
        classpath 'org.yaml:snakeyaml:2.2'
    }
}

if (!gradle.root.hasProperty("mozconfig")){
    apply from: file('./gradle/mozconfig.gradle')
} else {
    gradle.ext.mozconfig = gradle.root.mozconfig
    gradle.ext.configureMavenRepositories = gradle.root.ext.configureMavenRepositories
}

// Synchronized library configuration for all modules
// This "componentsVersion" number is defined in "version.txt" and should follow
// semantic versioning (MAJOR.MINOR.PATCH). See https://semver.org/
class Config {

    public final String componentsVersion
    public final String componentsGroupId
    public final Integer jvmTargetCompatibility
    public final Integer compileSdkMajorVersion
    public final Integer compileSdkMinorVersion
    public final Integer minSdkVersion
    public final Integer targetSdkVersion
    public final String ndkVersion


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

// Mimic Python: open(os.path.join(buildconfig.topobjdir, 'buildid.h')).readline().split()[2]
def getBuildId() {
    if (System.env.MOZ_BUILD_DATE) {
        if (System.env.MOZ_BUILD_DATE.length() == 14) {
            return System.env.MOZ_BUILD_DATE
        }
        logger.warn("Ignoring invalid MOZ_BUILD_DATE: ${System.env.MOZ_BUILD_DATE}")
    }
    return file("${gradle.mozconfig.topobjdir}/buildid.h").getText('utf-8').split()[2]
}

// Return a manifest version string that respects the Firefox version format,
// see: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/version#version_format
def getManifestVersionString(componentsVersion) {
    // We assume that the `version.txt` file will always contain a version
    // string with at least two parts separated with a dot. Below, we extract
    // each part, and we make sure that there is no letter, e.g. `"0a2"` would
    // become `"0"`.
    String[] parts = componentsVersion.split("\\.").collect {
        part -> part.split("a|b")[0]
    };

    // Per https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/version,
    // each part can have up to 9 digits.  Note the single `H` when formatting the output avoid
    // leading zeros, which are not allowed.
    def buildDate = LocalDateTime.parse(getBuildId(), DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))
    def dateAndTime = buildDate.format(DateTimeFormatter.ofPattern("YYYYMMdd.Hmmss"));

    return "${parts[0]}.${parts[1]}.${dateAndTime}";
}

gradle.projectsLoaded { ->
    def versionFile = new File(gradle.mozconfig.topsrcdir, "mobile/android/version.txt")
    String version = versionFile.text.stripTrailing()

    def yaml = new Yaml()
    def configDataFile = new File(gradle.mozconfig.topsrcdir, "mobile/android/android-components/.config.yml")
    def configData = yaml.load(configDataFile.newInputStream())

    if (gradle.rootProject.hasProperty("nightlyVersion")) {
        version = gradle.rootProject.nightlyVersion
    } else if (gradle.rootProject.hasProperty("local")) {
        // To support local auto-publication workflow, we use a version prefix we wouldn't normally encounter.
        version = "0.0.1"
    } else if (gradle.hasProperty("localProperties.branchBuild.android-components.version")) {
        version = gradle.getProperty("localProperties.branchBuild.android-components.version")
    }
    // get the ndk version from the external build environment.
    def ndkVersion = "${gradle.mozconfig.substs.ANDROID_NDK_MAJOR_VERSION}.${gradle.mozconfig.substs.ANDROID_NDK_MINOR_VERSION}"

    // 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.config = new Config(
            version,
            configData.componentsGroupId,
            configData.jvmTargetCompatibility,
            configData.compileSdkMajorVersion,
            configData.compileSdkMinorVersion,
            configData.minSdkVersion,
            configData.targetSdkVersion,
            ndkVersion
    )

    // Define a reusable task for updating the version in manifest.json for modules that package
    // a web extension. We automate this to make sure we never forget to update the version, either
    // in local development or for releases. In both cases, we want to make sure the latest version
    // of all extensions (including their latest changes) are installed on first start-up.
    gradle.rootProject.allprojects {
        ext.updateExtensionVersion = { task, extDir ->
            configure(task) {
                from extDir
                include 'manifest.template.json'
                rename { 'manifest.json' }
                into extDir

                def values = ['version': getManifestVersionString(rootProject.ext.config.componentsVersion)]
                inputs.properties(values)
                expand(values)
            }
        }
    }

    // Initialize all project buildDirs to be in ${topobjdir} to follow
    // conventions of mozilla-central build system.
    gradle.rootProject.allprojects { project ->
        def topSrcPath = file(gradle.mozconfig.topsrcdir).toPath()
        def topObjPath = file(gradle.mozconfig.topobjdir).toPath()

        def sourcePath = project.getBuildFile().toPath().getParent()
        def relativePath = topSrcPath.relativize(sourcePath)

        if (relativePath.startsWith("..")) {
            // The project doesn't appear to be in topsrcdir so leave the
            // buildDir alone.
        } else {
            // Transplant the project path into "${topobjdir}/gradle/build".
            // This is consistent with existing gradle / taskcluster
            // configurations but less consistent with the result of the
            // non-gradle build system.
            project.layout.buildDirectory.set(topObjPath.resolve("gradle/build").resolve(relativePath).toFile())
        }
    }

    // This explicitly disables stripping of native libraries in our projects to match the existing
    // implicit behaviour. Our projects do not specify the `ndkVersion` for our main Android builds
    // and so stripping would otherwise fail with a warning. Note that gecko builds themselves will
    // already strip the *.so files when compiled as release targets.
    gradle.rootProject.allprojects { project ->
        project.afterEvaluate {
            if (it.hasProperty('android')) {
                android.packagingOptions.jniLibs.keepDebugSymbols += "**/*.so"
            }
        }
    }
}