Skip to content

Commit

Permalink
build: don't fail build if pathname has space
Browse files Browse the repository at this point in the history
Ideally, the build shouldn't care what is the pathname of the build
directory. But some parts of the build process use, for historical
reasons and for convenience, full pathnames, and some of that code did
not correctly handle the case where the pathname might contain spaces,
and the build fails.

The fix is to use relative pathnames where it's easy, but where it's not,
be more careful to quote the filename or avoid using the shell's argument
splitting in Python code.

Fixes #1034 for basic "make" and "scripts/build image=rogue", but some
modules (e.g., Java) still don't build properly in this case and should
be fixed separately.

Signed-off-by: Nadav Har'El <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
nyh committed Mar 17, 2019
1 parent 3f7ce19 commit 15c8ff7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ local-includes =
INCLUDES = $(local-includes) -Iarch/$(arch) -I. -Iinclude -Iarch/common
INCLUDES += -isystem include/glibc-compat

glibcbase = $(CURDIR)/external/$(arch)/glibc.bin
gccbase = $(CURDIR)/external/$(arch)/gcc.bin
miscbase = $(CURDIR)/external/$(arch)/misc.bin
jdkbase := $(shell find $(CURDIR)/external/$(arch)/openjdk.bin/usr/lib/jvm \
glibcbase = external/$(arch)/glibc.bin
gccbase = external/$(arch)/gcc.bin
miscbase = external/$(arch)/misc.bin
jdkbase := $(shell find external/$(arch)/openjdk.bin/usr/lib/jvm \
-maxdepth 1 -type d -name 'java*')


Expand Down Expand Up @@ -1911,7 +1911,7 @@ $(bootfs_manifest_dep): phony

$(out)/bootfs.bin: scripts/mkbootfs.py $(bootfs_manifest) $(bootfs_manifest_dep) $(tools:%=$(out)/%) \
$(out)/zpool.so $(out)/zfs.so $(out)/libenviron.so $(out)/libvdso.so
$(call quiet, olddir=`pwd`; cd $(out); $$olddir/scripts/mkbootfs.py -o bootfs.bin -d bootfs.bin.d -m $$olddir/$(bootfs_manifest) \
$(call quiet, olddir=`pwd`; cd $(out); "$$olddir"/scripts/mkbootfs.py -o bootfs.bin -d bootfs.bin.d -m "$$olddir"/$(bootfs_manifest) \
-D jdkbase=$(jdkbase) -D gccbase=$(gccbase) -D \
glibcbase=$(glibcbase) -D miscbase=$(miscbase), MKBOOTFS $@)

Expand Down
22 changes: 11 additions & 11 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ esac
modules=${vars[modules]-!$image}

# TODO: some modules need these... Would be better if they wouldn't...
jdkbase=${vars[jdkbase]-`find $SRC/external/$arch/openjdk.bin/usr/lib/jvm -maxdepth 1 -type d -name 'java*'`}
gccbase=${vars[gccbase]-$SRC/external/$arch/gcc.bin}
glibcbase=${vars[glibcbase]-$SRC/external/$arch/glibc.bin}
miscbase=${vars[miscbase]-$SRC/external/$arch/misc.bin}
jdkbase=${vars[jdkbase]-`find "$SRC"/external/$arch/openjdk.bin/usr/lib/jvm -maxdepth 1 -type d -name 'java*'`}
gccbase=${vars[gccbase]-"$SRC"/external/$arch/gcc.bin}
glibcbase=${vars[glibcbase]-"$SRC"/external/$arch/glibc.bin}
miscbase=${vars[miscbase]-"$SRC"/external/$arch/misc.bin}

case $OUT in
/*) OSV_BUILD_PATH=$OUT;;
Expand Down Expand Up @@ -182,26 +182,26 @@ case $fs_type in
zfs)
cp loader.img bare.raw
zfs_size=$(($fs_size - $kernel_end))
$SRC/scripts/imgedit.py setpartition "-f raw bare.raw" 2 $kernel_end $zfs_size
"$SRC"/scripts/imgedit.py setpartition "-f raw bare.raw" 2 $kernel_end $zfs_size

qemu-img convert -f raw -O qcow2 bare.raw usr.img
qemu-img resize usr.img ${fs_size}b >/dev/null 2>&1

if [ "$export" == "none" ]
then
$SRC/scripts/upload_manifest.py -o usr.img -m usr.manifest -D jdkbase=$jdkbase -D gccbase=$gccbase -D glibcbase=$glibcbase -D miscbase=$miscbase
"$SRC"/scripts/upload_manifest.py -o usr.img -m usr.manifest -D jdkbase="$jdkbase" -D gccbase="$gccbase" -D glibcbase="$glibcbase" -D miscbase="$miscbase"
else
export_dir=${vars[export_dir]-$SRC/build/export}
$SRC/scripts/export_manifest.py -e "$export_dir" -m usr.manifest -D jdkbase=$jdkbase -D gccbase=$gccbase -D glibcbase=$glibcbase -D miscbase=$miscbase
"$SRC"/scripts/export_manifest.py -e "$export_dir" -m usr.manifest -D jdkbase="$jdkbase" -D gccbase="$gccbase" -D glibcbase="$glibcbase" -D miscbase="$miscbase"
fi
;;
rofs)
rm -rf rofs.img
$SRC/scripts/gen-${fs_type}-img.py -o rofs.img -m usr.manifest -D jdkbase=$jdkbase -D gccbase=$gccbase -D glibcbase=$glibcbase -D miscbase=$miscbase
"$SRC"/scripts/gen-${fs_type}-img.py -o rofs.img -m usr.manifest -D jdkbase="$jdkbase" -D gccbase="$gccbase" -D glibcbase="$glibcbase" -D miscbase="$miscbase"
rofs_size=`stat --printf %s rofs.img`
img_size=$((kernel_end + rofs_size))
cp loader.img bare.raw
$SRC/scripts/imgedit.py setpartition "-f raw bare.raw" 2 $kernel_end $rofs_size
"$SRC"/scripts/imgedit.py setpartition "-f raw bare.raw" 2 $kernel_end $rofs_size
qemu-img resize bare.raw ${img_size}b >/dev/null 2>&1
dd if=rofs.img of=bare.raw obs=${kernel_end} seek=1 >/dev/null 2>&1
qemu-img convert -f raw -O qcow2 bare.raw usr.img
Expand All @@ -211,14 +211,14 @@ ramfs)
;;
esac

$SRC/scripts/imgedit.py setargs usr.img `cat cmdline`
"$SRC"/scripts/imgedit.py setargs usr.img `cat cmdline`

# Support "build check"
for i
do
case $i in
check) set -x
cd $SRC
cd "$SRC"
exec ./scripts/test.py
esac
done
7 changes: 5 additions & 2 deletions scripts/imgedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ def write_cstr(file, str):
class nbd_file(object):

def __init__(self, filename):
fileformat = []
if filename.startswith("-f raw "):
filename = filename[7:]
fileformat = ['-f', 'raw']
self._filename = filename
self._offset = 0
self._buf = None
self._closed = True
nbd_port = randint(10809, 20809)
self._process = subprocess.Popen("qemu-nbd -p %d %s" % (nbd_port, filename),
shell=True, stdout=_devnull)
self._process = subprocess.Popen(["qemu-nbd", "-p", str(nbd_port)] + fileformat + [filename], shell=False, stdout=_devnull)
# wait for qemu-nbd to start: this thing doesn't tell anything on stdout
while True:
try:
Expand Down
2 changes: 1 addition & 1 deletion scripts/upload_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def main():

image_path = os.path.abspath(options.output)
upload_port = find_free_port()
osv = subprocess.Popen('cd ../..; scripts/run.py --vnc none -m 512 -c1 -i %s -u -s -e "--norandom --nomount --noinit /tools/mkfs.so; /tools/cpiod.so --prefix /zfs/zfs/; /zfs.so set compression=off osv" --forward tcp:127.0.0.1:%s-:10000' % (image_path,upload_port), shell=True, stdout=subprocess.PIPE)
osv = subprocess.Popen('cd ../..; scripts/run.py --vnc none -m 512 -c1 -i "%s" -u -s -e "--norandom --nomount --noinit /tools/mkfs.so; /tools/cpiod.so --prefix /zfs/zfs/; /zfs.so set compression=off osv" --forward tcp:127.0.0.1:%s-:10000' % (image_path,upload_port), shell=True, stdout=subprocess.PIPE)

upload(osv, manifest, depends, upload_port)

Expand Down

0 comments on commit 15c8ff7

Please sign in to comment.