henesy / mk

make remade
Other
4 stars 0 forks source link

Can't parse \ and \n separated lists for variable values #1

Open henesy opened 4 years ago

henesy commented 4 years ago

Using https://github.com/henesy/kfs as a test:

; mk
all-kfs: cd kfs
          mk $MKFLAGS all
don't know how to make 9p1.$O9p1lib.o\
    9p2.o\
    9p12.o\
    auth.o\
    chk.o\
    con.o\
    console.o\
    dat.o\
    dentry.o\
    ialloc.o\
    iobuf.o\
    main.o\
    misc.o\
    porttime.o\
    sub.o\
    uid.o\
    ofcallfmt.o\
    devwren.o\
 in /home/seh/repos/kfs/kfs

; 
henesy commented 4 years ago

The mkfile triggering this looks:

<$PLAN9/src/mkhdr

CFLAGS = -fplan9-extensions

TARG=kfs

OFILES=\
    9p1.$O\
    9p1lib.$O\
    9p2.$O\
    9p12.$O\
    auth.$O\
    chk.$O\
    con.$O\
    console.$O\
    dat.$O\
    dentry.$O\
    ialloc.$O\
    iobuf.$O\
    main.$O\
    misc.$O\
    porttime.$O\
    sub.$O\
    uid.$O\
    ofcallfmt.$O\
    devwren.$O\
#   devmulti.$O\

HFILES=\
    all.h\
    dat.h\
    errno.h\
    fns.h\
    portfns.h\
    portdat.h\

BIN = $PLAN9/bin/disk

UPDATE=mkfile\
    $HFILES\
    ${OFILES:%.$O=%.c}\

MAN = $PLAN9/man/man4/kfs.4

<$PLAN9/src/mkone

#$O.out:    devwren.$O

#$O.gfs:    $OFILES devmulti.$O
#   $LD $LDFLAGS -o $target $prereq

test:VQ:
    echo rm -fr /srv/il!$sysname!11111
    echo 'kill $O.out|rc'
    echo rm /srv/il!$sysname!11111
    echo $O.out -Crf /tmp/disk
    echo disk/kfscmd ''''listen il!*!11111''''
    echo srv il!$sysname!11111
    echo mount /srv/il!$sysname!11111 /n/emelie
henesy commented 4 years ago

OFILES=\ is not the issue, as

OFILES=9p1.$O\
    9p1lib.$O\

produces an identical error

henesy commented 4 years ago

With some debug output, we can see how the tokens are being read and see the mistaken(?) assignment to a word with a recipe following(?):

 46 0}
>>> DEBUG emit -  [Word] {2 CFLAGS 3 0}
>>> DEBUG emit -  [Assign] {6 = 3 7}
>>> DEBUG emit -  [Word] {2 -fplan9-extensions 3 9}
>>> DEBUG emit -  [Newline] {1 
 4 0}
>>> DEBUG emit -  [Word] {2 TARG 5 0}
>>> DEBUG emit -  [Assign] {6 = 5 0}
>>> DEBUG emit -  [Word] {2 kfs 5 0}
>>> DEBUG emit -  [Newline] {1 
 6 0}
>>> DEBUG emit -  [Word] {2 OFILES 7 0}
>>> DEBUG emit -  [Assign] {6 = 7 0}
>>> DEBUG emit -  [Word] {2 9p1.$O 8 1}
>>> DEBUG emit -  [Recipe] {7 9p1lib.$O\
    9p2.$O\
    9p12.$O\
    auth.$O\
    chk.$O\
    con.$O\
    console.$O\
    dat.$O\
    dentry.$O\
    ialloc.$O\
    iobuf.$O\
    main.$O\
    misc.$O\
    porttime.$O\
    sub.$O\
    uid.$O\
    ofcallfmt.$O\
    devwren.$O\
 27 1}
>>> DEBUG emit -  [Newline] {1 
 28 14}
>>> DEBUG emit -  [Word] {2 HFILES 29 0}
>>> DEBUG emit -  [Assign] {6 = 29 0}
>>> DEBUG emit -  [Word] {2 all.h 30 1}
>>> DEBUG emit -  [Recipe] {7 dat.h\
    errno.h\
    fns.h\
    portfns.h\
    portdat.h\

 37 1}
>>> DEBUG emit -  [Word] {2 BIN 37 0}
henesy commented 4 years ago

This bug seems to be bypassed by doing

s/\\/ \\/g

on $OFILES.

Instead, mk hangs in the middle of parsing (it seems) and crashes.

In this case, mk clean works, though.

henesy commented 4 years ago

Closer observation shows this as a memory leak leading to exhaustion