[% c("var/set_default_env") -%]
[% pc(c('var/compiler'), 'var/setup', {
  compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')),
  gradle_tarfile => c("input_files_by_name/gradle"),
}) %]
distdir=/var/tmp/dist
builddir=/var/tmp/build
mkdir -p $builddir $distdir

tar -C $distdir -xf [% c('input_files_by_name/node') %]
export PATH="/var/tmp/dist/node/bin:$PATH"

export LC_ALL=C.UTF-8
export LANG=C.UTF-8

tar -xf [% c('input_files_by_name/application-services') %]
export NIMBUS_FML=$rootdir/application-services/nimbus-fml

[% INCLUDE 'fake-git' %]

tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.[% c('compress_tar') %]

[% c("var/set_MOZ_BUILD_DATE") %]

export JAVA_HOME=/usr/lib/jvm/java-1.17.0-openjdk-amd64
gradle_repo=/var/tmp/dist/gradle-dependencies
export GRADLE_MAVEN_REPOSITORIES="file://$gradle_repo","file://$gradle_repo/maven2"
# Set the Maven local repository because Gradle ignores our overriding of $HOME.
# It is only used for the local pubblication of single-arch AARs.
export GRADLE_FLAGS="--no-daemon --offline -Dmaven.repo.local=$distdir/[% project %]"
# Move the Gradle repo to a hard-coded location. The location is embedded in
# the file chrome/toolkit/content/global/buildconfig.html so it needs to be
# standardized for reproducibility.
mv $rootdir/[% c('input_files_by_name/gradle-dependencies') %] $gradle_repo
cp -rl $rootdir/application-services/maven/* $gradle_repo
cp -rl $gradle_repo/dl/android/maven2/* $gradle_repo || true
cp -rl $gradle_repo/m2/* $gradle_repo || true
cp -rl $gradle_repo/maven2/* $gradle_repo || true

tar -xf [% c('input_files_by_name/glean-wheels') %]
export GLEAN_PYTHON_WHEELS_DIR=$rootdir/glean-wheels

tar -xf [% c('input_files_by_name/oss-licenses-plugin') %]
cp -rl oss-licenses-plugin/. $gradle_repo

# We unbreak mach, see: https://bugzilla.mozilla.org/show_bug.cgi?id=1656993.
export MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE=system
# Create .mozbuild to avoid interactive prompt in configure
mkdir "$HOME/.mozbuild"

[% INCLUDE 'browser-localization' %]
