Potentially nasty interaction between init.pl and build system (build maybe needs `-f none`)

Short version: When Cmake invokes swipl, it maybe should do so with -f none?

Long version:

Inspired by some recent posting or other, I decided this morning to clone the git repository for SWI Prolog, thinking it might be useful to be able to propose changes for this or that modest improvement in the reference manual.

I eventually got homebrew to install all the pre-requisites listed at https://eu.swi-prolog.org/build/macos.html and proceeded to the steps listed at https://github.com/SWI-Prolog/swipl-devel/blob/166a6ac48bd45f5957ed12e089602708df9bf780/CMAKE.md

cd swipl-devel
mkdir build
cd build
cmake -G Ninja ..

This is where I eventually noticed that my initial brew install ... command had only succeeded for maybe half the packages.

ninja

Here is where I stalled for an hour or so. When, after a couple of false starts, I ran ninja clean to start afresh, and then ninja, the build process trundled along quite nicely for a while and then stopped with the message

[2132/2353] Generating odbc.html
No bibliography file
No bibliography entry for "miller1990"
[2173/2353] Generating protobufs.html
FAILED: packages/protobufs/protobufs.html 
cd /home2/dev/swipl/swipl-devel/build/packages/protobufs && /home2/dev/swipl/swipl-devel/build/src/swipl /home2/dev/swipl/swipl-devel/build/home/library/latex2html/latex2html.pl -- --quiet protobufs && /usr/local/Cellar/cmake/3.16.1/bin/cmake -E remove /home2/dev/swipl/swipl-devel/build/home/doc/manindex.db
ERROR: /home2/dev/swipl/swipl-devel/build/home/library/latex2html/latex2html.pl:3142: tex:main source_sink `tex('protobufsoverview.tex')' does not exist
[2182/2353] Generating tests/test_certs/generated
ninja: build stopped: subcommand failed.

I saw that something had gone wrong when trying to make protobufs.html.

Trying to look at the Cmake files, the way I would look at a make file, was not a success; if learning to understand cmake is a prerequisite to offering copy edits to the reference manual, then this could take longer than I had hoped (though I’m sure I’ll be better for the experience).

When I look more closely, I saw that the error message

source_sink `tex('protobufsoverview.tex')' does not exist

was issued by latex2html.pl. There is a file of that name, according to find:

$ find . -name "protobuf*"
./home/library/protobufs.pl
./home/doc/packages/examples/protobufs
./packages/protobufs
./packages/protobufs/protobufspl.tex
./packages/protobufs/CMakeFiles/plugin_protobufs.dir/protobufs.c.o
./packages/protobufs/protobufsoverview.tex
./packages/protobufs/protobufs.so

The error message tells me that html2latex.pl is looking for the file in the directory with the alias tex. The source code tells me that tex is an alias of the current directory; at least, that’s what I think is meant by:

user:file_search_path(tex, '.').

The program latex2html.pl is invoked from directory packages/protobufs, which means that it ought to be finding the file.

It was only as I typed the words “is invoked from” in the preceding paragraph, in what was then not a report of a slight problem in the build system but a plea for help understanding what was going wrong, that I realized that I had done this to myself. I spent most of yesterday evening figuring out where the user initialization file is located and how to use it to make swipl cd to my home directory (the way it did at some point) instead of running with / as the current working directory. So my init.pl program contained the line

:- getenv('HOME',Home_directory), working_directory(_,Home_directory).

The problem went away when I corrected the init.pl to read

:- (working_directory(CWD, CWD),
    CWD = '//'
   -> 
    getenv('HOME',Home_directory), 
    working_directory(_,Home_directory)
   ; 
    true
   ).

Since the build system has to work in environments where swipl has not yet been installed or there is no personal initialization file, it presumably cannot hurt for Cmake to invoke swipl with -f none, to prevent interactions like the one I just experienced.

Looking at this again today with a fresh head (or at least a different one), I see that man/CMakeLists.txt already specifies -f none every time it invokes Prolog to run a program. As far as I can tell, the problem I stumbled into yesterday is caused by the fact that -f none is not specified by the invocations in packages/cmake/PackageDoc.cmake.

I will use that as a way to see whether I can follow the instructions for making a fix and submitting a pull request.

1 Like