diff --git a/.gitignore b/.gitignore index d129e9f..c65b28e 100644 --- a/.gitignore +++ b/.gitignore @@ -103,6 +103,7 @@ /build/test_pass/sudo_iso_mount /build/twm_cfg /build/virtualbox.img +/COMMIT_TIMESTAMP /deploy-screenshots/bochs-anim.gif /deploy-screenshots/bochs.png /deploy-screenshots/dosbox-anim.gif diff --git a/Makefile b/Makefile index 6c7bc51..d8a6a06 100644 --- a/Makefile +++ b/Makefile @@ -34,8 +34,8 @@ define date_command date -d ${1} ${2}; \ fi endef -commit_timestamp = "$$(${call date_command,"${COMMIT_TIMESTAMP_ISO_8601}",'+%Y%m%d%H%m.%S'})" -commit_timestamp_iso_8601 = ${COMMIT_TIMESTAMP_ISO_8601} +real_commit_timestamp_iso_8601 = $$(if test "${COMMIT_TIMESTAMP_ISO_8601}" = "FILE"; then cat COMMIT_TIMESTAMP; else echo "${COMMIT_TIMESTAMP_ISO_8601}"; fi) +commit_timestamp = "$$(${call date_command,"${real_commit_timestamp_iso_8601}",'+%Y%m%d%H%m.%S'})" reproducible_os_filename="${bld}/reproduced_$$(basename "${os_filename}")" @@ -50,7 +50,8 @@ built_files += ${bld}/check_makefile \ ${bld}/makefile_non_file_targets \ ${bld}/makefile_phony \ ${bld}/makefile_targets \ - ${bld}/makefile_w_arnings + ${bld}/makefile_w_arnings \ + COMMIT_TIMESTAMP include Makefile.example-os include Makefile.test-example-os @@ -62,6 +63,9 @@ more_built_directories = ${built_directories} ${bld} in-guix: .gitignore \ ${bld}/check_makefile +COMMIT_TIMESTAMP: + echo "This file is injected by the Guix build recipe." + ${bld}/makefile_w_arnings: | $${@D} ${built_files}: | $${@D} @@ -71,7 +75,7 @@ ${bld}/makefile_w_arnings: ${Makefiles} OS_FILENAME=${OS_FILENAME} \ BUILD_DIR=${BUILD_DIR} \ SCREENSHOTS_DIR=${SCREENSHOTS_DIR} \ - COMMIT_TIMESTAMP_ISO_8601=${COMMIT_TIMESTAMP_ISO_8601} \ + COMMIT_TIMESTAMP_ISO_8601=${real_commit_timestamp_iso_8601} \ test 2>$@ 1>/dev/null \ || cat $@ @@ -92,7 +96,7 @@ ${bld}/makefile_database: ${Makefiles} ${bld}/check_makefile_w_arnings OS_FILENAME=${OS_FILENAME} \ BUILD_DIR=${BUILD_DIR} \ SCREENSHOTS_DIR=${SCREENSHOTS_DIR} \ - COMMIT_TIMESTAMP_ISO_8601=${COMMIT_TIMESTAMP_ISO_8601} \ + COMMIT_TIMESTAMP_ISO_8601=${real_commit_timestamp_iso_8601} \ | sed -n -e '/^# Make data base,/,$$p' > $@ ${bld}/makefile_database_files: ${bld}/makefile_database ${bld}/check_makefile_w_arnings @@ -138,7 +142,7 @@ clean_reproducible: ${bld}/check_makefile make OS_FILENAME=${reproducible_os_filename} \ BUILD_DIR=${bld}/reproducible \ SCREENSHOTS_DIR=${bld}/reproducible/screenshots \ - COMMIT_TIMESTAMP_ISO_8601=${COMMIT_TIMESTAMP_ISO_8601} \ + COMMIT_TIMESTAMP_ISO_8601=${real_commit_timestamp_iso_8601} \ clean; \ fi @@ -158,13 +162,13 @@ ${bld}/test_pass/noemu_reproducible_build: ${os_filename} ${bld}/os.hex_with_off make OS_FILENAME=${reproducible_os_filename} \ BUILD_DIR=${bld}/reproducible \ SCREENSHOTS_DIR=${bld}/reproducible/screenshots \ - COMMIT_TIMESTAMP_ISO_8601=${COMMIT_TIMESTAMP_ISO_8601} \ + COMMIT_TIMESTAMP_ISO_8601=${real_commit_timestamp_iso_8601} \ clean unset MAKEFLAGS MAKELEVEL MAKE_TERMERR MFLAGS; \ make OS_FILENAME=${reproducible_os_filename} \ BUILD_DIR=${bld}/reproducible \ SCREENSHOTS_DIR=${bld}/reproducible/screenshots \ - COMMIT_TIMESTAMP_ISO_8601=${COMMIT_TIMESTAMP_ISO_8601} \ + COMMIT_TIMESTAMP_ISO_8601=${real_commit_timestamp_iso_8601} \ ${reproducible_os_filename} \ ${bld}/reproducible/os.hex_with_offsets # Check that the second build produced the same file. @@ -186,6 +190,6 @@ ${bld}/test_pass/noemu_reproducible_build: ${os_filename} ${bld}/os.hex_with_off make OS_FILENAME=${reproducible_os_filename} \ BUILD_DIR=${bld}/reproducible \ SCREENSHOTS_DIR=${bld}/reproducible/screenshots \ - COMMIT_TIMESTAMP_ISO_8601=${COMMIT_TIMESTAMP_ISO_8601} \ + COMMIT_TIMESTAMP_ISO_8601=${real_commit_timestamp_iso_8601} \ clean touch $@ diff --git a/Makefile.example-os b/Makefile.example-os index 67b952e..da255b5 100644 --- a/Makefile.example-os +++ b/Makefile.example-os @@ -103,7 +103,8 @@ ${bld}/os.iso: ${bld}/iso_files/os.zip ${bld}/iso_files/boot/iso_boot.sys ./util ! test -d ${bld}/iso_files.tmp cp -a ${cp_T_option} -- ${bld}/iso_files ${bld}/iso_files.tmp find ${bld}/iso_files.tmp -depth -exec touch -t ${commit_timestamp} '{}' ';' - UTILS="$$PWD/utils" ./utils/faketime.sh ${commit_timestamp_iso_8601} sh -c '(cd ./${bld}/iso_files.tmp/ && "$$UTILS/mkisofs" \ + UTILS="$$PWD/utils" ./utils/faketime.sh ${real_commit_timestamp_iso_8601} \ + sh -c '(cd ./${bld}/iso_files.tmp/ && "$$UTILS/mkisofs" \ --input-charset utf-8 \ -rock \ -joliet \ @@ -182,12 +183,12 @@ os_fat12_partition = "$@@@${bytes_fat12_start}" ${bld}/os.fat12: ${bld}/os.zip ${dep_bytes_fat12_size} ${dep_bytes_fat12_start} ${dep_sectors_os_size} \ ./utils/mformat ./utils/mcopy ${bld}/check_makefile set -x; dd if=/dev/zero bs=${sector_size} count=${sectors_os_size} of=$@ - ./utils/faketime.sh ${commit_timestamp_iso_8601} ./utils/mformat -v "Example OS" \ + ./utils/faketime.sh ${real_commit_timestamp_iso_8601} ./utils/mformat -v "Example OS" \ -T ${sectors_fat12_size} \ -h ${os_floppy_chs_h} \ -s ${os_floppy_chs_s} \ -i ${os_fat12_partition} - ./utils/faketime.sh ${commit_timestamp_iso_8601} ./utils/mcopy -i ${os_fat12_partition} $< "::os.zip" + ./utils/faketime.sh ${real_commit_timestamp_iso_8601} ./utils/mcopy -i ${os_fat12_partition} $< "::os.zip" ${bld}/iso_files/os.zip: ${bld}/os.zip ${bld}/check_makefile # TODO: make it so that the various file formats are mutual quines: diff --git a/guix.scm b/guix.scm index 99f82f7..898b5de 100644 --- a/guix.scm +++ b/guix.scm @@ -21,6 +21,10 @@ (guix build-system gnu) (guix gexp) (guix) + (guix build utils) + (ice-9 popen) + (ice-9 rdelim) + (gnu packages version-control) (gnu packages assembly) (gnu packages base) (gnu packages mtools) @@ -55,50 +59,65 @@ (synopsis ""))) (define-public os-test-framework - (package - (name "os-test-framework") - (version "0.0") - (build-system gnu-build-system) - (arguments - `(#:phases - (modify-phases %standard-phases - ;; unpack ;; this phase is enabled - ;; patch-source-shebangs ;; this phase is enabled - (add-after 'patch-source-shebangs 'make-clean - (lambda* (#:key inputs #:allow-other-keys) - (invoke "make" "clean" "COMMIT_TIMESTAMP_ISO_8601=1970-01-01T00:00:00+00:00"))) - (delete 'configure) - (add-before 'build 'make-.gitignore-writable - (lambda* (#:key inputs #:allow-other-keys) - (invoke "chmod" "+w" ".gitignore"))) - ;; build ;; this phase is enabled - (delete 'check) ;; disabled for now, will enable it later. - (replace 'install - (lambda* (#:key outputs #:allow-other-keys) - (let ((out (lambda (f) (string-append (assoc-ref outputs "out") f)))) ;; TODO: use path-append or something similar - (invoke "mkdir" "-p" (out "/bin")) - (invoke "cp" "os.bat" (out "/bin/os.bat"))))) - (delete 'patch-shebangs) - (delete 'strip)) - #:parallel-build? #t - #:make-flags '("in-guix" "COMMIT_TIMESTAMP_ISO_8601=1970-01-01T00:00:00+00:00"))) - (native-inputs - `(("nasm" ,nasm) - ("which" ,which) - ("mtools" ,mtools) - ("mkisofs" ,xorriso) - ("zip" ,zip) - ("faketime" ,faketime) - ("gdisk" ,gptfdisk) - ("column" ,util-linux))) - (description "Test framework to run an OS in multiple emulators, as a guest graphical / text shell on linux, and so on.") - (home-page "https://github.com/jsmaniac/os-test-framework") - (license "CC0-1.0") - (source (local-file - (current-source-directory) - #:recursive? #t - #:select? (lambda (file stat) - (not (equal? (basename file) ".git"))))) - (synopsis ""))) + (let ((makefile-commit-timestamp + '(string-append + "COMMIT_TIMESTAMP_ISO_8601=" + ;; (let* ((pipe (open-input-pipe "git log -1 --pretty=format:%ad --date=iso8601-strict")) + ;; (timestamp (read-line pipe))) + ;; (close-pipe pipe) + ;; timestamp) + "FILE"))) + (package + (name "os-test-framework") + (version "0.0") + (build-system gnu-build-system) + (arguments + `(#:phases + (modify-phases %standard-phases + ;; unpack ;; this phase is enabled + ;; patch-source-shebangs ;; this phase is enabled + (add-after 'patch-source-shebangs 'make-clean + (lambda* (#:key inputs #:allow-other-keys) + (invoke "cp" "COMMIT_TIMESTAMP" "COMMIT_TIMESTAMP.bak") + (invoke "make" "clean" ,makefile-commit-timestamp) + (invoke "cp" "COMMIT_TIMESTAMP.bak" "COMMIT_TIMESTAMP"))) + (delete 'configure) + (add-before 'build 'make-.gitignore-writable + (lambda* (#:key inputs #:allow-other-keys) + (invoke "chmod" "+w" ".gitignore"))) + ;; build ;; this phase is enabled + (delete 'check) ;; disabled for now, will enable it later. + (replace 'install + (lambda* (#:key outputs #:allow-other-keys) + (let ((out (lambda (f) (string-append (assoc-ref outputs "out") f)))) ;; TODO: use path-append or something similar + (invoke "mkdir" "-p" (out "/bin")) + (invoke "cp" "os.bat" (out "/bin/os.bat"))))) + (delete 'patch-shebangs) + (delete 'strip)) + #:parallel-build? #t + #:make-flags + (list "in-guix" ,makefile-commit-timestamp))) + (native-inputs + `(("git" ,git) + ("nasm" ,nasm) + ("which" ,which) + ("mtools" ,mtools) + ("mkisofs" ,xorriso) + ("zip" ,zip) + ("faketime" ,faketime) + ("gdisk" ,gptfdisk) + ("column" ,util-linux))) + (description "Test framework to run an OS in multiple emulators, as a guest graphical / text shell on linux, and so on.") + (home-page "https://github.com/jsmaniac/os-test-framework") + (license "CC0-1.0") + (source (let () + (invoke "sh" "-c" + "git log -1 --pretty=format:%ad --date=iso8601-strict > COMMIT_TIMESTAMP") + (local-file + (current-source-directory) + #:recursive? #t + #:select? (lambda (file stat) + (not (equal? (basename file) ".git")))))) + (synopsis "")))) os-test-framework