summaryrefslogtreecommitdiffstats
path: root/mobile/android/gradle.configure
blob: 2fc194fa8f85e0343fa793de0e0ac99833e5e1cd (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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.

# If --with-gradle is specified, build mobile/android with Gradle.  If no
# Gradle binary is specified use the in tree Gradle wrapper.  The wrapper
# downloads and installs Gradle, which is good for local developers but not
# good in automation.
option(
    "--without-gradle",
    nargs="?",
    help="Disable building mobile/android with Gradle "
    "(argument: location of binary or wrapper (gradle/gradlew))",
)


@depends("--with-gradle")
def with_gradle(value):
    if not value:
        die(
            "Building --without-gradle is no longer supported: "
            "see https://bugzilla.mozilla.org/show_bug.cgi?id=1414415."
        )

    if value:
        return True


@depends(host, "--with-gradle", check_build_environment)
@imports(_from="os.path", _import="isfile")
def gradle(host, value, build_env):
    if len(value):
        gradle = value[0]
    else:
        gradle = os.path.join(build_env.topsrcdir, "gradlew")
        if host.os == "WINNT":
            gradle = gradle + ".bat"

    # TODO: verify that $GRADLE is executable.
    if not isfile(gradle):
        die("GRADLE must be executable: %s", gradle)

    return gradle


set_config("GRADLE", gradle)


@dependable
@imports(_from="itertools", _import="chain")
def gradle_android_build_config():
    def capitalize(s):
        # str.capitalize lower cases trailing letters.
        if s:
            return s[0].upper() + s[1:]
        else:
            return s

    def variant(productFlavors, buildType):
        return namespace(
            productFlavors=productFlavors,
            buildType=buildType,
            # Like 'WithoutGeckoBinariesDebug'
            name="".join(capitalize(t) for t in chain(productFlavors, (buildType,))),
        )

    return namespace(
        geckoview=namespace(
            variant=variant(("withGeckoBinaries",), "debug"),
        ),
        geckoview_example=namespace(
            variant=variant(("withGeckoBinaries",), "debug"),
        ),
    )


@depends(gradle_android_build_config)
def gradle_android_intermediates_folder(build_config):
    """Path to intermediates classes folder."""

    def uncapitalize(s):
        if s:
            return s[0].lower() + s[1:]
        else:
            return s

    def capitalize(s):
        # str.capitalize lower cases trailing letters.
        if s:
            return s[0].upper() + s[1:]
        else:
            return s

    productFlavor = uncapitalize(
        "".join(capitalize(f) for f in build_config.geckoview.variant.productFlavors)
    )
    buildType = uncapitalize(build_config.geckoview.variant.buildType)

    return "gradle/build/mobile/android/geckoview/intermediates/javac/{}{}/compile{}{}JavaWithJavac/classes".format(
        productFlavor,
        capitalize(buildType),
        capitalize(productFlavor),
        capitalize(buildType),
    )


set_config(
    "GRADLE_ANDROID_GECKOVIEW_APILINT_FOLDER", gradle_android_intermediates_folder
)


@depends(gradle_android_build_config)
def gradle_android_variant_name(build_config):
    """Like "withoutGeckoBinariesDebug"."""

    def uncapitalize(s):
        if s:
            return s[0].lower() + s[1:]
        else:
            return s

    return namespace(
        geckoview=uncapitalize(build_config.geckoview.variant.name),
    )


set_config(
    "GRADLE_ANDROID_GECKOVIEW_VARIANT_NAME", gradle_android_variant_name.geckoview
)


@depends(gradle_android_build_config)
def gradle_android_app_tasks(build_config):
    """Gradle tasks run by |mach android assemble-app|."""
    return [
        "geckoview:generateJNIWrappersForGenerated{geckoview.variant.name}".format(
            geckoview=build_config.geckoview
        ),
    ]


set_config("GRADLE_ANDROID_APP_TASKS", gradle_android_app_tasks)


@dependable
def gradle_android_generate_sdk_bindings_tasks():
    """Gradle tasks run by |mach android generate-sdk-bindings|."""
    return [
        "geckoview:generateSDKBindings",
    ]


set_config(
    "GRADLE_ANDROID_GENERATE_SDK_BINDINGS_TASKS",
    gradle_android_generate_sdk_bindings_tasks,
)


@depends(gradle_android_build_config)
def gradle_android_generate_generated_jni_wrappers_tasks(build_config):
    """Gradle tasks run by |mach android generate-generated-jni-wrappers|."""
    return [
        "geckoview:generateJNIWrappersForGenerated{geckoview.variant.name}".format(
            geckoview=build_config.geckoview
        ),
    ]


set_config(
    "GRADLE_ANDROID_GENERATE_GENERATED_JNI_WRAPPERS_TASKS",
    gradle_android_generate_generated_jni_wrappers_tasks,
)


@depends(gradle_android_build_config)
def gradle_android_test_tasks(build_config):
    """Gradle tasks run by |mach android test|."""
    return [
        "geckoview:test{geckoview.variant.name}UnitTest".format(
            geckoview=build_config.geckoview
        ),
    ]


set_config("GRADLE_ANDROID_TEST_TASKS", gradle_android_test_tasks)


@depends(gradle_android_build_config)
def gradle_android_lint_tasks(build_config):
    """Gradle tasks run by |mach android lint|."""
    return [
        "geckoview:lint{geckoview.variant.name}".format(
            geckoview=build_config.geckoview
        ),
    ]


set_config("GRADLE_ANDROID_LINT_TASKS", gradle_android_lint_tasks)


@depends(gradle_android_build_config)
def gradle_android_api_lint_tasks(build_config):
    """Gradle tasks run by |mach android api-lint|."""
    return [
        "geckoview:apiLint{geckoview.variant.name}".format(
            geckoview=build_config.geckoview
        ),
    ]


set_config("GRADLE_ANDROID_API_LINT_TASKS", gradle_android_api_lint_tasks)


@depends(gradle_android_build_config)
def gradle_android_checkstyle_tasks(build_config):
    """Gradle tasks run by |mach android checkstyle|."""
    return [
        "geckoview:checkstyle{geckoview.variant.name}".format(
            geckoview=build_config.geckoview
        ),
    ]


set_config("GRADLE_ANDROID_CHECKSTYLE_TASKS", gradle_android_checkstyle_tasks)


@depends(gradle_android_build_config)
def gradle_android_checkstyle_output_files(build_config):
    def uncapitalize(s):
        if s:
            return s[0].lower() + s[1:]
        else:
            return s

    variant = uncapitalize(build_config.geckoview.variant.name)

    """Output folder for checkstyle"""
    return [
        "gradle/build/mobile/android/geckoview/reports/checkstyle/{}.xml".format(
            variant
        ),
    ]


set_config(
    "GRADLE_ANDROID_CHECKSTYLE_OUTPUT_FILES", gradle_android_checkstyle_output_files
)


@depends(gradle_android_build_config)
def gradle_android_archive_geckoview_tasks(build_config):
    """Gradle tasks run by |mach android archive-geckoview|."""
    return [
        "geckoview:assemble{geckoview.variant.name}".format(
            geckoview=build_config.geckoview
        ),
        "geckoview:assemble{geckoview.variant.name}AndroidTest".format(
            geckoview=build_config.geckoview
        ),
        "geckoview_example:assemble{geckoview_example.variant.name}".format(
            geckoview_example=build_config.geckoview_example
        ),
        "messaging_example:assemble{geckoview_example.variant.name}".format(
            geckoview_example=build_config.geckoview_example
        ),
        "port_messaging_example:assemble{geckoview_example.variant.name}".format(
            geckoview_example=build_config.geckoview_example
        ),
        "geckoview:publish{geckoview.variant.name}PublicationToMavenRepository".format(
            geckoview=build_config.geckoview
        ),
    ]


set_config(
    "GRADLE_ANDROID_ARCHIVE_GECKOVIEW_TASKS", gradle_android_archive_geckoview_tasks
)


@depends(gradle_android_build_config)
def gradle_android_geckoview_docs_tasks(build_config):
    """Gradle tasks run by |mach android geckoview-docs|."""
    return [
        "geckoview:javadoc{geckoview.variant.name}".format(
            geckoview=build_config.geckoview
        ),
    ]


set_config("GRADLE_ANDROID_GECKOVIEW_DOCS_TASKS", gradle_android_geckoview_docs_tasks)


@depends(gradle_android_build_config)
def gradle_android_geckoview_docs_archive_tasks(build_config):
    """Gradle tasks run by |mach android geckoview-docs --archive| or |... --upload."""
    return [
        "geckoview:javadocCopyJar{geckoview.variant.name}".format(
            geckoview=build_config.geckoview
        ),
    ]


set_config(
    "GRADLE_ANDROID_GECKOVIEW_DOCS_ARCHIVE_TASKS",
    gradle_android_geckoview_docs_archive_tasks,
)


@depends(gradle_android_build_config)
def gradle_android_geckoview_docs_output_files(build_config):
    """Output files for GeckoView javadoc."""

    def uncapitalize(s):
        if s:
            return s[0].lower() + s[1:]
        else:
            return s

    variant = uncapitalize(build_config.geckoview.variant.name)

    return [
        "gradle/build/mobile/android/geckoview/reports/javadoc-results-{}.json".format(
            variant
        ),
    ]


set_config(
    "GRADLE_ANDROID_GECKOVIEW_DOCS_OUTPUT_FILES",
    gradle_android_geckoview_docs_output_files,
)


@depends(gradle_android_build_config)
def gradle_android_archive_coverage_artifacts_tasks(build_config):
    """Gradle tasks run by |mach android archive-coverage-artifacts|."""
    return [
        "geckoview:archiveClassfiles{geckoview.variant.name}".format(
            geckoview=build_config.geckoview
        ),
        "geckoview:copyCoverageDependencies",
    ]


set_config(
    "GRADLE_ANDROID_ARCHIVE_COVERAGE_ARTIFACTS_TASKS",
    gradle_android_archive_coverage_artifacts_tasks,
)


@depends(gradle_android_build_config)
def gradle_android_build_geckoview_example_tasks(build_config):
    """Gradle tasks run by |mach android build-geckoview_example|."""
    return [
        "geckoview_example:assemble{geckoview_example.variant.name}".format(
            geckoview_example=build_config.geckoview_example
        ),
        "geckoview:assemble{geckoview.variant.name}AndroidTest".format(
            geckoview=build_config.geckoview
        ),
    ]


set_config(
    "GRADLE_ANDROID_BUILD_GECKOVIEW_EXAMPLE_TASKS",
    gradle_android_build_geckoview_example_tasks,
)


@depends(gradle_android_build_config)
def gradle_android_install_geckoview_example_tasks(build_config):
    """Gradle tasks run by |mach android install-geckoview_example|."""
    return [
        "geckoview_example:install{geckoview_example.variant.name}".format(
            geckoview_example=build_config.geckoview_example
        ),
        "geckoview:install{geckoview.variant.name}AndroidTest".format(
            geckoview=build_config.geckoview
        ),
    ]


set_config(
    "GRADLE_ANDROID_INSTALL_GECKOVIEW_EXAMPLE_TASKS",
    gradle_android_install_geckoview_example_tasks,
)


@dependable
def gradle_android_dependencies():
    """Gradle tasks that download all dependencies."""
    # These tasks download most dependencies from each configuration, the
    # notable exception is dependencies added at runtime by gradle plugins
    return [
        "downloadDependencies",
    ]


@depends(
    gradle_android_api_lint_tasks,
    gradle_android_checkstyle_tasks,
    gradle_android_dependencies,
)
@imports(_from="itertools", _import="chain")
def gradle_android_dependencies_tasks(*tasks):
    """Gradle tasks run by |mach android dependencies|."""
    # The union, plus a bit more, of all of the Gradle tasks
    # invoked by the android-* automation jobs.
    def withoutGeckoBinaries(task):
        return task.replace("withGeckoBinaries", "withoutGeckoBinaries")

    return list(withoutGeckoBinaries(t) for t in chain(*tasks))


set_config("GRADLE_ANDROID_DEPENDENCIES_TASKS", gradle_android_dependencies_tasks)


# Automation uses this to change log levels, not use the daemon, and use
# offline mode.
option(env="GRADLE_FLAGS", default="", help="Flags to pass to Gradle.")


@depends("GRADLE_FLAGS")
def gradle_flags(value):
    return value[0] if value else ""


set_config("GRADLE_FLAGS", gradle_flags)

# Automation will set this to (file:///path/to/local, ...) via the mozconfig.
# Local developer default is (jcenter, maven.google.com).
option(
    env="GRADLE_MAVEN_REPOSITORIES",
    nargs="+",
    default=(
        "https://maven.google.com/",
        "https://jcenter.bintray.com/",
        "https://plugins.gradle.org/m2/",
    ),
    help="Comma-separated URLs of Maven repositories containing Gradle dependencies.",
)


@depends("GRADLE_MAVEN_REPOSITORIES")
@imports(_from="os.path", _import="isdir")
def gradle_maven_repositories(values):
    if not values:
        die("GRADLE_MAVEN_REPOSITORIES must not be empty")
    if not all(values):
        die("GRADLE_MAVEN_REPOSITORIES entries must not be empty")
    return values


set_config("GRADLE_MAVEN_REPOSITORIES", gradle_maven_repositories)