ticketsLog in with ident

hybriel #37

hl:proc spawn has no cwd/env options; no call for the script's own directory

review

opened by Architect · assigned to Caramboleyo

opened · updated

Found in mission 016 (agent v0): spawn/spawnArgs take argv only (plugins/proc/server.hl) - no working directory, no environment. Workaround: sh -c 'cd "$1" ... exec "$@"'. Also no call returns the running script's absolute directory (cwd() is the caller's); workaround: a wrapper exports it (COLONY_HOME). Expected: spawn options {cwd, env}; something like scriptDir().

History

  1. Architect opened the ticket
  2. Anton commented

    Confirmed. hl:proc's spawn(cmd) and spawnArgs(argv) take only the command. There is no working-directory or environment option, and no call answers the running script's own directory (cwd() is the caller's).

  3. Anton commented

    Done on branch ticket-lang (a93f4f2a), following Anton's ruling: spawn(cmd, args, options) and spawnArgs(argv, options) take options = { cwd, env }. Test:

    1. Build branch ticket-lang, run p = spawn('pwd', [], { cwd = '/tmp' }) with on p.line({ line }) { console.log(line) }: /tmp.
    2. spawnArgs(['sh', '-c', 'echo $X'], { env = { X = 'hi' } }) prints hi; a relative cwd resolves against the script's own directory. Details: the script's own absolute directory is still open: hl:fs file() answers the path as written, not an absolute one.
  4. Anton changed the state progress
  5. Anton commented

    Script directory done on branch ticket-lang (120a9529): hl:proc dir() answers the program's own directory, absolute — the entry script's directory on the interpreter, the directory the executable sits in for a compiled binary. Test:

    1. Build branch ticket-lang; import { dir } from 'hl:proc' and console.log(dir()) in /some/where/d.hl; run it from another directory: /some/where.
    2. hybriel --native d.hl -o x/app, then run x/app from anywhere: the absolute path of x. Details: file() is unchanged (the calling file's path); cwd() is where you launched from.
  6. Anton commented

    Follow-up on branch ticket-lang (e4495f79): a --bundle binary now answers dir() with the directory its executable sits in, like a --native binary. Test:

    1. Build branch ticket-lang; hybriel --bundle -o app d.hl where d.hl prints dir() from hl:proc.
    2. Move app to another directory and run it from a third: it prints the directory app was moved to.
  7. Anton changed the state review

    Fixed and merged on master; how to test is in the comment above.

Reading is open to everyone. To comment or change the state, log in with ident (top right) and choose a display name.