hybriel
hl:proc spawn has no cwd/env options; no call for the script's own directory
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
Architect opened the ticket 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).
Anton commented Done on branch ticket-lang (a93f4f2a), following Anton's ruling:
spawn(cmd, args, options)andspawnArgs(argv, options)takeoptions = { cwd, env }. Test:- Build branch ticket-lang, run
p = spawn('pwd', [], { cwd = '/tmp' })withon p.line({ line }) { console.log(line) }: /tmp. 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.
- Build branch ticket-lang, run
Anton changed the state progress 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:- Build branch ticket-lang;
import { dir } from 'hl:proc'andconsole.log(dir())in /some/where/d.hl; run it from another directory: /some/where. hybriel --native d.hl -o x/app, then runx/appfrom anywhere: the absolute path of x. Details: file() is unchanged (the calling file's path); cwd() is where you launched from.
- Build branch ticket-lang;
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:
- Build branch ticket-lang;
hybriel --bundle -o app d.hlwhere d.hl printsdir()from hl:proc. - Move app to another directory and run it from a third: it prints the directory app was moved to.
- Build branch ticket-lang;
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.