-
Notifications
You must be signed in to change notification settings - Fork 59
Make packages reproducible #543
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
Open
jodersky
wants to merge
2
commits into
cvogt:master
Choose a base branch
from
jodersky:reproducible-builds
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package package_example | ||
| object Main{ | ||
| def main( args: Array[String] ): Unit = { | ||
| println( Console.GREEN ++ "Hello World" ++ Console.RESET ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package package_example_build | ||
| import java.nio.file._ | ||
| import java.security.MessageDigest | ||
| import cbt._ | ||
| class Build(val context: Context) extends BaseBuild with PackageJars { | ||
| override def groupId = "org.example" | ||
| override def version = "1.0.0" | ||
|
|
||
| def hash(file: Path): String = { | ||
| val digest = MessageDigest.getInstance("SHA-256"); | ||
| val in = Files.newInputStream(file) | ||
| try { | ||
| val chunk = new Array[Byte](4096) | ||
| while(in.read(chunk) > 0) { | ||
| digest.update(chunk) | ||
| } | ||
| } finally { | ||
| in.close | ||
| } | ||
| val bytes = digest.digest() | ||
| val builder = new StringBuilder(bytes.length * 2); | ||
| for(b <- bytes) { | ||
| builder.append(f"$b%02x") | ||
| } | ||
| builder.toString | ||
| } | ||
|
|
||
| override def run = { | ||
| val pass1 = super.`package`.map(f => hash(f.toPath)) | ||
| lib.clean(cleanFiles, true, false, false, false) | ||
| transientCache.clear() | ||
| val pass2 = super.`package`.map(f => hash(f.toPath)) | ||
|
|
||
| assert( | ||
| pass1 == pass2, | ||
| "The checksums of jars generated during two separate builds did not match. " + | ||
| "The build is not reproducible." | ||
| ) | ||
| ExitCode.Success | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cache invalidation is required here, or else the second pass will fail due to missing files. Should this be moved to the clean helper method in lib?
Also, I'm not sure if I have the same concept of what a
cleanoperation should do, but IMO there should not be the need to prompt the user for a confirmation since we're only deleting generated files.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would probably be safer if we don't try to clear caches from within a single cbt run.
What if in test.scala we call
cbt package, then read the info into memory. Callcbt clean, thencbt package, check that the file modified date is different but the jar meta data is still the same.cleanrequiring confirmation is less about not trusting the user having called the right command, more about not trusting cbt as a fast moving code base to not silently break behavior here at some point. Once we get to the point where we have solid, in-memory filesystem test for this, we can remove the check.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cvogt, should the checksum be generated and checked in the master test file then?