From 23783ae38b3ae9ed768d3383eb2d56cc31ea8b20 Mon Sep 17 00:00:00 2001 From: Raul Infante-Sainz Date: Sat, 11 Jun 2022 11:00:10 +0200 Subject: Configuration: replacing hard coded PATH in SCons Until now, SCons (a high-level Python package builder) was using the OS PATH when building packages (like Imfit that use SCons), not Maneage's PATH. This happened even though 'reproduce/software/make/high-level.mk' completely removes the host's PATH to avoid any host OS dependency. After some investigation, we recognized that SCons hard-codes operating system directories into its source! This doesn't let the user (Maneage in this case; that builds packages that use SCons) customize the search directories. As a result, even though we have our own linker and compiler in Maneage, SCons would go and use the operating system's linker and compiler, causing a leak in the controlled environment we plan to achieve in Maneage. Not letting users customize such critical components of a software and hard-coding parameters is bad program design! This wasn't noticed until now because most operating systems we tested on were relatively recent and the versions of Maneage's linker and the OS linker weren't too different! However, after testing on a much older operating system (GNU/Linux 4.4.0-143-generic X86_64), the operating system's linker couldn't build Imfit (that uses SCons) and would crash. With this commit, after unpacking SCons's source (but before building or installing it), we have added a step to modify SCons's source and replace the hard-coded PATH directories with Maneage's PATH. This fixed the problem. This bug has been fixed with the help of Mohammad Akhlaghi. --- reproduce/software/make/high-level.mk | 37 +++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/reproduce/software/make/high-level.mk b/reproduce/software/make/high-level.mk index 9c5cd31..966ea9b 100644 --- a/reproduce/software/make/high-level.mk +++ b/reproduce/software/make/high-level.mk @@ -1380,16 +1380,49 @@ $(ibidir)/scamp-$(scamp-version): \ cp $(dtexdir)/scamp.tex $(ictdir)/ echo "SCAMP $(scamp-version) \citep{scamp}" > $@ -# Since 'scons' doesn't use the traditional GNU installation with -# 'configure' and 'make' it is installed manually using 'python'. +# Since 'scons' doesn't use the traditional GNU installation with 'configure' +# and 'make' it is installed manually using 'python'. After 'scons' is +# installed, there is a file, '$(ildir)/scons/SCons/Platform/posix.py', that +# contains several hard coded paths like '/usr/local'. This is bad because it +# causes later problems in the installation of other programs (e.g., 'imfit'). +# As a consequence, at the end of the installation we replace the +# '/usr/local' by the one Maneage uses: '$(idir)'. Only one of these paths +# is replaced, the first one: '/usr/local'. $(ibidir)/scons-$(scons-version): $(ibidir)/python-$(python-version) + +# Prepare the tarball tarball=scons-$(scons-version).tar.gz $(call import-source, $(scons-url), $(scons-checksum)) + +# Unpack and enter the source directory cd $(ddir) unpackdir=scons-$(scons-version) rm -rf $$unpackdir tar -xf $(tdir)/$$tarball cd $$unpackdir + +# Unfortuantely SCons hard-codes its search PATH in its source (to +# use POSIX operating system defaults)! So the only way to modify it +# is to edit the source manually! Instead of using SED to replace a +# fixed string, we are using AWK to replace the value. This is done +# because in future versions, they may suddenly change the order, and +# the fixed string won't match with SED. But with AWK, we can be +# fully ignorant to their default value, and just change the value of +# the known variable. Some technical notes: +# - In the shell, the single quote is used to separate AWK's +# environment from the shell, we are using '\47' instead of the +# single quote. +# - In Python (the source we are editing) indentation is +# meaningful, but SPACE is a delimiter in AWK and AWK will +# remove leading/trailing SPACE from its values. So we'll +# manually inseart the necessary number of spaces before the +# modified line. + awk '{ if($$1=="env[\47ENV\47][\47PATH\47]") \ + {$$3="\47'$(ibdir)'\47"; print " "$$0} \ + else print}' engine/SCons/Platform/posix.py > posix-edited.py + mv posix-edited.py engine/SCons/Platform/posix.py + +# Install SCons python setup.py install cd .. rm -rf $$unpackdir -- cgit v1.2.1