[Git][reproducible-builds/reproducible-website][master] 2 commits: SOURCE_DATE_EPOCH: add missing syntax highlighting
Chris Lamb (@lamby)
gitlab at salsa.debian.org
Sat May 25 08:04:45 UTC 2024
Chris Lamb pushed to branch master at Reproducible Builds / reproducible-website
Commits:
c41667e6 by FC (Fay) Stegerman at 2024-05-25T00:46:38+02:00
SOURCE_DATE_EPOCH: add missing syntax highlighting
- - - - -
db010718 by FC (Fay) Stegerman at 2024-05-25T00:53:36+02:00
SOURCE_DATE_EPOCH tool versions: use `` for > and >= (to fix a small bug)
- - - - -
1 changed file:
- _docs/source-date-epoch.md
Changes:
=====================================
_docs/source-date-epoch.md
=====================================
@@ -13,7 +13,7 @@ Before added support to a tool for reading this variable, you should scan throug
### Python >= 3.x
-```
+```python
import os
import time
import datetime
@@ -26,7 +26,7 @@ build_date = datetime.datetime.fromtimestamp(
… or with fewer imports and rendering to a string:
-```
+```python
import os
import time
@@ -41,7 +41,7 @@ date_str = time.strftime(
If you still require Python 2.x support, you will need to use the non-recommended [`datetime.utcfromtimestamp`](https://docs.python.org/3.8/library/datetime.html#datetime.datetime.utcfromtimestamp) method ([more info](https://blog.ganssle.io/articles/2019/11/utcnow.html)):
-```
+```python
import os
import time
import datetime
@@ -55,13 +55,13 @@ build_date = datetime.datetime.utcfromtimestamp(
For GNU systems:
-```
+```bash
BUILD_DATE="$(date --utc --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +%Y-%m-%d)"
```
If you need to support BSD date as well you should fallback to trying ther `-r seconds` timestamp variant:
-```
+```bash
DATE_FMT="+%Y-%m-%d"
SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(date +%s)}"
BUILD_DATE=$(date -u -d "@$SOURCE_DATE_EPOCH" "$DATE_FMT" 2>/dev/null || date -u -r "$SOURCE_DATE_EPOCH" "$DATE_FMT" 2>/dev/null || date -u "$DATE_FMT")
@@ -69,14 +69,14 @@ BUILD_DATE=$(date -u -d "@$SOURCE_DATE_EPOCH" "$DATE_FMT" 2>/dev/null || date -u
### Perl
-```
+```perl
use POSIX qw(strftime);
my $date = strftime("%Y-%m-%d", gmtime($ENV{SOURCE_DATE_EPOCH} || time));
```
### Makefile
-```
+```make
DATE_FMT = +%Y-%m-%d
ifdef SOURCE_DATE_EPOCH
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)")
@@ -89,7 +89,7 @@ The above will work with either GNU or BSD date, and fallback to ignore `SOURCE_
### CMake
-```
+```cmake
STRING(TIMESTAMP BUILD_DATE "%Y-%m-%d" UTC)
```
@@ -97,7 +97,7 @@ STRING(TIMESTAMP BUILD_DATE "%Y-%m-%d" UTC)
If you would like to support legacy/archival versions of CMake, you can use this less-preferred variant:
-```
+```cmake
if (DEFINED ENV{SOURCE_DATE_EPOCH})
execute_process(
COMMAND "date" "-u" "-d" "@$ENV{SOURCE_DATE_EPOCH}" "+%Y-%m-%d"
@@ -117,7 +117,7 @@ Note that the above will work only with GNU `date`; see the POSIX shell example
By deliberate design, [Meson does not provide access to environment variables in build files](https://github.com/mesonbuild/meson/issues/9#issuecomment-543780613) which makes accessing `SOURCE_DATE_EPOCH` troublesome.
-```
+```meson
date_exe = find_program('date')
cmd = run_command('sh', '-c', 'echo $SOURCE_DATE_EPOCH')
source_date_epoch = cmd.stdout().strip()
@@ -132,7 +132,7 @@ The above will work only with GNU `date`. See the POSIX shell example on how to
### C
-```
+```c
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
@@ -173,7 +173,7 @@ build_time = gmtime(&now);
If you want less verbose code and are happy with the assumptions stated below, you can use
-```
+```c
#include <stdlib.h>
time_t now;
@@ -187,7 +187,7 @@ if ((source_date_epoch = getenv("SOURCE_DATE_EPOCH")) == NULL ||
### C++
-```
+```cpp
#include <sstream>
#include <iostream>
#include <cstdlib>
@@ -209,7 +209,7 @@ if ((source_date_epoch = getenv("SOURCE_DATE_EPOCH")) == NULL ||
### Go
-```
+```go
import (
"fmt"
"os"
@@ -234,13 +234,13 @@ if source_date_epoch == "" {
### PHP
-```
+```php
\date('Y', (int)\getenv('SOURCE_DATE_EPOCH') ?: \time())
```
### Emacs-Lisp
-```
+```elisp
(current-time-string
(when (getenv "SOURCE_DATE_EPOCH")
(seconds-to-time
@@ -250,7 +250,7 @@ if source_date_epoch == "" {
### OCaml
-```
+```ocaml
let build_date =
try
float_of_string (Sys.getenv "SOURCE_DATE_EPOCH")
@@ -260,7 +260,7 @@ let build_date =
### Java / gradle
-```
+```groovy
def buildDate = System.getenv("SOURCE_DATE_EPOCH") == null ?
new java.util.Date() :
new java.util.Date(1000 * Long.parseLong(System.getenv("SOURCE_DATE_EPOCH")))
@@ -268,7 +268,7 @@ def buildDate = System.getenv("SOURCE_DATE_EPOCH") == null ?
### Javascript / node.js
-```
+```javascript
var timestamp = new Date(process.env.SOURCE_DATE_EPOCH ? (process.env.SOURCE_DATE_EPOCH * 1000) : new Date().getTime());
// Alternatively, to ensure a fixed timezone:
@@ -281,7 +281,7 @@ if (process.env.SOURCE_DATE_EPOCH) {
### Coffeescript
-```
+```coffeescript
now = new Date()
if process.env.SOURCE_DATE_EPOCH
now = new Date((process.env.SOURCE_DATE_EPOCH * 1000) + (now.getTimezoneOffset() * 60000))
@@ -290,7 +290,7 @@ if process.env.SOURCE_DATE_EPOCH
### Ruby
-```
+```ruby
if ENV['SOURCE_DATE_EPOCH'].nil?
now = Time.now
else
@@ -330,6 +330,7 @@ let now = match env::var("SOURCE_DATE_EPOCH") {
};
```
or
+
```rust
use chrono::{DateTime, NaiveDateTime, Utc};
use std::env;
@@ -348,7 +349,7 @@ let now = match env::var("SOURCE_DATE_EPOCH") {
Add the following property in the `pom.xml` file:
-```
+```xml
<properties>
<project.build.outputTimestamp>
${env.SOURCE_DATE_EPOCH}
@@ -360,7 +361,7 @@ Add the following property in the `pom.xml` file:
Set the following properties for the Zip Task that creates the `.jar` file:
-```
+```groovy
// Normalizes the ZIP and JAR archives
tasks.withType(Zip) {
preserveFileTimestamps = false
@@ -402,7 +403,7 @@ def extendedTimestamp = buildInstant.toString()
`debian/strip-nondeterminism/a2x`:
-```
+```sh
#!/bin/sh
# Depends: faketime
# Eventually the upstream tool should support SOURCE_DATE_EPOCH internally.
@@ -412,7 +413,7 @@ exec env NO_FAKE_STAT=1 faketime -f "$(TZ=UTC date -d "@$SOURCE_DATE_EPOCH" +'%Y
`debian/rules`:
-```
+```make
export PATH := $(CURDIR)/debian/strip-nondeterminism:$(PATH)
```
@@ -442,29 +443,29 @@ In Debian, this is automatically set to the same time as the latest entry in `de
4. If none of the above options are good (you should have a ''very good reason'') then package maintainers may set and export this variable manually in `debian/rules`:
- ```
- export SOURCE_DATE_EPOCH ?= $(shell dpkg-parsechangelog -STimestamp)
- ```
+```make
+export SOURCE_DATE_EPOCH ?= $(shell dpkg-parsechangelog -STimestamp)
+```
- If you need/want to support dpkg versions earlier than 1.18.8:
+If you need/want to support dpkg versions earlier than 1.18.8:
- ```
- export SOURCE_DATE_EPOCH ?= $(shell dpkg-parsechangelog -SDate | date -f- +%s)
- ```
+```make
+export SOURCE_DATE_EPOCH ?= $(shell dpkg-parsechangelog -SDate | date -f- +%s)
+```
- If you need/want to support dpkg versions earlier than 1.17.0:
+If you need/want to support dpkg versions earlier than 1.17.0:
- ```
- export SOURCE_DATE_EPOCH ?= $(shell dpkg-parsechangelog | grep -Po '^Date: \K.*' | date -f- +%s)
- ```
+```make
+export SOURCE_DATE_EPOCH ?= $(shell dpkg-parsechangelog | grep -Po '^Date: \K.*' | date -f- +%s)
+```
- This snippet is believed to work on dpkg versions as far back as 2003.
+This snippet is believed to work on dpkg versions as far back as 2003.
### Git
To set `SOURCE_DATE_EPOCH` to the last modification of a Git repository you can use `git log`. For example:
-```
+```make
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
```
@@ -475,30 +476,30 @@ We are persuading upstream tools to support `SOURCE_DATE_EPOCH` directly. You ma
Complete:
-* [busybox](http://lists.busybox.net/pipermail/busybox/2021-June/088880.html) (>1.33.1)
-* [clang](https://github.com/llvm/llvm-project/commit/2c090162746a6b901c5639562c090e4bb2b7327e) (>= 16.0.0)
-* [cmake](https://gitlab.kitware.com/cmake/cmake/merge_requests/432) (>= 3.8.0)
-* [debhelper](https://bugs.debian.org/791823) (>= 9.20151004)
-* [distro-info](https://bugs.debian.org/1034422) (>= 1.6)
-* [docbook-utils](https://bugs.debian.org/800797) (Debian >= 0.6.14-3.1, upstream TODO)
-* [doxygen](https://bugs.debian.org/792201) (>= [1.8.12](https://github.com/doxygen/doxygen/commit/9a2c7bbfb0c53b4532db7280e6804c7ce76d70a3), Debian pending)
-* [epydoc](https://bugs.debian.org/790899) (>= 3.0.1+dfsg-8, upstream [pending](https://sourceforge.net/p/epydoc/bugs/368/))
-* [gcc](https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=e3e8c48c4a494d9da741c1c8ea6c4c0b7c4ff934) (>= 7, Debian >= 5.3.1-17, Debian >= 6.1.1-1)
-* [gettext](https://bugs.debian.org/792687) (>=0.20)
-* [ghostscript](https://bugs.debian.org/794004) (Debian >= 9.16~dfsg-1, upstream [unfortunately rejected](http://bugs.ghostscript.com/show_bug.cgi?id=696765) due to additional constraints they have)
-* [groff](https://bugs.debian.org/762854) (Debian >= 1.22.3-2, upstream [pending](https://lists.gnu.org/archive/html/groff/2015-11/msg00038.html))
-* [help2man](https://bugs.debian.org/787444) (>= 1.47.1)
-* [libxslt](https://bugs.debian.org/791815) (>= [1.1.29](https://bugzilla.gnome.org/show_bug.cgi?id=758148), Debian >= 1.1.28-3)
-* [man2html](https://bugs.debian.org/796130) (Debian >= 1.6g-8, [needs forwarding](https://sources.debian.net/src/man2html/1.6g-8/debian/patches/035-source-date-epoch.patch/))
-* [mkdocs](https://bugs.debian.org/824266) (>= [0.16](https://github.com/mkdocs/mkdocs/pull/939/commits/8b006bd7fda55e47e29412896c511c7244398f82), Debian pending)
-* [ocamldoc](https://bugs.debian.org/794586) (>= [4.03.0](https://github.com/ocaml/ocaml/commit/0319173b7d02008e4ce6b81dceaf7c32cf5f8a6f), Debian >= 4.02.3-1)
-* [pydoctor](https://bugs.debian.org/807166) (>= 0.5+git20151204)
-* [rcc](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=894476) (Qt5 >= [5.13.0](https://code.qt.io/cgit/qt/qtbase.git/commit/?id=1ffcca4cc208c48ddb06b6a23abf1756f9724351), Debian TODO)
-* [rpm upstream](https://github.com/rpm-software-management/rpm/pull/144) (>4.13 other relevant patches linked in there)
-* [sphinx](https://github.com/sphinx-doc/sphinx/pull/1954) (>= 1.4, Debian >= 1.3.1-3)
-* [texi2html](https://bugs.debian.org/783475) (Debian >= 1.82+dfsg1-4, [needs forwarding](https://sources.debian.net/src/texi2html/1.82%2Bdfsg1-5/debian/patches/05_reproducible-build/))
-* [texlive-bin](https://bugs.debian.org/792202) (>= 2016.20160512.41045)
-* [txt2man](https://bugs.debian.org/790801) (>= [1.5.7](https://github.com/mvertes/txt2man/pull/1), Debian >= 1.5.6-4)
+* [busybox](http://lists.busybox.net/pipermail/busybox/2021-June/088880.html) (`>` 1.33.1)
+* [clang](https://github.com/llvm/llvm-project/commit/2c090162746a6b901c5639562c090e4bb2b7327e) (`>=` 16.0.0)
+* [cmake](https://gitlab.kitware.com/cmake/cmake/merge_requests/432) (`>=` 3.8.0)
+* [debhelper](https://bugs.debian.org/791823) (`>=` 9.20151004)
+* [distro-info](https://bugs.debian.org/1034422) (`>=` 1.6)
+* [docbook-utils](https://bugs.debian.org/800797) (Debian `>=` 0.6.14-3.1, upstream TODO)
+* [doxygen](https://bugs.debian.org/792201) (`>=` [1.8.12](https://github.com/doxygen/doxygen/commit/9a2c7bbfb0c53b4532db7280e6804c7ce76d70a3), Debian pending)
+* [epydoc](https://bugs.debian.org/790899) (`>=` 3.0.1+dfsg-8, upstream [pending](https://sourceforge.net/p/epydoc/bugs/368/))
+* [gcc](https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=e3e8c48c4a494d9da741c1c8ea6c4c0b7c4ff934) (`>=` 7, Debian `>=` 5.3.1-17, Debian `>=` 6.1.1-1)
+* [gettext](https://bugs.debian.org/792687) (`>=` 0.20)
+* [ghostscript](https://bugs.debian.org/794004) (Debian `>=` 9.16~dfsg-1, upstream [unfortunately rejected](http://bugs.ghostscript.com/show_bug.cgi?id=696765) due to additional constraints they have)
+* [groff](https://bugs.debian.org/762854) (Debian `>=` 1.22.3-2, upstream [pending](https://lists.gnu.org/archive/html/groff/2015-11/msg00038.html))
+* [help2man](https://bugs.debian.org/787444) (`>=` 1.47.1)
+* [libxslt](https://bugs.debian.org/791815) (`>=` [1.1.29](https://bugzilla.gnome.org/show_bug.cgi?id=758148), Debian `>=` 1.1.28-3)
+* [man2html](https://bugs.debian.org/796130) (Debian `>=` 1.6g-8, [needs forwarding](https://sources.debian.net/src/man2html/1.6g-8/debian/patches/035-source-date-epoch.patch/))
+* [mkdocs](https://bugs.debian.org/824266) (`>=` [0.16](https://github.com/mkdocs/mkdocs/pull/939/commits/8b006bd7fda55e47e29412896c511c7244398f82), Debian pending)
+* [ocamldoc](https://bugs.debian.org/794586) (`>=` [4.03.0](https://github.com/ocaml/ocaml/commit/0319173b7d02008e4ce6b81dceaf7c32cf5f8a6f), Debian `>=` 4.02.3-1)
+* [pydoctor](https://bugs.debian.org/807166) (`>=` 0.5+git20151204)
+* [rcc](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=894476) (Qt5 `>=` [5.13.0](https://code.qt.io/cgit/qt/qtbase.git/commit/?id=1ffcca4cc208c48ddb06b6a23abf1756f9724351), Debian TODO)
+* [rpm upstream](https://github.com/rpm-software-management/rpm/pull/144) (`>` 4.13 other relevant patches linked in there)
+* [sphinx](https://github.com/sphinx-doc/sphinx/pull/1954) (`>=` 1.4, Debian `>=` 1.3.1-3)
+* [texi2html](https://bugs.debian.org/783475) (Debian `>=` 1.82+dfsg1-4, [needs forwarding](https://sources.debian.net/src/texi2html/1.82%2Bdfsg1-5/debian/patches/05_reproducible-build/))
+* [texlive-bin](https://bugs.debian.org/792202) (`>=` 2016.20160512.41045)
+* [txt2man](https://bugs.debian.org/790801) (`>=` [1.5.7](https://github.com/mvertes/txt2man/pull/1), Debian `>=` 1.5.6-4)
Or you can [search in all Debian sources](https://codesearch.debian.net/search?perpkg=1&q=SOURCE_DATE_EPOCH).
View it on GitLab: https://salsa.debian.org/reproducible-builds/reproducible-website/-/compare/aa5e9da9c8e92cf87e787acdb9671d35683e8fe4...db0107186beed128d3702b9c1a5493e65f70db71
--
This project does not include diff previews in email notifications.
View it on GitLab: https://salsa.debian.org/reproducible-builds/reproducible-website/-/compare/aa5e9da9c8e92cf87e787acdb9671d35683e8fe4...db0107186beed128d3702b9c1a5493e65f70db71
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20240525/c8be5572/attachment.htm>
More information about the rb-commits
mailing list