Bug 1509573 - Part 2: Use |mach build faster| rather than special Make target. r=snorp

This uses |mach build faster| rather than a custom target, reducing
Make magic and making it easier to reason about the Gradle build.  I
also took the opportunity to improve the task logging.

Differential Revision: https://phabricator.services.mozilla.com/D12797

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nick Alexander 2018-11-28 19:46:35 +00:00
parent 28bf110c5c
commit f5cdc551cb
4 changed files with 41 additions and 46 deletions

View File

@ -58,41 +58,57 @@ buildscript {
classpath 'org.mozilla.apilint:apilint:0.1.4'
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
classpath 'org.apache.commons:commons-exec:1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
// A stream that processes bytes line by line, prepending a tag before sending
// each line to Gradle's logging.
class TaggedLogOutputStream extends org.apache.commons.exec.LogOutputStream {
String tag
Logger logger
TaggedLogOutputStream(tag, logger) {
this.tag = tag
this.logger = logger
}
void processLine(String line, int level) {
logger.lifecycle("${this.tag} ${line}")
}
}
if ('multi' == System.env.AB_CD) {
// Multi-l10n builds set `AB_CD=multi`, which isn't a valid locale. This
// causes the
//
// |mach build| > |mach gradle| > |make gradle-targets| > AndroidManifest.xml > strings.xml > multi/brand.dtd
// |mach build| > |mach gradle| > AndroidManifest.xml > strings.xml > multi/brand.dtd
//
// dependency chain to fail, since multi isn't a real locale. To avoid
// this, if Gradle is invoked with AB_CD=multi, we don't invoke Make at all.
task generateCodeAndResources()
task machBuildFaster()
} else if (System.env.IS_LANGUAGE_REPACK == '1') {
// Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and handle resource
// and code generation themselves.
task generateCodeAndResources()
task machBuildFaster()
} else {
task generateCodeAndResources(type:Exec) {
workingDir "${topobjdir}"
task machBuildFaster(type: Exec) {
workingDir "${topsrcdir}"
commandLine mozconfig.substs.GMAKE
args '-C'
args "${topobjdir}/mobile/android/base"
args 'gradle-targets'
commandLine mozconfig.substs.PYTHON
args "${topsrcdir}/mach"
args 'build'
args 'faster'
// Only show the output if something went wrong.
ignoreExitValue = true
standardOutput = new ByteArrayOutputStream()
errorOutput = standardOutput
doLast {
if (execResult.exitValue != 0) {
throw new GradleException("Process '${commandLine}' finished with non-zero exit value ${execResult.exitValue}:\n\n${standardOutput.toString()}")
}
// Add `-v` if we're running under `--info` (or `--debug`).
if (project.logger.isEnabled(LogLevel.INFO)) {
args '-v'
}
// `path` is like `:machBuildFaster`.
standardOutput = new TaggedLogOutputStream("${path}>", logger)
errorOutput = standardOutput
}
}
@ -131,10 +147,10 @@ afterEvaluate {
return
}
android.applicationVariants.all {
preBuild.dependsOn rootProject.generateCodeAndResources
preBuild.dependsOn rootProject.machBuildFaster
}
android.libraryVariants.all {
preBuild.dependsOn rootProject.generateCodeAndResources
preBuild.dependsOn rootProject.machBuildFaster
}
}
}

View File

@ -338,7 +338,7 @@ android.applicationVariants.all { variant ->
// what we want for Fennec, however, with applicationId. To use the same
// manifest as moz.build, we replace the package with org.mozilla.gecko (the
// eventual package) here.
def rewriteManifestPackage = task("rewriteManifestPackageFor${variant.name.capitalize()}", type: Copy, dependsOn: rootProject.generateCodeAndResources) {
def rewriteManifestPackage = task("rewriteManifestPackageFor${variant.name.capitalize()}", type: Copy, dependsOn: rootProject.machBuildFaster) {
into("${project.buildDir}/moz.build/src/${variant.name}")
from("${topobjdir}/mobile/android/base/AndroidManifest.xml")
filter { it.replaceFirst(/package=".*?"/, 'package="org.mozilla.gecko"') }
@ -359,9 +359,9 @@ android.applicationVariants.all { variant ->
// re-entrant. Official builds are driven by the moz.build system and
// should never be re-entrant in this way.
if (!mozconfig.substs.MOZILLA_OFFICIAL) {
syncPreprocessedJava.dependsOn rootProject.generateCodeAndResources
syncPreprocessedRes.dependsOn rootProject.generateCodeAndResources
rewriteManifestPackage.dependsOn rootProject.generateCodeAndResources
syncPreprocessedJava.dependsOn rootProject.machBuildFaster
syncPreprocessedRes.dependsOn rootProject.machBuildFaster
rewriteManifestPackage.dependsOn rootProject.machBuildFaster
}
// When driven from moz.build via |mach build|, Gradle does not require or

View File

@ -6,19 +6,6 @@
# find and create .mozconfig files and to generate targets.
.NOTPARALLEL:
generated_resources := \
AndroidManifest.xml \
res/raw/suggestedsites.json \
res/values/strings.xml \
$(NULL)
generated_files := \
AndroidManifest.xml \
generated/preprocessed/org/mozilla/gecko/AdjustConstants.java \
generated/preprocessed/org/mozilla/gecko/AppConstants.java \
generated/preprocessed/org/mozilla/gecko/MmaConstants.java \
$(NULL)
include $(topsrcdir)/config/AB_rCD.mk
chrome-%:: AB_CD=$*
@ -44,22 +31,14 @@ $(ABS_DIST)/fennec/$(OMNIJAR_NAME): FORCE
$(RM) $(DIST)/fennec/$(notdir $(OMNIJAR_NAME))
ifndef MOZILLA_OFFICIAL
# Targets built very early during a Gradle build. In automation,
# these are built before Gradle is invoked, and gradle-targets is not
# made at all. This is required to avoid building gradle-targets with
# AB_CD=multi during multi-l10n builds.
gradle-targets: $(generated_resources) $(generated_files)
# Local developers update omni.ja during their builds. There's a
# chicken-and-egg problem here.
gradle-omnijar: $(abspath $(DIST)/fennec/$(OMNIJAR_NAME))
else
# In automation, omni.ja is built only during packaging.
gradle-omnijar:
gradle-targets:
endif
.PHONY: gradle-targets gradle-omnijar
.PHONY: gradle-omnijar
export:: android_apks

View File

@ -12,7 +12,7 @@ evaluationDependsOn(':omnijar')
evaluationDependsOn(':annotations')
task buildOmnijars(type:Exec) {
dependsOn rootProject.generateCodeAndResources
dependsOn rootProject.machBuildFaster
// See comment in :omnijar project regarding interface mismatches here.
inputs.file(project(':omnijar').sourceSets.main.resources.srcDirs).skipWhenEmpty()