General TC > Programming & Scripting - Unofficial

when building extension, workaround for when DESTDIR fails

(1/2) > >>

GNUser:
When building extensions, a very handy trick the DESTDIR=/tmp/dest argument to make install (where /tmp/dest is simply an empty directory).

Rarely, DESTDIR doesn't work, which can make it difficult to build an extension.

The wiki gives a workaround for when DESTDIR fails here, but the workaround has a caveat (see the "Be careful..." part), which requires its own workaround.

I recently discovered a little utility called inotifywait (part of the inotify-tools.tcz extension) which provides a much cleaner workaround for when DESTDIR fails:


--- Code: ---$ inotifywait --quiet --monitor --recursive -e create --format '%w%f' /usr/local >new.txt &
-> install the package (e.g., sudo make install, sudo cmake --install build, etc.)
$ pkill inotifywait
$ cat new.txt | sort | uniq >list.txt
$ tar -cvf dest.tar -T list.txt
$ mkdir /tmp/dest
$ tar -xvf dest.tar -C /tmp/dest

--- End code ---

After the above, /tmp/dest will contain exactly what you would expect :)

P.S. Regarding some of the options to inotifywait: The tool is quite chatty by default. The --quiet flag tells it not to introduce itself when it starts running. The -e create option quiets it down further by telling it that we are only interested in new directories and files, nothing else. The --format '%w%f' option quiets it down more by saying that we want it to merely output the path of new directories and files, without any commentary. Even after all this there are still some duplicate lines in the output, which is why the sort | uniq step is needed later on.

P.P.S. I would add this tip the appropriate place in the wiki, but the wiki will not allow me to log in no matter what I do.

Rich:
Hi GNUser

--- Quote from: GNUser on March 15, 2023, 07:05:38 AM --- ... Rarely, DESTDIR doesn't work, which can make it difficult to build an extension. ...
--- End quote ---
When building an extension I really prefer the build system not install files in the system
directories, but this looked like a good technique so I decided to adapt it and skip DESTDIR.

This is what I did:

--- Code: ---PROGRAMPACKAGE="/home/$USER/pkg/"

# This creates a list of files added to /usr/local by sudo make install.
inotifywait --quiet --monitor --recursive -e create --format '%w%f' /usr/local > list.txt &

# Install program to /usr/local.
sudo make install

pkill inotifywait

# This sorts the file in place while removing duplicate entries.
echo "$(sort -u list.txt)" > list.txt

while read -r ENTRY
do
# Keep file entries, skip entries that are only paths.
if [ -f "$ENTRY" ]
then
echo "$ENTRY" >> files.txt
# since we found a file, we want its path.
echo "${ENTRY%/*}" >> paths.txt
fi
done < list.txt

# This sorts the file in place while removing duplicate entries.
echo "$(sort -u paths.txt)" > paths.txt

# Create the directory tree to move the installed files to.
while read -r ENTRY
do
mkdir -p "$PROGRAMPACKAGE$ENTRY"
done < paths.txt

# Move the files from my system to the package directories where they belong.
while read -r ENTRY
do
sudo mv "$ENTRY" "$PROGRAMPACKAGE$ENTRY"
done < files.txt

# Change ownership so I don't need sudo for any further changes.
sudo chown -R tc:staff "$PROGRAMPACKAGE"
--- End code ---

I parse the list inotifywait creates and keep the entries that point to files.
For every entry that points to a file, I strip the file name and save the path.
I use the saved paths to create a directory tree in my package directory.
Then I move the files to my package directory.

Paul_123:
That's a neat option Rich.  The alternative way of just setting a timestamp mark   (touch /tmp/mark) fails quite often, as some installers keep the original modification dates that are in the source package.

GNUser:
Interesting. So you are manually creating the package subdirectories rather than letting  tar  handle it for you. Then moving the files from system directory to the package directory.

The approach in my original post (installing files to the system then using tar to collect inotifywait's log) requires a reboot to clean up the system directories. Your idea of moving the files to the package directory is nice, as it obviates the need for a reboot to clean up the system directories.

Rich:
Hi Paul_123

--- Quote from: Paul_123 on March 27, 2023, 06:57:29 AM ---That's a neat option Rich. ...
--- End quote ---
Thanks, "neat" is what I was shooting for.  ;D

Navigation

[0] Message Index

[#] Next page

Go to full version