build 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. [% c("var/set_default_env") -%]
  3. [% pc(c('var/compiler'), 'var/setup', {
  4. compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')),
  5. gradle_tarfile => c("input_files_by_name/gradle"),
  6. }) %]
  7. distdir=/var/tmp/dist
  8. builddir=/var/tmp/build/[% project %]
  9. mkdir -p $distdir/[% project %]
  10. mkdir -p /var/tmp/build
  11. cat > get-moz-build-date << "EOF"
  12. [% INCLUDE "get-moz-build-date" %]
  13. EOF
  14. [% IF !c("var/fetch_gradle_dependencies") %]
  15. tar -C $distdir -xf [% c('input_files_by_name/geckoview') %]
  16. gradle_repo=$rootdir/[% c('input_files_by_name/gradle-dependencies') %]
  17. # This overwrites the release, beta, and nightly geckoview .aar files in our
  18. # gradle-dependencies directory to be sure that only the one we provide is
  19. # getting used when building beta/release code.
  20. find $gradle_repo -type f -name geckoview*omni*.aar -exec cp -f $distdir/geckoview/geckoview*omni*.aar {} \;
  21. cp -r $gradle_repo/dl/android/maven2/* $gradle_repo
  22. cp -r $gradle_repo/maven2/* $gradle_repo
  23. cp -r $gradle_repo/m2/* $gradle_repo
  24. tar -C $distdir -xf [% c('input_files_by_name/application-services') %]
  25. # XXX: We could be smarter (both for a-s and a-c) and just copy over the
  26. # projects that are needed according to the Gradle dependencies list.
  27. cp -rf $distdir/application-services/maven/org $gradle_repo
  28. tar -C $distdir -xf [% c('input_files_by_name/android-components') %]
  29. cp -rf $distdir/android-components/maven/org $gradle_repo
  30. nimbusdir=$builddir-[% c("version") %]/app/build/bin/nimbus
  31. mkdir -p $nimbusdir
  32. cp $distdir/application-services/nimbus-fml $nimbusdir/
  33. tar -C $distdir -xf $rootdir/[% c('input_files_by_name/tba-translation') %]
  34. [% END %]
  35. tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz
  36. cd $builddir-[% c("version") %]
  37. # Move Android library dependencies so they will be included in the apk during the build
  38. cp $rootdir/[% c('input_files_by_name/topl') %]/* app/
  39. cp $rootdir/[% c('input_files_by_name/tor-android-service') %]/* app/
  40. # Avoid call to `getGitHash()`, which will fail b/c it invokes git, which is absent in
  41. # the build container. Instead just inject the commit hash, which we know!
  42. sed -i 's/\\"${Config.getGitHash()}\\"/\\"[% c('abbrev') %]\\"/' app/build.gradle
  43. # XXX We need the build variant in lower case. Do something smarter here.
  44. v=[% c("variant") %]
  45. [% IF c("var/fetch_gradle_dependencies") %]
  46. $GRADLE_HOME/bin/gradle --debug --no-daemon app:assemble[% c('variant') %] \
  47. app:assembleAndroidTest -x lint -PtestBuildType=${v,} -PdisableOptimization \
  48. > gradle.log 2>&1 \
  49. || ( cat gradle.log; exit 1 )
  50. $rootdir/gen_gradle_deps_file.sh gradle.log
  51. mv gradle-dependencies-list.txt '[% dest_dir _ "/" _ c("filename") %]'
  52. [% ELSE %]
  53. # Add our localized strings
  54. [% FOREACH lang = c('var/locales_mobile');
  55. SET lang = tmpl(lang); %]
  56. # Copy our torbrowser_strings.xml at the right place
  57. cp /var/tmp/dist/tba-translation/[% lang %]/torbrowser_strings.xml app/src/main/res/values-[% lang %]/
  58. [% END %]
  59. # Prepare Glean dependencies for offline build
  60. tar -xf $rootdir/[% c('input_files_by_name/glean') %]
  61. # We need to set `LC_ALL` and `LANG` to something that is not ASCII as encoding
  62. # otherwise `click` barfs. See: https://click.palletsprojects.com/python3/
  63. export LC_ALL=C.UTF-8
  64. export LANG=C.UTF-8
  65. patch -p1 < $rootdir/mavenLocal.patch
  66. eval $(perl $rootdir/get-moz-build-date [% c("var/copyright_year") %] [% c("var/torbrowser_version") %])
  67. if [ -z $MOZ_BUILD_DATE ]
  68. then
  69. echo "MOZ_BUILD_DATE is not set"
  70. exit 1
  71. fi
  72. # Bug 40485: Inject deterministic build date into Glean.
  73. echo "ext.gleanBuildDate = \"0\"" >> app/build.gradle
  74. # We put the tor-browser version last to avoid int-parsing errors when consumers of project.versionName
  75. # assume it starts with a major version number, as it does for all Mozilla version names.
  76. version_name='[% c("var/fenix_version") %]-[% c("variant") %] ([% c("var/torbrowser_version") %])'
  77. # We need -PdisableOptimization for building tests. See:
  78. # https://gitlab.torproject.org/tpo/applications/tor-browser-build/-/issues/40259#note_2732325
  79. $GRADLE_HOME/bin/gradle --offline --no-daemon -PversionName="$version_name" -Dmaven.repo.local=$gradle_repo app:assemble[% c('variant') %] -x lint -PtestBuildType=${v,}
  80. $GRADLE_HOME/bin/gradle --offline --no-daemon -PversionName="$version_name" -Dmaven.repo.local=$gradle_repo app:assembleAndroidTest -x lint -PtestBuildType=${v,} -PdisableOptimization
  81. cp app/build/outputs/apk/${v,}/*.apk $distdir/[% project %]
  82. cp app/build/outputs/apk/androidTest/${v,}/app-${v,}-androidTest.apk $distdir/[% project %]
  83. cd $distdir
  84. [% c('tar', {
  85. tar_src => [ project ],
  86. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  87. }) %]
  88. [% END %]