Closed lhstrh closed 10 months ago
I am not sure what the bug is but I pulled today's nightly build and run
../target/debug/lingo build --lfc /home/revol-xut/Downloads/lf-cli-0.4.1-SNAPSHOT-nightly-20230725050236-Linux-x86_64/bin/lfc
And this worked just fine
The bug is probably only when you don't use a prebuilt version of lfc, because then it goes through gradle (lf-lang/lingua-franca#1909). When I had this bug in development I found that it was possible to add single quotes around the json arg here: https://github.com/lf-lang/lingo/blob/bbb0b6fcf214b226b0705f06159050582d248c93/src/backends/lfc.rs#L35
(effectively using "--json='{}'"
as the format string) and that would fix the issue. I reverted that for trivial reasons so we could add it back.
@oowekyala So lfc release builds can handle --json, but the debug build cannot ? - this sounds silly
Can the release build handle wrapping the argument into quotes "--json={}"
?
The issue is with gradle and the release builds do not ship with gradle. That's why there could be a diff between release and dev builds afaiu. I don't know if both builds support the quoting though.
The problem is that the quotes that surround the JSON string disappear. In the lfc
script, invoking the following works:
"${gradlew}" -p "${base}" "cli:${tool}:run" --args="--json='{\"src\":\"foo.lf\"}'"
But, of course, we're not hard-coding the parameters but getting them from the command line, like so:
"${gradlew}" -p "${base}" "cli:${tool}:run" --args="$*"
At first, I thought this was just a problem with the string not being escaped properly, so I tried this:
args="$(printf "%q" "$@")"
"${gradlew}" -p "${base}" "cli:${tool}:run" --args="$args"
but the result of that is not what we want. I.e., given the input --json='{"src":"foo.lf"}'
, the escaped string is \{\src\:\foo\\}
, and lfc
reports an Invalid JSON string
. On the other hand, ./build/install/lf-cli/bin/lfc --json='{"src":"foo"}'
works fine in the sense that the JSON is parsed and lfc
complains that it cannot find foo.lf
.
I don't know if both builds support the quoting though.
They both do, but in different ways; the difference is, imo, whether an extra layer of quoting is necessary depending whether it will be parsed by gradle/gradlew.
(With gradlew
I need ./bin/lfc --json="'{\"src\": \"test/C/src/Hello.lf\"}'"
, where the single quoting is to prevent gradle from parsing the double quote; with release I only need lfc --json='{"src": "examples/C/src/Smokers.lf"}')
My point, which I believe is also the consensus which you have reached, is that we should just do https://github.com/lf-lang/lingo/issues/31 and stop adapting to gradle wrapper's behaviour, which, according to their GH issues, changes as the version updates 🤡
Using gradlew causes lots of troubles, even for reading from file/stdin.
Suppose somebody wants to do this (which people should be able to!)
lfc --json-file=<(echo "{\"src\": \"test/C/src/Hello.lf\"}")
This is okay with the release version of lfc
, but not with gradlew
.
This is issue is not relevant anymore because we agreed that lingo will not work with the gradle lfc
I'm using the latest
lfc
frommaster
.Output:
Also observed by @gundralaa who is blocked by this issue.
Running
lfc --json={"out":"/home/marten/lf-lang/lingo/sandbox/target","properties":{"logging":"info","no-compile":true},"src":"/home/marten/lf-lang/lingo/sandbox/src/Main.lf"}
results in:There seem to be two problems that need to be fixed:
lingo
so that it is clear what went wronglfc
so that it can actually handle the--json
argument (https://github.com/lf-lang/lingua-franca/issues/1909)