summaryrefslogtreecommitdiffstats
path: root/mobile/android/fenix/settings.gradle
blob: 9c1fa496b363fbba9b0aa367ef800d9b4e2e8a8e (plain)
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
/* 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/. */

pluginManagement {
    apply from: file('../gradle/mozconfig.gradle')

    repositories {
        gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
            maven {
                url repository
                if (gradle.mozconfig.substs.ALLOW_INSECURE_GRADLE_REPOSITORIES) {
                    allowInsecureProtocol = true
                }
            }
        }
    }

    includeBuild("../android-components/plugins/publicsuffixlist")
    includeBuild("../android-components/plugins/dependencies")
    includeBuild("../android-components/plugins/config")
    includeBuild("./plugins/apksize")
    includeBuild("./plugins/fenixdependencies")
}

plugins {
    id 'ApkSizePlugin'
    id 'FenixDependenciesPlugin'
    id "mozac.ConfigPlugin"
    id 'mozac.DependenciesPlugin'
}

ext.topsrcdir = rootProject.projectDir.absolutePath.minus("mobile/android/fenix")

apply from: file('../shared-settings.gradle')

include ':app'
include ':mozilla-detekt-rules'
include ':mozilla-lint-rules'
include ':benchmark'

gradle.projectsLoaded { ->
    // Disables A-C tests and lint when building Fenix.
    gradle.allprojects { project ->
        if (project.projectDir.absolutePath.contains("/android-components/")) {
            project.tasks.withType(Test).configureEach {
                enabled = false
            }
            project.tasks.configureEach { task ->
                if (task.name.contains("lint")) {
                    task.enabled = false
                }
            }
        }

        def appServicesSrcDir = null
        if (gradle.hasProperty('localProperties.autoPublish.application-services.dir')) {
          appServicesSrcDir = gradle.getProperty('localProperties.autoPublish.application-services.dir')
        } else if (gradle.hasProperty('localProperties.branchBuild.application-services.dir')) {
          appServicesSrcDir = gradle.getProperty('localProperties.branchBuild.application-services.dir')
        }
        if (appServicesSrcDir) {
            if (appServicesSrcDir.startsWith("/")) {
                apply from: "${appServicesSrcDir}/build-scripts/substitute-local-appservices.gradle"
            } else {
                apply from: "${rootProject.projectDir}/${appServicesSrcDir}/build-scripts/substitute-local-appservices.gradle"
            }
        }
    }
}

def log(message) {
    logger.lifecycle("[settings] ${message}")
}

def runCmd(cmd, workingDir, successMessage, captureStdout=true) {
    def proc = cmd.execute(null, new File(workingDir))
    def standardOutput = captureStdout ? new ByteArrayOutputStream() : System.out
    proc.consumeProcessOutput(standardOutput, System.err)
    proc.waitFor()

    if (proc.exitValue() != 0) {
        throw new GradleException("Process '${cmd}' finished with non-zero exit value ${proc.exitValue()}");
    } else {
        log(successMessage)
    }
    return captureStdout ? standardOutput : null
}

//////////////////////////////////////////////////////////////////////////
// Local Development overrides
//////////////////////////////////////////////////////////////////////////

Properties localProperties = null
String settingAppServicesPath = "autoPublish.application-services.dir"
String settingGleanPath = "autoPublish.glean.dir"

if (file('local.properties').canRead()) {
    localProperties = new Properties()
    localProperties.load(file('local.properties').newDataInputStream())
    log('Loaded local.properties')
} else {
    log('Missing local.properties; see https://github.com/mozilla-mobile/fenix/blob/main/README.md#local-properties-helpers for instructions.')
}

if (localProperties != null) {
    localProperties.each { prop ->
        gradle.ext.set("localProperties.${prop.key}", prop.value)
    }

    String appServicesLocalPath = localProperties.getProperty(settingAppServicesPath)

    if (appServicesLocalPath != null) {
        log("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 {
        log("Disabled auto-publication of application-services. Enable it by settings '$settingAppServicesPath' in local.properties")
    }

    String gleanLocalPath = localProperties.getProperty(settingGleanPath)

    if (gleanLocalPath != null) {
        log("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 {
        log("Disabled auto-publication of Glean. Enable it by settings '$settingGleanPath' in local.properties")
    }
}