rescript-compiler
rescript-compiler copied to clipboard
Generator command is not ran from the same dir as bsconfig
I ran into weird bugs where I essentially did:
"generators": [
{
"name": "atd_t",
"command": "esy @.. atdgen -t $in"
},
{
"name": "atd_bs",
"command": "esy @.. atdgen -bs $in"
}
]
and I got some really weird errors:
FAILED: ../../src/serializers_bs.ml
error: no manifests found at /Users/wczekalski/Documents/Work/Projects.nosync/dialo/shared/lib/
just to notice that the command is ran from somewhere else (I think ./lib/bs
).
I would expect it to be ran from the same place as bsconfig. Maybe in this example it's not obvious but let's imagine that I use -o
like so:
"generators": [
{
"name": "atd_bs",
"command": "esy atdgen -bs $in -o ./src"
}
]
I would expect the output to be inside src.
Workaround
- For
esy
you can use `esy @../.. - For anything else just remember that you are two directories up.
The current behavior is that the command is running in lib/bs
, since ninja is running there.
If you use $in
, $out
, it will be translated properly. Can you give $out
variable a try.
Below is a small example:
"sources": [
{
"dir": "src",
"generators": [
{
"name": "sed",
"edge": [
"test.ml", ":", "test.cpp.ml"
]
}
]
}
],
"generators": [
{
"name" : "sed",
"command": "sed 's/OCAML/3/' $in > $out"
}
],
Note the generated lib/bs/build.ninja is readable, for troubleshooting, it may be worth having a look.
I know. I could've used it indeed. It was just a bit confusing because I wanted to generate the files to a different directory than the one where my source file is located.
If there's multiple input files. The guessed work dir is wrong.
This is my workaround:
{
"name": "noodlescript",
"version": "0.0.1",
"sources": [
{
"dir": "src",
"subdirs": false
},
{
"dir": "src/syntax",
"generators": [
{
"name": "lexer",
"edge": ["Lexer.ml", ":", "Lexer.mll"]
},
{
"name": "tokens",
"edge": ["Tokens.ml", "Tokens.mli", ":", "Tokens.mly"]
},
{
"name": "parser",
"edge": ["Parser.ml", ":", "Parser.mly", "Tokens.mly"]
}
]
}
],
"generators": [
{
"name": "lexer",
"command": "ocamllex $in -o $out"
},
{
"name": "tokens",
"command": "menhir $in --only-tokens"
},
{
"name": "parser",
"command": "menhir $in --external-tokens Tokens --base ../../src/syntax/Parser"
}
],
"package-specs": {
"module": "commonjs",
"in-source": true
},
"suffix": ".bs.js",
"bs-dependencies": [],
"warnings": {
"error": "+101"
}
}
I just hit this because I'm using yarn
to run a generator installed via a NodeJS dependency. Setting the command to yarn <cmd> $in
doesn't work because yarn relocates the shell to the project root before running the command.
I had to use yarn <cmd> lib/bs/$in
which becomes yarn <cmd> lib/bs/../../<file>
and that works. Unfortunately it's brittle if rescript changes in the future.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.