Skip to content
Snippets Groups Projects
Commit 929cd939 authored by Luigi Scarso's avatar Luigi Scarso
Browse files

support for SOURCE_DATE_EPOCH and utc -- code & manual

parent 574708af
Branches
Tags
No related merge requests found
......@@ -56,44 +56,32 @@ similar fashion as the other \TEX\ engines. Some options are accepted but have n
consequence. The following command|-|line options are understood:
\starttabulate[|lT|p|]
\NC --credits \NC display credits and exit \NC \NR
\NC --debug-format \NC enable format debugging \NC \NR
\NC --draftmode \NC switch on draft mode i.e.\ generate no output in \PDF\ mode \NC \NR
\NC --[no-]file-line-error \NC disable/enable \type {file:line:error} style messages \NC \NR
\NC --[no-]file-line-error-style \NC aliases of \type {--[no-]file-line-error} \NC \NR
\NC --fmt=FORMAT \NC load the format file \type {FORMAT} \NC\NR
\NC --lua=FILE \NC load and execute a \LUA\ initialization script\NC\NR
\NC --safer \NC disable easily exploitable \LUA\ commands \NC\NR
\NC --nosocket \NC disable the \LUA\ socket library \NC\NR
\NC --halt-on-error \NC stop processing at the first error\NC \NR
\NC --help \NC display help and exit \NC\NR
\NC --ini \NC be \type {iniluatex}, for dumping formats \NC\NR
\NC --interaction=STRING \NC set interaction mode: \type {batchmode}, \type {nonstopmode},
\type {scrollmode} or \type {errorstopmode} \NC \NR
\NC --halt-on-error \NC stop processing at the first error\NC \NR
\NC --kpathsea-debug=NUMBER \NC set path searching debugging flags according to
the bits of \type {NUMBER} \NC \NR
\NC --interaction=STRING \NC set interaction mode: \type {batchmode}, \type {nonstopmode}, \type {scrollmode} or \type {errorstopmode} \NC \NR
\NC --jobname=STRING \NC set the job name to \type {STRING} \NC \NR
\NC --kpathsea-debug=NUMBER \NC set path searching debugging flags according to the bits of \type {NUMBER} \NC \NR
\NC --lua=FILE \NC load and execute a \LUA\ initialization script \NC\NR
\NC --[no-]mktex=FMT \NC disable/enable \type {mktexFMT} generation with \type {FMT} is \type {tex} or \type {tfm} \NC \NR
\NC --nosocket \NC disable the \LUA\ socket library \NC\NR
\NC --output-comment=STRING \NC use \type {STRING} for \DVI\ file comment instead of date (no effect for \PDF) \NC \NR
\NC --output-directory=DIR \NC use \type {DIR} as the directory to write files to \NC \NR
\NC --output-format=FORMAT \NC use \type {FORMAT} for job output; \type {FORMAT} is \type {dvi} or \type {pdf} \NC \NR
\NC --progname=STRING \NC set the program name to \type {STRING} \NC \NR
\NC --version \NC display version and exit \NC \NR
\NC --credits \NC display credits and exit \NC \NR
\NC --recorder \NC enable filename recorder \NC \NR
\NC --output-comment=STRING \NC use \type {STRING} for \DVI\ file comment
instead of date (no effect for \PDF) \NC \NR
\NC --output-directory=DIR \NC use \type {DIR} as the directory to write
files to \NC \NR
\NC --draftmode \NC switch on draft mode i.e.\ generate no
output in \PDF\ mode \NC \NR
\NC --output-format=FORMAT \NC use \type {FORMAT} for job output; \type
{FORMAT} is \type {dvi} or \type {pdf} \NC
\NR
\NC --safer \NC disable easily exploitable \LUA\ commands \NC\NR
\NC --[no-]shell-escape \NC disable/enable system calls \NC \NR
\NC --enable-write18 \NC enable system calls \NC \NR
\NC --disable-write18 \NC disable system calls \NC \NR
\NC --shell-restricted \NC restrict system calls to a list of commands
given in \type {texmf.cnf} \NC \NR
\NC --debug-format \NC enable format debugging \NC \NR
\NC --[no-]file-line-error \NC disable/enable \type {file:line:error} style
messages \NC \NR
\NC --[no-]file-line-error-style \NC aliases of \type {--[no-]file-line-error} \NC \NR
\NC --jobname=STRING \NC set the job name to \type {STRING} \NC \NR
\NC --[no-]mktex=FMT \NC disable/enable \type {mktexFMT} generation
with \type {FMT} is \type {tex} or \type
{tfm} \NC \NR
\NC --shell-restricted \NC restrict system calls to a list of commands given in \type {texmf.cnf} \NC \NR
\NC --synctex=NUMBER \NC enable \type {synctex} \NC \NR
\NC --utc \NC use utc times when applicable \NC \NR
\NC --version \NC display version and exit \NC \NR
\stoptabulate
Some of the traditional flags are just ignored: \type {--etex}, \type
......@@ -543,6 +531,42 @@ At some point (this also depends on distributions) \LUATEX\ might have these
libraries loaded on demand. For this reason you can best use \type {require} to
make sure they are loaded.
\section{Testing}
For development reasons you can influence the used startup date and time. This can
be done in two ways.
\startitemize[n]
\startitem
By setting the environmment variable \type {SOURCE_DATE_EPOCH}. This will
influence the \TEX\ parameters \type {time} and \type {date}, the random seed,
the \PDF\ timestamp and the \PDF\ id that is derived from the time as well. This
variable is consulted when the \KPSE\ library is enabled. Resolving is
delegated to this library.
\stopitem
\startitem
By setting the \type {start_time} variable in the \type {texconfig} table; as
with other variables we use the internal name there. For compatibility
reasons we also honour a \type {SOURCE_DATE_EPOCH} entry. It should be noted
that there are no such variables in other engines and this method is only
relevant in case the while setup happens in \LUA.
\stopitem
\stopitemize
When Universal Time is needed, you can pass the flag \type {utc} to the engine. This
property also works when the date and time are set by \LUATEX\ itself. It has a
complementary entry \type {use_utf_time} in the \type {texconfig} table.
{\em To some extend a cleaner solution would be to have a flag that disables all
variable data in one go (like filenames and so) but we just follow the method
implemented in \PDFTEX\ where primitives are used to influence other properties.}
{\em In \CONTEXT\ we provide the command line argument \type {--nodates} that
does bit more disabling of dates.}
\stopchapter
\stopcomponent
No preview for this file type
......@@ -3,10 +3,7 @@
% \tex vs \type vs \syntax vs. \luatex
% \em \it \/
\startmode[nodates]
\enabledirectives[backend.date=no]
\nopdfcompression
\stopmode
% "context --nodates --nocompression luatex" can be used for comparison runs
\environment luatex-style
\environment luatex-logos
......
......@@ -576,6 +576,7 @@ static void init_kpse(void)
kpse_set_program_name(argv[0], user_progname);
init_shell_escape(); /* set up 'restrictedshell' */
init_start_time();
program_name_set = 1 ;
if (recorderoption) {
recorder_enabled = 1;
......@@ -859,6 +860,8 @@ void lua_initialize(int ac, char **av)
char *banner;
int kpse_init;
size_t len;
int starttime;
int utc;
static char LC_CTYPE_C[] = "LC_CTYPE=C";
static char LC_COLLATE_C[] = "LC_COLLATE=C";
static char LC_NUMERIC_C[] = "LC_NUMERIC=C";
......@@ -1035,6 +1038,25 @@ void lua_initialize(int ac, char **av)
}
}
starttime = -1 ;
get_lua_number("texconfig", "start_time", &starttime);
if (starttime < 0) {
/*
We provide this one for compatibility reasons and therefore also in
uppercase.
*/
get_lua_number("texconfig", "SOURCE_DATE_EPOCH", &starttime);
}
if (starttime >= 0) {
set_start_time(starttime);
}
utc = -1 ;
get_lua_boolean("texconfig", "use_utc_time", &utc);
if (utc >= 0 && utc <= 1) {
utc_option = utc;
}
fix_dumpname();
} else {
if (luainit) {
......
......@@ -148,26 +148,75 @@ void mk_shellcmdlist(char *v)
/* Called from maininit. Not static because also called from
luatexdir/lua/luainit.c. */
/*
In order to avoid all kind of time code in the backend code we use a function.
The start time can be overloaded in several ways:
(1) By setting the environmment variable SOURCE_DATE_EPOCH. This will influence
the tex parameters, random seed, pdf timestamp and pdf id that is derived
from the time. This variable is consulted when the kpse library is enabled
which is analogue to other properties.
(2) By setting the texconfig.start_time variable (as with other variables
we use the internal name there). This has the same effect as (1) and is
provided for when kpse is not used to set these variables or when an overloaded
is wanted. This is analogue to other properties.
When an utc time is needed one can provide the flag --utc. This property is
independent of this time hackery. This flag has a corresponding texconfig
option use_utc_time.
To some extend a cleaner solution would be to have a flag that disables all
variable data in one go (like filenames and so) but we just follow the method
implemented in pdftex where primitives are used tod disable it.
*/
static int start_time = -1;
int get_start_time(void) {
if (start_time < 0) {
char *source_date_epoch;
start_time = time((time_t *) NULL);
}
return start_time;
}
/*
This one is called as part of the kpse initialization which only happens
when this library is enabled.
*/
void init_start_time(void) {
if (start_time < 0) {
unsigned long long epoch;
char *endptr;
source_date_epoch = getenv("SOURCE_DATE_EPOCH");
if (source_date_epoch) {
/*
We don't really care how kpse sets up this variable but we prefer to
just use its abstract interface.
*/
/* char *source_date_epoch = getenv("SOURCE_DATE_EPOCH"); */
char *source_date_epoch = kpse_var_value("SOURCE_DATE_EPOCH");
if (source_date_epoch && source_date_epoch != '\0' ) {
errno = 0;
epoch = strtoull(source_date_epoch, &endptr, 10);
if (epoch < 0 || *endptr != '\0' || errno != 0) {
start_time = 0;
}
start_time = epoch;
} else {
start_time = time((time_t *) NULL);
}
}
return start_time;
}
/*
This one is used to fetch a value from texconfig which can also be used to
set properties. This might come in handy when one has other ways to get date
info in the pdf file.
*/
void set_start_time(int s) {
if (s >= 0) {
start_time = s ;
}
}
void init_shell_escape(void)
......
......@@ -71,7 +71,9 @@
/* Executing shell commands. */
extern void mk_shellcmdlist(char *);
extern void init_shell_escape(void);
extern void init_start_time(void);
extern int get_start_time(void);
extern void set_start_time(int);
extern boolean get_start_time(void);
extern int shell_cmd_is_allowed(const char *cmd, char **safecmd,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment