-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Allow to use deterministic mtime in jar #15529
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
base: master
Are you sure you want to change the base?
Conversation
eli-schwartz
left a comment
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 that ideally we should be testing this in CI. We can use unittests/ to define a custom python routine that first runs some arbitrary python code (like setting os.environ :)) and then tries to build one of the sample test projects in test cases/.
mesonbuild/scripts/depfixer.py
Outdated
| source_date_epoch = os.environ.get('SOURCE_DATE_EPOCH') | ||
| if source_date_epoch: | ||
| # We want to adjust mtime for deterministic .jar file results: | ||
| source_date_epoch = int(source_date_epoch) |
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.
Per the spec:
If the value is malformed, the build process SHOULD exit with a non-zero error code.
Which relying on python to catch invalid string-to-int conversions will do.
That being said, I wonder whether it's worth explicitly catching the exception and re-raising MesonException with a more specific error message?
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.
IMHO, it is not worth the extra complexity to catch cases that should never happen. The usual cases are
- the variable is not set
- the variable is set and contains a valid integer
|
As you know the test infra, could you add such a test? For me it could take days (which I don't have) to figure out all the details. |
I'm happy to advise! But it's your PR, so it's also your responsibility to complete the PR. Here is a basic java test sample project that will automatically test any commits regarding jar() in meson already: https://github.com/mesonbuild/meson/tree/master/test%20cases/java/1%20basic Note it is literally just a sample meson.build, and the "project tests" harness attempts to configure compile and install all sample project directories in turn. By default all non- "unit" test sample projects are run by Here is an example of building a sample project (as a platform agnostic test which means that in CI it will only run on "fast" platforms) with arbitrary python code run first: meson/unittests/platformagnostictests.py Lines 569 to 582 in 6835b6e
Here is the definition of meson/unittests/baseplatformtests.py Line 274 in 6835b6e
|
|
For more details see https://mesonbuild.com/Contributing.html#tests (and if you really think that it will take you days to figure out how to contribute a.test case, then that is a documentation bug, so please tell us how we can improve the contributing docs!) |
|
I managed to add some test and run it with However, I cannot find the .jar file it should create and then we would still need to check the mtime that now should stop to vary. The docs seem to only cover the basics, not these specific things. Would we just use python zip modules for the test? |
|
It should be in self.builddir (or self.installdir if you run |
|
Thanks, that got me a bit further. Now the test fails - my guess is that the patched code is not actually run in the test. I think, it should be |
And currently you are passing it to init(), which is like setting it before running |
|
Indeed, the env override was needed for the install step. The test looks good now. Is the hardcoded And should the test move to a different file? Maybe it could also be tested on Windows? |
When updating a .jar file, we use the SOURCE_DATE_EPOCH variable to determine the mtime value of the manifest file. See https://reproducible-builds.org/ for why this is good. This branch will fail if an incompatible jar version (e.g. openjdk < 17) is used. This is probably preferable to silently generating non-deterministic build results. And it keeps the code simpler. Signed-off-by: Bernhard M. Wiedemann <[email protected]>
similar to those variables for other languages
When updating a
.jarfile, we use theSOURCE_DATE_EPOCHenv variable to determine the mtime value of the manifest file.See https://reproducible-builds.org/ for why this is good.
This branch will fail if an incompatible jar version (e.g. openjdk < 17) is used. This is probably preferable to silently generating non-deterministic build results. And it keeps the code simpler.