1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 # If --with-gradle is specified, build mobile/android with Gradle. If no
8 # Gradle binary is specified use the in tree Gradle wrapper. The wrapper
9 # downloads and installs Gradle, which is good for local developers but not
14 help="Disable building mobile/android with Gradle "
15 "(argument: location of binary or wrapper (gradle/gradlew))",
19 @depends("--with-gradle")
20 def with_gradle(value):
23 "Building --without-gradle is no longer supported: "
24 "see https://bugzilla.mozilla.org/show_bug.cgi?id=1414415."
31 @depends(host, "--with-gradle", build_environment)
32 @imports(_from="os.path", _import="isfile")
33 def gradle(host, value, build_env):
37 gradle = os.path.join(build_env.topsrcdir, "gradlew")
38 if host.os == "WINNT":
39 gradle = gradle + ".bat"
41 # TODO: verify that $GRADLE is executable.
42 if not isfile(gradle):
43 die("GRADLE must be executable: %s", gradle)
48 set_config("GRADLE", gradle)
52 @imports(_from="itertools", _import="chain")
53 def gradle_android_build_config():
55 # str.capitalize lower cases trailing letters.
57 return s[0].upper() + s[1:]
61 def variant(productFlavors, buildType):
63 productFlavors=productFlavors,
65 # Like 'WithoutGeckoBinariesDebug'
66 name="".join(capitalize(t) for t in chain(productFlavors, (buildType,))),
71 variant=variant(("withGeckoBinaries",), "debug"),
73 geckoview_example=namespace(
74 variant=variant(("withGeckoBinaries",), "debug"),
79 @depends(gradle_android_build_config)
80 def gradle_android_intermediates_folder(build_config):
81 """Path to intermediates classes folder."""
85 return s[0].lower() + s[1:]
90 # str.capitalize lower cases trailing letters.
92 return s[0].upper() + s[1:]
96 productFlavor = uncapitalize(
97 "".join(capitalize(f) for f in build_config.geckoview.variant.productFlavors)
99 buildType = uncapitalize(build_config.geckoview.variant.buildType)
102 "gradle/build/mobile/android/geckoview/intermediates/javac/{}{}/classes".format(
104 capitalize(buildType),
110 "GRADLE_ANDROID_GECKOVIEW_APILINT_FOLDER", gradle_android_intermediates_folder
114 @depends(gradle_android_build_config)
115 def gradle_android_geckoview_test_runner_bundle(build_config):
116 """Path to intermediates classes folder."""
120 return s[0].lower() + s[1:]
125 # str.capitalize lower cases trailing letters.
127 return s[0].upper() + s[1:]
131 productFlavor = uncapitalize(
132 "".join(capitalize(f) for f in build_config.geckoview.variant.productFlavors)
134 buildType = uncapitalize(build_config.geckoview.variant.buildType)
135 variant = uncapitalize(build_config.geckoview.variant.name)
137 return "gradle/build/mobile/android/test_runner/outputs/bundle/{}/test_runner-{}-{}.aab".format(
145 "GRADLE_ANDROID_GECKOVIEW_TEST_RUNNER_BUNDLE",
146 gradle_android_geckoview_test_runner_bundle,
150 @depends(gradle_android_build_config)
151 def gradle_android_geckoview_example_bundle(build_config):
152 """Path to intermediates classes folder."""
156 return s[0].lower() + s[1:]
161 # str.capitalize lower cases trailing letters.
163 return s[0].upper() + s[1:]
167 productFlavor = uncapitalize(
168 "".join(capitalize(f) for f in build_config.geckoview.variant.productFlavors)
170 buildType = uncapitalize(build_config.geckoview.variant.buildType)
171 variant = uncapitalize(build_config.geckoview.variant.name)
173 return "gradle/build/mobile/android/geckoview_example/outputs/bundle/{}/geckoview_example-{}-{}.aab".format(
181 "GRADLE_ANDROID_GECKOVIEW_EXAMPLE_BUNDLE", gradle_android_geckoview_example_bundle
185 @depends(gradle_android_build_config)
186 def gradle_android_variant_name(build_config):
187 """Like "withoutGeckoBinariesDebug"."""
191 return s[0].lower() + s[1:]
196 geckoview=uncapitalize(build_config.geckoview.variant.name),
201 "GRADLE_ANDROID_GECKOVIEW_VARIANT_NAME", gradle_android_variant_name.geckoview
205 @depends(gradle_android_build_config)
206 def gradle_android_app_tasks(build_config):
207 """Gradle tasks run by |mach android assemble-app|."""
209 "geckoview:generateJNIWrappersForGenerated{geckoview.variant.name}".format(
210 geckoview=build_config.geckoview
215 set_config("GRADLE_ANDROID_APP_TASKS", gradle_android_app_tasks)
219 def gradle_android_generate_sdk_bindings_tasks():
220 """Gradle tasks run by |mach android generate-sdk-bindings|."""
222 "geckoview:generateSDKBindings",
227 "GRADLE_ANDROID_GENERATE_SDK_BINDINGS_TASKS",
228 gradle_android_generate_sdk_bindings_tasks,
232 @depends(gradle_android_build_config)
233 def gradle_android_generate_generated_jni_wrappers_tasks(build_config):
234 """Gradle tasks run by |mach android generate-generated-jni-wrappers|."""
236 "geckoview:generateJNIWrappersForGenerated{geckoview.variant.name}".format(
237 geckoview=build_config.geckoview
243 "GRADLE_ANDROID_GENERATE_GENERATED_JNI_WRAPPERS_TASKS",
244 gradle_android_generate_generated_jni_wrappers_tasks,
248 @depends(gradle_android_build_config)
249 def gradle_android_test_tasks(build_config):
250 """Gradle tasks run by |mach android test|."""
252 "geckoview:test{geckoview.variant.name}UnitTest".format(
253 geckoview=build_config.geckoview
258 set_config("GRADLE_ANDROID_TEST_TASKS", gradle_android_test_tasks)
261 @depends(gradle_android_build_config)
262 def gradle_android_lint_tasks(build_config):
263 """Gradle tasks run by |mach android lint|."""
265 "geckoview:lint{geckoview.variant.name}".format(
266 geckoview=build_config.geckoview
271 set_config("GRADLE_ANDROID_LINT_TASKS", gradle_android_lint_tasks)
274 @depends(gradle_android_build_config)
275 def gradle_android_api_lint_tasks(build_config):
276 """Gradle tasks run by |mach android api-lint|."""
278 "geckoview:apiLint{geckoview.variant.name}".format(
279 geckoview=build_config.geckoview
284 set_config("GRADLE_ANDROID_API_LINT_TASKS", gradle_android_api_lint_tasks)
288 "GRADLE_ANDROID_FORMAT_LINT_FIX_TASKS", ["spotlessJavaApply", "spotlessKotlinApply"]
293 def gradle_android_format_lint_check_tasks():
294 return ["spotlessJavaCheck", "spotlessKotlinCheck"]
298 "GRADLE_ANDROID_FORMAT_LINT_CHECK_TASKS", gradle_android_format_lint_check_tasks
302 "GRADLE_ANDROID_FORMAT_LINT_FOLDERS",
304 "mobile/android/annotations",
305 "mobile/android/geckoview",
306 "mobile/android/geckoview_example",
307 "mobile/android/test_runner",
308 "mobile/android/examples/messaging_example",
309 "mobile/android/examples/port_messaging_example",
314 @depends(gradle_android_build_config)
315 def gradle_android_checkstyle_tasks(build_config):
316 """Gradle tasks run by |mach android checkstyle|."""
318 "geckoview:checkstyle{geckoview.variant.name}".format(
319 geckoview=build_config.geckoview
324 set_config("GRADLE_ANDROID_CHECKSTYLE_TASKS", gradle_android_checkstyle_tasks)
327 @depends(gradle_android_build_config)
328 def gradle_android_checkstyle_output_files(build_config):
331 return s[0].lower() + s[1:]
335 variant = uncapitalize(build_config.geckoview.variant.name)
337 """Output folder for checkstyle"""
339 "gradle/build/mobile/android/geckoview/reports/checkstyle/{}.xml".format(
346 "GRADLE_ANDROID_CHECKSTYLE_OUTPUT_FILES", gradle_android_checkstyle_output_files
351 "--disable-android-bundle",
352 help="{Enable|Disable} AAB build.",
355 imply_option("--disable-android-bundle", False, when="--enable-address-sanitizer")
358 @depends(gradle_android_build_config, "--disable-android-bundle")
359 def gradle_android_archive_geckoview_tasks(build_config, aab_enabled):
360 """Gradle tasks run by |mach android archive-geckoview|."""
362 "geckoview:assemble{geckoview.variant.name}".format(
363 geckoview=build_config.geckoview
365 "geckoview:assemble{geckoview.variant.name}AndroidTest".format(
366 geckoview=build_config.geckoview
368 "test_runner:assemble{geckoview_example.variant.name}".format(
369 geckoview_example=build_config.geckoview_example
371 "geckoview_example:assemble{geckoview_example.variant.name}".format(
372 geckoview_example=build_config.geckoview_example
374 "messaging_example:assemble{geckoview_example.variant.name}".format(
375 geckoview_example=build_config.geckoview_example
377 "port_messaging_example:assemble{geckoview_example.variant.name}".format(
378 geckoview_example=build_config.geckoview_example
380 "geckoview:publish{geckoview.variant.name}PublicationToMavenRepository".format(
381 geckoview=build_config.geckoview
383 "exoplayer2:publishDebugPublicationToMavenRepository",
388 "test_runner:bundle{geckoview_example.variant.name}".format(
389 geckoview_example=build_config.geckoview_example
391 "geckoview_example:bundle{geckoview_example.variant.name}".format(
392 geckoview_example=build_config.geckoview_example
399 "GRADLE_ANDROID_ARCHIVE_GECKOVIEW_TASKS", gradle_android_archive_geckoview_tasks
403 @depends(gradle_android_build_config)
404 def gradle_android_geckoview_docs_tasks(build_config):
405 """Gradle tasks run by |mach android geckoview-docs|."""
407 "geckoview:javadoc{geckoview.variant.name}".format(
408 geckoview=build_config.geckoview
413 set_config("GRADLE_ANDROID_GECKOVIEW_DOCS_TASKS", gradle_android_geckoview_docs_tasks)
416 @depends(gradle_android_build_config)
417 def gradle_android_geckoview_docs_archive_tasks(build_config):
418 """Gradle tasks run by |mach android geckoview-docs --archive| or |... --upload."""
420 "geckoview:javadocCopyJar{geckoview.variant.name}".format(
421 geckoview=build_config.geckoview
427 "GRADLE_ANDROID_GECKOVIEW_DOCS_ARCHIVE_TASKS",
428 gradle_android_geckoview_docs_archive_tasks,
432 @depends(gradle_android_build_config)
433 def gradle_android_geckoview_docs_output_files(build_config):
434 """Output files for GeckoView javadoc."""
438 return s[0].lower() + s[1:]
442 variant = uncapitalize(build_config.geckoview.variant.name)
445 "gradle/build/mobile/android/geckoview/reports/javadoc-results-{}.json".format(
452 "GRADLE_ANDROID_GECKOVIEW_DOCS_OUTPUT_FILES",
453 gradle_android_geckoview_docs_output_files,
457 @depends(gradle_android_build_config)
458 def gradle_android_archive_coverage_artifacts_tasks(build_config):
459 """Gradle tasks run by |mach android archive-coverage-artifacts|."""
461 "geckoview:archiveClassfiles{geckoview.variant.name}".format(
462 geckoview=build_config.geckoview
464 "geckoview:copyCoverageDependencies",
469 "GRADLE_ANDROID_ARCHIVE_COVERAGE_ARTIFACTS_TASKS",
470 gradle_android_archive_coverage_artifacts_tasks,
474 @depends(gradle_android_build_config)
475 def gradle_android_build_geckoview_example_tasks(build_config):
476 """Gradle tasks run by |mach android build-geckoview_example|."""
478 "geckoview_example:assemble{geckoview_example.variant.name}".format(
479 geckoview_example=build_config.geckoview_example
481 "geckoview_example:bundle{geckoview_example.variant.name}".format(
482 geckoview_example=build_config.geckoview_example
484 "geckoview:assemble{geckoview.variant.name}AndroidTest".format(
485 geckoview=build_config.geckoview
487 "test_runner:assemble{geckoview.variant.name}".format(
488 geckoview=build_config.geckoview
490 "test_runner:bundle{geckoview.variant.name}".format(
491 geckoview=build_config.geckoview
497 "GRADLE_ANDROID_BUILD_GECKOVIEW_EXAMPLE_TASKS",
498 gradle_android_build_geckoview_example_tasks,
502 @depends(gradle_android_build_config)
503 def gradle_android_install_geckoview_test_runner_tasks(build_config):
504 """Gradle tasks run by |mach android install-geckoview-test_runner|."""
506 "test_runner:install{geckoview.variant.name}".format(
507 geckoview=build_config.geckoview
513 "GRADLE_ANDROID_INSTALL_GECKOVIEW_TEST_RUNNER_TASKS",
514 gradle_android_install_geckoview_test_runner_tasks,
518 @depends(gradle_android_build_config)
519 def gradle_android_install_geckoview_test_tasks(build_config):
520 """Gradle tasks run by |mach android install-geckoview-test|."""
522 "geckoview:install{geckoview.variant.name}AndroidTest".format(
523 geckoview=build_config.geckoview
529 "GRADLE_ANDROID_INSTALL_GECKOVIEW_TEST_TASKS",
530 gradle_android_install_geckoview_test_tasks,
534 @depends(gradle_android_build_config)
535 def gradle_android_install_geckoview_example_tasks(build_config):
536 """Gradle tasks run by |mach android install-geckoview_example|."""
538 "geckoview_example:install{geckoview_example.variant.name}".format(
539 geckoview_example=build_config.geckoview_example
545 "GRADLE_ANDROID_INSTALL_GECKOVIEW_EXAMPLE_TASKS",
546 gradle_android_install_geckoview_example_tasks,
551 gradle_android_api_lint_tasks,
552 gradle_android_format_lint_check_tasks,
553 gradle_android_checkstyle_tasks,
555 @imports(_from="itertools", _import="chain")
556 def gradle_android_dependencies_tasks(*tasks):
557 """Gradle tasks run by |mach android dependencies|."""
558 # The union, plus a bit more, of all of the Gradle tasks
559 # invoked by the android-* automation jobs.
560 def withoutGeckoBinaries(task):
561 return task.replace("withGeckoBinaries", "withoutGeckoBinaries")
563 return list(withoutGeckoBinaries(t) for t in chain(*tasks))
566 set_config("GRADLE_ANDROID_DEPENDENCIES_TASKS", gradle_android_dependencies_tasks)
569 # Automation uses this to change log levels, not use the daemon, and use
571 option(env="GRADLE_FLAGS", default="", help="Flags to pass to Gradle.")
574 @depends("GRADLE_FLAGS")
575 def gradle_flags(value):
576 return value[0] if value else ""
579 set_config("GRADLE_FLAGS", gradle_flags)
581 # Automation will set this to (file:///path/to/local, ...) via the mozconfig.
582 # Local developer default is (maven.google.com).
584 env="GRADLE_MAVEN_REPOSITORIES",
587 "https://maven.mozilla.org/maven2/",
588 "https://maven.google.com/",
589 "https://repo.maven.apache.org/maven2/",
590 "https://plugins.gradle.org/m2/",
592 help="Comma-separated URLs of Maven repositories containing Gradle dependencies.",
596 "--allow-insecure-gradle-repositories",
597 help="Gradle is allowed to connect to insecure Maven repositories.",
601 "ALLOW_INSECURE_GRADLE_REPOSITORIES",
603 when="--allow-insecure-gradle-repositories",
607 @depends("GRADLE_MAVEN_REPOSITORIES")
608 @imports(_from="os.path", _import="isdir")
609 def gradle_maven_repositories(values):
611 die("GRADLE_MAVEN_REPOSITORIES must not be empty")
613 die("GRADLE_MAVEN_REPOSITORIES entries must not be empty")
617 set_config("GRADLE_MAVEN_REPOSITORIES", gradle_maven_repositories)