Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset timestamps to 1970-01-01 during packaging for repeatable builds #5344

Merged
merged 6 commits into from
Dec 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions main-actions/src/main/scala/sbt/Package.scala
Original file line number Diff line number Diff line change
@@ -70,13 +70,23 @@ object Package {
val options: Seq[PackageOption]
)

@deprecated("Please specify whether to use a static timestamp", "1.4.0")
def apply(conf: Configuration, cacheStoreFactory: CacheStoreFactory, log: Logger): Unit =
apply(conf, cacheStoreFactory, log, None)

/**
*
* @param conf the package configuration that should be build
* @param cacheStoreFactory used for jar caching. We try to avoid rebuilds as much as possible
* @param log feedback for the user
* @param time static timestamp to use for all entries, if any.
*/
def apply(conf: Configuration, cacheStoreFactory: CacheStoreFactory, log: Logger): Unit = {
def apply(
conf: Configuration,
cacheStoreFactory: CacheStoreFactory,
log: Logger,
time: Option[Long]
): Unit = {
val manifest = new Manifest
val main = manifest.getMainAttributes
for (option <- conf.options) {
@@ -96,7 +106,7 @@ object Package {
val sources :+: _ :+: manifest :+: HNil = inputs
outputChanged(cacheStoreFactory make "output") { (outChanged, jar: PlainFileInfo) =>
if (inChanged || outChanged) {
makeJar(sources, jar.file, manifest, log)
makeJar(sources, jar.file, manifest, log, time)
jar.file
()
} else
@@ -153,7 +163,17 @@ object Package {
homepage map (h => (IMPLEMENTATION_URL, h.toString))
}: _*)
}
def makeJar(sources: Seq[(File, String)], jar: File, manifest: Manifest, log: Logger): Unit = {
@deprecated("Please specify whether to use a static timestamp", "1.4.0")
def makeJar(sources: Seq[(File, String)], jar: File, manifest: Manifest, log: Logger): Unit =
makeJar(sources, jar, manifest, log, None)

def makeJar(
sources: Seq[(File, String)],
jar: File,
manifest: Manifest,
log: Logger,
time: Option[Long]
): Unit = {
val path = jar.getAbsolutePath
log.debug("Packaging " + path + " ...")
if (jar.exists)
@@ -162,7 +182,7 @@ object Package {
else
sys.error(path + " exists, but is not a regular file")
log.debug(sourcesDebugString(sources))
IO.jar(sources, jar, manifest)
IO.jar(sources, jar, manifest, time)
log.debug("Done packaging.")
}
def sourcesDebugString(sources: Seq[(File, String)]): String =
7 changes: 6 additions & 1 deletion main/src/main/scala/sbt/Defaults.scala
Original file line number Diff line number Diff line change
@@ -1409,7 +1409,12 @@ object Defaults extends BuildCommon {
Def.task {
val config = packageConfiguration.value
val s = streams.value
Package(config, s.cacheStoreFactory, s.log)
Package(
config,
s.cacheStoreFactory,
s.log,
sys.env.get("SOURCE_DATE_EPOCH").map(_.toLong * 1000).orElse(Some(0L))
)
config.jar
}

2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ object Dependencies {
def nightlyVersion: Option[String] = sys.props.get("sbt.build.version")

// sbt modules
private val ioVersion = nightlyVersion.getOrElse("1.3.1")
private val ioVersion = nightlyVersion.getOrElse("1.4.0-M2")
private val lmVersion =
sys.props.get("sbt.build.lm.version") match {
case Some(version) => version