oasislinux / oasis

a small statically-linked linux system
Other
2.79k stars 85 forks source link

Error during build of `file` package #24

Closed faithanalog closed 3 years ago

faithanalog commented 3 years ago

Meant to report this last night but was tired

During build, using ubuntu 20.04 and debian buster, I got the following error with the file package: file: could not find any valid magic files!'. This happens while running file -C -m magic, after a bunch of warnings. Full log of warnings attached but it's not too relevant.

Anyway, the problem seems to be that it's using the host system's file, not the file it just built, and I guess there's some incompatibilities from the versions shipped by debian and ubuntu. This patch fixes it by using the file it just built to generate the magic:

diff --git a/pkg/file/gen.lua b/pkg/file/gen.lua
index 626b044d..f4399a50 100644
--- a/pkg/file/gen.lua
+++ b/pkg/file/gen.lua
@@ -38,7 +38,7 @@ exe('file', {'src/file.c', 'src/seccomp.c', 'libmagic.a', '$builddir/pkg/zlib/li
 file('bin/file', '755', '$outdir/file')
 man{'$outdir/file.1'}

-rule('magic', 'cd $outdir && file -C -m magic')
+rule('magic', 'cd $outdir && ./file -C -m magic')
 build('magic', '$outdir/magic.mgc', {'|',
        copy('$outdir/magic', '$srcdir/magic/Magdir', lines('magic.txt')),
        copy('$outdir/magic', '$srcdir/magic', {'Header', 'Localstuff'}),

There is a catch. If you want to be able to cross-compile oasis, this won't work, unless you have qemu-user and corresponding binfmt on the host system to emulate the built file binary. I don't know if cross compiling is even a goal of oasis or not; If that's not a problem, this should work.

michaelforney commented 3 years ago

This has been an annoyance for quite a while, and I usually worked around it with samu out/pkg/file/file && PATH=$PWD/out/pkg/file:$PATH samu. I did some investigation and it turns out file has a bunch of ifdefs for COMPILE_ONLY which allow you to build a minimal tool just to generate the magic database.

It appears to generate the exact same magic.mgc as the real file, so I pushed a commit to use that instead. This should work even when cross-compiling.

Thanks for reporting the issue!