[tbb-commits] [Git][tpo/applications/tor-browser-build][main] Bug 40089: Change how we set MOZ_BUILD_DATE

boklm (@boklm) git at gitlab.torproject.org
Fri Jul 14 07:52:11 UTC 2023



boklm pushed to branch main at The Tor Project / Applications / tor-browser-build


Commits:
69317005 by Nicolas Vigier at 2023-07-14T09:49:46+02:00
Bug 40089: Change how we set MOZ_BUILD_DATE

For normal alpha/release builds, we use the date from the commit, on
which we add the numbers from the version string as seconds (in order to
keep increasing the build date when we release a new version without
adding new commits).

For nightly-testbuild, we use the date from the commit.

For nightly we try to parse the day from the version number, or use the
current day at 00:00:01.

- - - - -


9 changed files:

- projects/android-components/build
- − projects/common/get-moz-build-date
- projects/fenix/build
- projects/firefox/build
- projects/firefox/config
- − projects/firefox/get-moz-build-date
- projects/geckoview/build
- projects/geckoview/config
- rbm.conf


Changes:

=====================================
projects/android-components/build
=====================================
@@ -9,10 +9,6 @@ builddir=/var/tmp/build/[% project %]
 mkdir $distdir/[% project %]
 mkdir /var/tmp/build
 
-cat > get-moz-build-date << "EOF"
-[% INCLUDE "get-moz-build-date" %]
-EOF
-
 [% IF !c("var/fetch_gradle_dependencies") %]
   tar -C $distdir -xf [% c('input_files_by_name/geckoview') %]
   gradle_repo=$rootdir/[% c('input_files_by_name/gradle-dependencies') %]
@@ -60,12 +56,7 @@ sed -i 's/tag = getGitHash()/tag = \"[% c('abbrev') %]\"/' publish.gradle
   export LANG=C.UTF-8
   patch -p1 < $rootdir/mavenLocal.patch
 
-  eval $(perl $rootdir/get-moz-build-date [% pc("fenix", "var/copyright_year") %] [% pc("fenix", "var/torbrowser_version") %])
-  if [ -z $MOZ_BUILD_DATE ]
-  then
-    echo "MOZ_BUILD_DATE is not set"
-    exit 1
-  fi
+  [% c("var/set_MOZ_BUILD_DATE") %]
 
   # Increase the maximum memory usage, for when compiling with --disable-install-strip
   gradle_args="--offline --no-daemon -Dmaven.repo.local=$gradle_repo -Dorg.gradle.jvmargs=-Xmx8g"


=====================================
projects/common/get-moz-build-date deleted
=====================================
@@ -1,30 +0,0 @@
-#!/usr/bin/perl -w
-# Generate a MOZ_BUILD_DATE based on Tor Browser version number
-
-use strict;
-
-die "wrong number of arguments" unless @ARGV == 2;
-my ($year, $version) = @ARGV;
-my $date;
-if ($version =~ m/^tbb-nightly\.([^\.]+)\.([^\.]+)\.([^\.]+)$/) {
-  $date = sprintf("%d%02d%02d010101", $1, $2, $3);
-} elsif ($version eq 'testbuild') {
-  # There is no need for an increasing build date in test builds. Just hardcode
-  # it to a value that is compatible with the v1 versionCode scheme on Android,
-  # see: #34163. We adjust the date to the new cutoff according to
-  # https://github.com/mozilla-mobile/fenix/pull/14952, following Mozilla.
-  # This should be unproblematic for test builds anyway.
-  $date = 20141228000000;
-} else {
-  my @v = split(/[\.ab]/, $version);
-  push @v, '0' if @v < 4;
-  push @v, '0' if @v < 4;
-  # When MOZ_BUILD_DATE was based on the firefox version, with
-  # Tor Browser 8.0.6 and firefox 60.5.1 it was 20190204060201
-  # We can remove 5 from the month, while keeping it increasing.
-  my $month = $v[0] - 5;
-  $date = 1010101 + $year * 10000000000 + $month * 100000000
-             + $v[1] * 1000000 + $v[2] * 10000 + $v[3];
-  $date += 1000000 unless $version =~ m/[ab]/;
-}
-print "export MOZ_BUILD_DATE=$date\n";


=====================================
projects/fenix/build
=====================================
@@ -9,10 +9,6 @@ builddir=/var/tmp/build/[% project %]
 mkdir -p $distdir/[% project %]
 mkdir -p /var/tmp/build
 
-cat > get-moz-build-date << "EOF"
-[% INCLUDE "get-moz-build-date" %]
-EOF
-
 [% IF !c("var/fetch_gradle_dependencies") %]
   tar -C $distdir -xf [% c('input_files_by_name/geckoview') %]
   gradle_repo=$rootdir/[% c('input_files_by_name/gradle-dependencies') %]
@@ -71,12 +67,7 @@ v=[% c("variant") %]
   export LANG=C.UTF-8
   patch -p1 < $rootdir/mavenLocal.patch
 
-  eval $(perl $rootdir/get-moz-build-date [% c("var/copyright_year") %] [% c("var/torbrowser_version") %])
-  if [ -z $MOZ_BUILD_DATE ]
-  then
-    echo "MOZ_BUILD_DATE is not set"
-    exit 1
-  fi
+  [% c("var/set_MOZ_BUILD_DATE") %]
 
   # Bug 40485: Inject deterministic build date into Glean.
   echo "ext.gleanBuildDate = \"0\"" >> app/build.gradle


=====================================
projects/firefox/build
=====================================
@@ -70,12 +70,7 @@ MOZCONFIG_EOF
   export ASAN_OPTIONS="detect_leaks=0"
 [% END -%]
 
-eval $(perl $rootdir/get-moz-build-date [% c("var/copyright_year") %] [% c("var/torbrowser_version") %])
-if [ -z $MOZ_BUILD_DATE ]
-then
-    echo "MOZ_BUILD_DATE is not set"
-    exit 1
-fi
+[% c("var/set_MOZ_BUILD_DATE") %]
 
 [% IF c("var/windows") %]
   # Make sure widl is not inserting random timestamps, see #21837.


=====================================
projects/firefox/config
=====================================
@@ -153,7 +153,6 @@ input_files:
   - project: container-image
   - name: '[% c("var/compiler") %]'
     project: '[% c("var/compiler") %]'
-  - filename: get-moz-build-date
   - project: binutils
     name: binutils
     enable: '[% c("var/linux") %]'


=====================================
projects/firefox/get-moz-build-date deleted
=====================================
@@ -1,27 +0,0 @@
-#!/usr/bin/perl -w
-# Generate a MOZ_BUILD_DATE based on Tor Browser version number
-
-use strict;
-
-die "wrong number of arguments" unless @ARGV == 2;
-my ($year, $version) = @ARGV;
-my $date;
-if ($version =~ m/^tbb-nightly\.([^\.]+)\.([^\.]+)\.([^\.]+)$/) {
-  $date = sprintf("%d%02d%02d010101", $1, $2, $3);
-} elsif ($version eq 'testbuild') {
-  # There is no need for an increasing build date in test builds. Just hardcode
-  # it.
-  $date = 20010101010101;
-} else {
-  my @v = split(/[\.ab]/, $version);
-  push @v, '0' if @v < 4;
-  push @v, '0' if @v < 4;
-  # When MOZ_BUILD_DATE was based on the firefox version, with
-  # Tor Browser 8.0.6 and firefox 60.5.1 it was 20190204060201
-  # We can remove 5 from the month, while keeping it increasing.
-  my $month = $v[0] - 5;
-  $date = 1010101 + $year * 10000000000 + $month * 100000000
-             + $v[1] * 1000000 + $v[2] * 10000 + $v[3];
-  $date += 1000000 unless $version =~ m/[ab]/;
-}
-print "export MOZ_BUILD_DATE=$date\n";


=====================================
projects/geckoview/build
=====================================
@@ -8,13 +8,6 @@ distdir=/var/tmp/dist
 mkdir -p /var/tmp/build
 mkdir -p $distdir/[% project %]
 
-# We need to have the get-moz-build-date script available in the container
-# but we can't include it via input_files as it is a script shared between
-# projects.
-cat > get-moz-build-date << "EOF"
-[% INCLUDE "get-moz-build-date" %]
-EOF
-
 tar -C /var/tmp/dist -xf [% c('input_files_by_name/rust') %]
 tar -C /var/tmp/dist -xf [% c('input_files_by_name/cbindgen') %]
 tar -C /var/tmp/dist -xf [% c('input_files_by_name/nasm') %]
@@ -49,12 +42,7 @@ export MOZ_SOURCE_REPO="[% c('var/gitlab_project') %]"
 export MOZ_SOURCE_CHANGESET=[% c("var/git_commit") %]
 MOZCONFIG_EOF
 
-eval $(perl $rootdir/get-moz-build-date [% c("var/copyright_year") %] [% c("var/torbrowser_version") %])
-if [ -z $MOZ_BUILD_DATE ]
-then
-    echo "MOZ_BUILD_DATE is not set"
-    exit 1
-fi
+[% c("var/set_MOZ_BUILD_DATE") %]
 
 export JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64
 gradle_repo=/var/tmp/dist/gradle-dependencies


=====================================
projects/geckoview/config
=====================================
@@ -48,10 +48,6 @@ steps:
       mkdir -p /var/tmp/build
       mkdir -p $distdir/[% project %]
 
-      cat > get-moz-build-date << "EOF"
-      [% INCLUDE "get-moz-build-date" %]
-      EOF
-
       tar -C $distdir -xf [% c('input_files_by_name/node') %]
       export PATH="/var/tmp/dist/node/bin:$PATH"
 
@@ -73,12 +69,7 @@ steps:
       ln -s mozconfig-android-all .mozconfig
       echo 'mk_add_options MOZ_PARALLEL_BUILD=[% c("num_procs") %]' >> .mozconfig
 
-      eval $(perl $rootdir/get-moz-build-date [% c("var/copyright_year") %] [% c("var/torbrowser_version") %])
-      if [ -z $MOZ_BUILD_DATE ]
-      then
-          echo "MOZ_BUILD_DATE is not set"
-          exit 1
-      fi
+      [% c("var/set_MOZ_BUILD_DATE") %]
 
       export JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64
       gradle_repo=/var/tmp/dist/gradle-dependencies


=====================================
rbm.conf
=====================================
@@ -218,6 +218,7 @@ var:
     [% END -%]
 
   DOCSDIR_project: '[% project %]'
+  set_MOZ_BUILD_DATE: 'export MOZ_BUILD_DATE=[% c("var_p/MOZ_BUILD_DATE") %]'
 
 targets:
   notarget: linux-x86_64
@@ -717,5 +718,31 @@ gpg_allow_expired_keys: 1
         }
         return [@res];
       },
+      MOZ_BUILD_DATE => sub {
+        use POSIX qw(strftime);
+        my ($project, $options) = @_;
+        my $nightly = project_config($project, 'var/nightly', $options);
+        my $testbuild = project_config($project, 'var/testbuild', $options);
+
+        if ($nightly && !$testbuild) {
+          my $torbrowser_version = project_config($project, 'var/torbrowser_version', $options);
+          return sprintf("%d%02d%02d000001", $1, $2, $3)
+            if $torbrowser_version =~ m/^tbb-nightly\.([^\.]+)\.([^\.]+)\.([^\.]+)$/;
+          return strftime("%Y%m%d000001", gmtime);
+        }
+
+        my $timestamp = project_config($project, 'timestamp', $options);
+        if (!$nightly) {
+          my $torbrowser_version = project_config($project, 'var/torbrowser_version', $options);
+          my @n = reverse split /[\.\D]/, $torbrowser_version;
+          my $i = 1;
+          unshift @n, 0 if @n < 3;
+          for my $n (@n) {
+            $timestamp += $n * $i;
+            $i = $i * 10;
+          }
+        }
+        return strftime "%Y%m%d%H%M%S", gmtime($timestamp);
+      },
     },
   )



View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser-build/-/commit/693170054285bcf7ce35a1b84773958d59596b7c

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser-build/-/commit/693170054285bcf7ce35a1b84773958d59596b7c
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tbb-commits/attachments/20230714/34cb8166/attachment-0001.htm>


More information about the tbb-commits mailing list