build 4.7 KB

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