From: Lady Date: Sun, 19 May 2024 21:16:42 +0000 (-0400) Subject: Remove stat dependency X-Git-Tag: 0.9.0~3 X-Git-Url: https://git.ladys.computer/Shushe/commitdiff_plain/b620a662b669862cd7bf01aa06c8ad3de2f1a7f4 Remove stat dependency This is, strictly speaking, a downgrade in functionality, with the upside of reducing reliance on non·Posix programs (namely `stat`). A better, Posix‐compliant solution is to archive an empty file with the correct modification time and then list out the time from that archive; however, as far as I’m aware, it’s not possible to obtain an implementation of the `pax` utility which actually supports this. macOS only supports a very limited subset of the `listopt` option, and only for pax archives (not tarballs); other implementations don’t seem to support it at all. --- diff --git a/GNUmakefile b/GNUmakefile index 0156970..73c8057 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -36,7 +36,6 @@ override define makefileinfo ║│ • rm │║ ║│ • sed │║ ║│ • sleep │║ -║│ • stat │║ ║│ • test │║ ║│ • touch │║ ║│ • tr │║ @@ -117,7 +116,6 @@ PRINTF := printf RM := rm SED := sed SLEEP := sleep -STAT := stat TEST := test TOUCH := touch TR := tr @@ -257,10 +255,17 @@ override silent := $(if $(VERBOSE),,@) # (callable) Get the modified time of the provided file. # -# This is messy; there is no portable way of using `stat´. +# Only the date·time information available via `ls -l´ is supported; that is, only minute precision for files newer than six months, and only day precision for files which are older. +# This is, unfortunately, the best that can be done in pure Posix as of now. +# +# There is an easier implementation which provides the full date·time by archiving an empty file and then reading it back out of the archive :— +# +# $(shell LC_TIME=POSIX TZ=UTC0 $(TOUCH) -m -r $(callquote,$1) $(BUILDDIR)/.mtime && $(PAX) -w -x ustar $(BUILDDIR)/.mtime | $(PAX) -v -o 'listopt=%(mtime=%Y-%m-%dT%H:%M:%SZ)T') +# +# However, it depends on the `listopt´ option in `pax´, which (despite being specified in Posix) no implementations actually support. # # ☡ This variable creates a subshell every time it is computed. -override modtime = $(shell if $(STAT) --version 2> /dev/null | $(GREP) -q GNU; then $(DATE) -u -d "@$$(TZ= $(STAT) -c '%Y' $(call quote,$1))" '+%Y-%m-%dT%H:%M:%SZ'; else TZ= $(STAT) -f '%Sm' -t '%Y-%m-%dT%H:%M:%SZ' $(call quote,$1); fi) +override modtime = $(shell { $(DATE) -u '+%Y-%m'; LC_TIME=POSIX TZ=UTC0 ls -q -A -l $(call quote,$1) | $(SED) 's/\([^ ]* \{1,\}\)\{5\}\(\([^ ]* \{1,\}\)\{3\}\).*/\2/;s/ \([0123456789]\) / 0\1 /;s/Jan/01/;s/Feb/02/;s/Mar/03/;s/Apr/04/;s/May/05/;s/Jun/06/;s/Jul/07/;s/Aug/08/;s/Sep/09/;s/Oct/10/;s/Nov/11/;s/Dec/12/;s/\([0123456789]\{2\}\) *\([0123456789]\{2\}\) *\([0123456789]\{4\}\)/\3-\1-\2T00:00:00Z/;s/\([0123456789]\{2\}\) *\([0123456789]\{2\}\) *\([0123456789:]\{5\}\)/XXXX-\1-\2T\3:00Z/'; } | $(TR) -d ' ' | $(AWK) -F '-' 'NR==1{year=$$1;month=$$2}$$1=="XXXX"&&$$2<=month{print year"-"$$2"-"$$3}$$1=="XXXX"&&$$2>month{print year-1"-"$$2"-"$$3}NR>1&&$$1!="XXXX"') # ─ ¶ Recipe Variable Definitions ───────────────────────────────────── @@ -502,7 +507,7 @@ install : $(call installed,$(recursivefiles) $(installablefiles)) ; # List all source files and includes and their computed types. list : - @$(PRINTF) '%b' $(call quote,$(foreach file,$(sort $(sourcefiles)) $(sort $(sourceincludes)),\0033[1m$(file)\0033[22m|$(call typeoffile,$(file))|[\0033[3m$(if $(filter $(file),$(xmlfiles)),xml,$(if $(filter $(file),$(plaintextfiles)),text,asset))$(if $(filter $(file),$(sourceincludes)),|include,)\0033[23m]$(if $(call dependencies,$(file))$(call recursives,$(file)), $(strip $(foreach recursive,$(call recursives,$(file)),\0033[93;41m•|Recursive|Dependency|\0033[39;49m|$(recursive)) $(foreach dependency,$(call dependencies,$(file)),\0033[2m•|Dependency|\0033[22m|$(dependency))))$(if $(filter $(file),$(sourcefiles)), →|<\0033[4m/$(call destination,$(file))\0033[24m>,) )) | $(TR) ' |' '\n ' + @$(PRINTF) '%b' $(call quote,$(foreach file,$(sort $(sourcefiles)) $(sort $(sourceincludes)),\0033[1m$(file)\0033[22m|$(call typeoffile,$(file))|[\0033[3m$(if $(filter $(file),$(xmlfiles)),xml,$(if $(filter $(file),$(plaintextfiles)),text,asset))$(if $(filter $(file),$(sourceincludes)),|include,)\0033[23m] Modified:|$(call modtime,$(file))$(if $(call dependencies,$(file))$(call recursives,$(file)), $(strip $(foreach recursive,$(call recursives,$(file)),\0033[93;41m•|Recursive|Dependency|\0033[39;49m|$(recursive)) $(foreach dependency,$(call dependencies,$(file)),\0033[2m•|Dependency|\0033[22m|$(dependency))))$(if $(filter $(file),$(sourcefiles)), →|<\0033[4m/$(call destination,$(file))\0033[24m>,) )) | $(TR) ' |' '\n ' # Lists out the destinations of all resulting files (relative to `DESTDIR´). listout : diff --git a/README.markdown b/README.markdown index d459604..952f4ee 100644 --- a/README.markdown +++ b/README.markdown @@ -57,13 +57,6 @@ Details on particular programs are given below; if a program is not listed, it is assumed that any Posix‐compliant implementation will work. -### `date` - -This is a Posix utility, but ⛩️📰 书社 currently depends on - unspecified behaviour. -When the G·N·U version of `stat` is being used, then the G·N·U version - of `date` is also expected. - ### `file` This is a Posix utility, but ⛩️📰 书社 currently depends on @@ -108,13 +101,6 @@ This is a Posix utility, but not included in the Linux Standard Base or installed by default in many distributions. Only `ustar` format support is required. -### `stat` - -This is not a Posix utility, and nor is it particularly portable. -To get around incompatibilities, ⛩️📰 书社 attempts to recognize G·N·U - `stat` by searching for the string `GNU` when invoked with the - `--version` option, and falls back to B·S·D behaviour otherwise. - ### `uudecode` and `uuencode` These are Posix utilities, but not included in the Linux Standard Base @@ -212,7 +198,6 @@ In every case, you may supply your own implementation by overriding the - `rm` - `sed` - `sleep` -- `stat` (BSD *or* GNU) - `test` - `touch` - `tr` @@ -579,6 +564,10 @@ The following params are made available globally in parsers and - **`SRCTIME`:** The time at which the source file was last modified. + Due to limitations in Posix, this time will only have minute + precision if the file was modified in the last six months, and will + only have day precision if the file is older. + Users should not expect this value to be particularly stable. - **`THISREV`:** The value of the `THISREV` variable (if present).