← Back to team overview

openjdk team mailing list archive

Bug#933349: openjdk-11: Make the generated copyright headers reproducible

 

Source: openjdk-11
Version: 11.0.4+11-1
Severity: normal

OpenJDK generates several classes at build time with a copyright header that
look like this:

  /*
   * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it

The upper bound of the date range is generated dynamically using the current
date, which makes the file non reproducible.

It affects the reproducibility of the src.zip file installed by openjdk-11-source.

I'm attaching a patch fixing the two build tools involved in this issue
(EquivMapsGenerator and CopyrightHeaders).

Emmanuel Bourg
Description: Makes the generated copyright headers reproducible
Author: Emmanuel Bourg <ebourg@xxxxxxxxxx>
Forwarded: no
--- a/make/jdk/src/classes/build/tools/cldrconverter/CopyrightHeaders.java
+++ b/make/jdk/src/classes/build/tools/cldrconverter/CopyrightHeaders.java
@@ -26,6 +26,7 @@
 package build.tools.cldrconverter;
 
 import java.util.Calendar;
+import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.Locale;
 import java.util.TimeZone;
@@ -150,8 +151,14 @@
     }
 
     private static int getYear() {
-        return new GregorianCalendar(TimeZone.getTimeZone("America/Los_Angeles"),
-                                         Locale.US).get(Calendar.YEAR);
+        Date date = new Date();
+        if (System.getenv("SOURCE_DATE_EPOCH") != null) {
+            date = new Date(1000 * Long.valueOf(System.getenv("SOURCE_DATE_EPOCH")));
+        }
+
+        GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"), Locale.ENGLISH);
+        calendar.setTime(date);
+        return calendar.get(Calendar.YEAR);
     }
 
     // no instantiation
--- a/make/jdk/src/classes/build/tools/generatelsrequivmaps/EquivMapsGenerator.java
+++ b/make/jdk/src/classes/build/tools/generatelsrequivmaps/EquivMapsGenerator.java
@@ -33,9 +33,13 @@
 import java.time.ZoneId;
 import java.time.ZonedDateTime;
 import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.TimeZone;
 import java.util.TreeMap;
 
 /**
@@ -225,8 +229,15 @@
         + "}";
 
     private static String getOpenJDKCopyright() {
-        int year = ZonedDateTime.now(ZoneId
-                .of("America/Los_Angeles")).getYear();
+        Date date = new Date();
+        if (System.getenv("SOURCE_DATE_EPOCH") != null) {
+            date = new Date(1000 * Long.valueOf(System.getenv("SOURCE_DATE_EPOCH")));
+        }
+
+        GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"), Locale.ENGLISH);
+        calendar.setTime(date);
+
+        int year = calendar.get(Calendar.YEAR);
         return String.format(Locale.US, COPYRIGHT, year);
     }