lf-lang / lingo

Package manager and build tool for the Lingua Franca coordination language
BSD 2-Clause "Simplified" License
4 stars 1 forks source link

`lingo build` (in the sandbox) does not work #29

Closed lhstrh closed 10 months ago

lhstrh commented 1 year ago

I'm using the latest lfc from master.

Output:

- embedded: Error: Command exited with status exit status: 1: "/home/marten/lingua-franca-master/git/lingua-franca/bin/lfc" "--json={\"out\":\"/home/marten/lf-lang/lingo/sandbox/target\",\"properties\":{\"no-compile\":true},\"src\":\"/home/marten/lf-lang/lingo/sandbox/src/Main2.lf\"}"
- git-hook: Error: Command exited with status exit status: 1: "/home/marten/lingua-franca-master/git/lingua-franca/bin/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\"}"

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:

Usage: lfc [-cfhlnqV] [--print-statistics] [--build-type=<buildType>]
           [--external-runtime-path=<externalRuntimePath>]
           [--logging=<logging>] [-o=<outputPath>] [-r=<rti>]
           [--runtime-version=<runtimeVersion>] [-s=<scheduler>]
           [-t=<true/false>] [--target-compiler=<targetCompiler>]
           [-w=<workers>] (FILES... | --json=<jsonString> |
           --json-file=<jsonFile> | --stdin)
      FILES...              Paths to one or more Lingua Franca programs.
      --build-type=<buildType>
                            The build type to use.
  -c, --clean               Clean before building.
      --external-runtime-path=<externalRuntimePath>
                            Specify an external runtime library to be used by
                              the compiled binary.
  -f, --federated           Treat main reactor as federated.
  -h, --help                Show this help message and exit.
      --json=<jsonString>   JSON object containing CLI arguments.
      --json-file=<jsonFile>
                            JSON file containing CLI arguments.
  -l, --lint                Enable linting of generated code.
      --logging=<logging>   The logging level to use by the generated binary
  -n, --no-compile          Do not invoke target compiler.
  -o, --output-path=<outputPath>
                            Specify the root output directory.
      --print-statistics    Instruct the runtime to collect and print
                              statistics.
  -q, --quiet               Suppress output of the target compiler and other
                              commands
  -r, --rti=<rti>           Specify the location of the RTI.
      --runtime-version=<runtimeVersion>
                            Specify the version of the runtime library used for
                              compiling LF programs.
  -s, --scheduler=<scheduler>
                            Specify the runtime scheduler (if supported).
      --stdin               Read paths to Lingua Franca programs from stdin.
  -t, --threading=<true/false>
                            Specify whether the runtime should use
                              multi-threading (true/false).
      --target-compiler=<targetCompiler>
                            Target compiler to invoke.
  -V, --version             Print version information and exit.
  -w, --workers=<workers>   Specify the default number of worker threads.

There seem to be two problems that need to be fixed:

tanneberger commented 1 year 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

oowekyala commented 1 year ago

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.

tanneberger commented 1 year ago

@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={}" ?

oowekyala commented 1 year ago

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.

lhstrh commented 1 year ago

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.

axmmisaka commented 11 months ago

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.

tanneberger commented 10 months ago

This is issue is not relevant anymore because we agreed that lingo will not work with the gradle lfc