Repository navigation
fix(cli): scope the console to the module you are standing in - #421
AnshumanAI wants to merge 3 commits into
Conversation
The launcher walks up to the build root and selects the project whose directory contains you. A project flag names one when the directory does not. eezoDev stays a command. DevProcess keeps one application per project base. Fixes Eezo-framework#293
A project whose base is the build root matched every directory under it. Nested modules now win, and several projects at the root stay a refusal. The blog README names project blog then eezoDev.
|
@AnshumanAI, you left the PR as a draft? Are you still working on it? |
yeah sorry ,was looking for some things before I make it RFR. |
rcardin
left a comment
There was a problem hiding this comment.
Thank you for this work. The gate is green at 20e2eae and the module choice works for the examples build. The review found 11 points. Three are regressions against dev (the comments on lines 287, 371 and 500 of bin/eezo). Three are cases of issue 293 that stay open. The others are about tests and docs. Each comment gives one fix.
| # The older plugin's console is lines already, so `--no-tui` changes nothing here, and it has | ||
| # no event stream, so `--json` gets the lines too. | ||
| dev_legacy | ||
| dev_legacy "$scoped" |
There was a problem hiding this comment.
Regression: the flags reach the old alias.
dev() now sends the scoped string with its flags to dev_legacy. On a plugin older than 0.4.0, eezoDev is only the alias ~eezoRestart. Thus eezo dev --no-tui sends eezoDev --plain, eezo dev --json sends eezoDev --json, and sbt cannot parse them. On dev, this path always sent the bare eezoDev. This also breaks builds with one project.
The comment on line 498 and the sentence "as it did before" in docs/reference/cli.md are now false.
Fix: build the string without the flags on this path: dev_legacy "$(eezo_scoped_command dev "$EEZO_MODULE")". Add an assertion for that string to bin/eezo-module-test.
| # A project at file(".") has the build root as its base, so it matches every directory under | ||
| # the root. Nested modules win over that. The aggregate itself is not a module: several projects | ||
| # at the root stay a refusal, and a sibling directory is unmatched rather than root. | ||
| if [ -n "$best" ] && { [ "${#ids[@]}" -eq 1 ] || [ "$bestbase" != "$root" ]; }; then |
There was a problem hiding this comment.
Regression: an application at the build root with a library module is refused.
Take this build:
lazy val root = (project in file(".")).enablePlugins(EezoPlugin)
lazy val lib = project in file("lib")From the root, eezo routes and eezo dev now refuse, because a project at file(".") never wins when the build has more than one id. On dev, the launcher sent run routes and sbt ran it on the root application. From root/src the message says src is not inside a project, which is false, because the base of root contains it.
Fix: when no nested module contains the directory and the project at file(".") enables EezoPlugin in its declaration, select that project. Refuse only when the project at file(".") is a bare aggregate.
| chunk="$(sed -e 's|//.*||' "$f" | tr '\n' ' ')" | ||
| text="${text} ${chunk}" | ||
| done | ||
| if printf '%s' "$text" | grep -qE 'project[[:space:]]+in[[:space:]]+file|project[[:space:]]*\.[[:space:]]*in[[:space:]]*\([[:space:]]*file|[[:space:]]Project[[:space:]]*\('; then |
There was a problem hiding this comment.
Regression: a string literal can make the build unreadable.
This test reads the joined build text with its string literals. A build that declares no project, but has a string such as description := "The bookshelf Project (a demo)", gets exit code 2. The launcher then refuses each command, --project included. On dev, the launcher forwarded run routes for the same build. The case is rare, but it breaks the scaffold criterion.
Fix: anchor the pattern to a declaration, for example =[[:space:]]*\(?[[:space:]]*(project|Project), or remove the string literals from the text before this test. Add the case to bin/eezo-module-test.
| n=$((n + 1)) | ||
| done < <(printf '%s' "$text" | grep -oE "$pattern" || true) | ||
| } | ||
| eezo_emit_projects 'val[[:space:]]+[A-Za-z_][A-Za-z0-9_]*[[:space:]]*=[[:space:]]*\(?[[:space:]]*project[[:space:]]+in[[:space:]]+file[[:space:]]*\([[:space:]]*"[^"]+"' val |
There was a problem hiding this comment.
The launcher does not read lazy val hello = project.
This is the sbt form that takes the base from the id. The launcher reads only project in file(...), project.in(file(...)) and Project(...). For a build that uses the bare form, it finds no declaration and takes the build for one project. From the module hello it sends the unscoped run routes at the build root, which is the No main class detected failure of issue 293. Also, --project hello refuses with the false message unknown project 'hello'. The only project is <rootdir>.
Fix: read val <id> = project with no in file(...) and no .in(...) after it as a project with the base <root>/<id>.
| projects="$(eezo_projects_of "$root")" | ||
| code=$? | ||
| set -e | ||
| if [ "$code" -eq 2 ]; then |
There was a problem hiding this comment.
--project does not help on a build the launcher cannot read.
When eezo_projects_of returns 2, this branch refuses before it looks at the explicit id. The message says Pass --project <id>, but that gives the same refusal. A build that uses project in file(helloDir) or Seq("a").map(id => Project(id, file(s"m/$id"))) cannot reach its modules. The build of eezo itself uses the second form.
Fix: when the code is 2 and an explicit id is given, trust the id and print <root>\t<id>. sbt then reports an id it does not know. Refuse only when no id is given.
|
|
||
| enter_module() { | ||
| local resolved | ||
| resolved="$(eezo_resolve "$(pwd -P)" "$EEZO_PROJECT")" || return 1 |
There was a problem hiding this comment.
A module directory that is a symlink does not find the build root.
pwd -P gives the physical path. When the module directory is a symlink to a directory out of the build, the walk up never reaches the root build.sbt. The refusal then shows a path that the user did not type. This is not a regression.
Fix: find the build root from the logical path ($PWD) and keep the physical path only for the comparison with the project bases. As an alternative, say in docs/reference/cli.md that a module directory that is a symlink is not supported.
| code=$? | ||
| set -e | ||
| [ "$code" -ne 0 ] || fail "root with several projects should refuse" | ||
| printf '%s' "$err" | grep -q "hello" || fail "refusal should name hello: $err" |
There was a problem hiding this comment.
The fixture does not prove which refusal it got.
These checks grep for fragments (hello, todo, --project) that more than one message contains. In a copy of bin/eezo, I changed the "several projects" refusal to the "not inside a project" text and changed the four dispatch refusals to oops. The fixture still printed eezo module choice: ok.
The dispatch refusals have no test: --project needs a project id, --project is not used with new|deploy|upgrade, --project is not used with this command and --project needs a command.
Fix: move the argv checks into a function that the fixture can call, or run bin/eezo with a stub sbt on PATH. Then assert the full stderr line and the exit code of each refusal.
| val eezo = pluginProjects(extracted) | ||
| // A project the launcher already selected, `reminders` for one, is not the aggregate. Do | ||
| // not look at the build root and take a sibling that does enable the plugin. | ||
| if (extracted.currentRef.project != rootId) { |
There was a problem hiding this comment.
No test covers this guard.
The rule "a current project that is not the root and does not enable the plugin is refused" depends on this line. No suite calls scoped. I removed the guard and DevCommandSuite stayed green, 14 of 14. Without the guard, sbt "project lib" eezoDev switches to the one sibling that enables EezoPlugin.
The test "a project without the plugin is not replaced by a sibling" gives Selected("reminders") to forConsole. Production never builds that input, because choose always gets user.dir, which is the build root.
Fix: move the guard into ModuleChoice, so that forConsole takes the current id and the root id, and test that case in DevCommandSuite.
|
|
||
| /** Which project a directory names. | ||
| * | ||
| * The launcher applies the same rule to the projects it read from the build definition, because it |
There was a problem hiding this comment.
The launcher does not apply the same rule.
For a build whose only project is lazy val root = (project in file(".")), seen from root/src, eezo_choose_from selects root and ModuleChoice.choose returns Unmatched.
Also, the only production caller is DevCommand.scoped. It passes explicit = None and cwd = user.dir, which is the build root. Thus the explicit branch, Unknown and the longest nested match are not reachable from production.
Fix: in DevCommand.scoped, select the project when pluginProjects has exactly one entry and refuse in the other cases. Then remove ModuleChoice.choose or remove this sentence from the scaladoc.
| forwards to the application's own `main` as `sbt "run <command> <args>"`, so `eezo db status` and | ||
| `sbt "run db status"` are the same code path, and so is the sbt task `eezoStatus`. | ||
| forwards to the application's own `main`. Standing in a module, that is | ||
| `sbt "<id>/run <command> <args>"`. A build with one project keeps `sbt "run <command> <args>"`. |
There was a problem hiding this comment.
This sentence does not describe what the launcher sends.
The launcher keeps run <command> <args> only when it reads no project declaration. A build that declares its one project, such as lazy val root = (project in file(".")), gets root/run routes, project root; eezoDev and root/eezoStage.
Fix: write that a build that declares no project keeps sbt "run <command> <args>", and that a build with one declared project is scoped to that project.
The launcher walks up to the build root and selects the project whose directory contains you. A project flag names one when the directory does not. eezoDev stays a command. DevProcess keeps one application per project base.
Why
Issue #293: the launcher and the console assume the application is the root project. That is true of a scaffold and false of examples/, or of any multimodule sbt build.
From examples/, eezo routes is sbt "run routes" on the aggregate. The aggregate has no sources, so it dies with No main class detected. From examples/hello, sbt has no build, so it dies with Neither build.sbt nor a 'project' directory. eezo dev is sbt eezoDev at the root: every project that enables EezoPlugin starts at once, they race for 8080, and DevProcess kept one child, so a SIGTERM reaped hello and left todo listening on 8090. sbt hello/eezoDev is not a valid spelling, because eezoDev is a command, not a task.
What already worked, and was not reachable through bin/eezo: sbt "hello/run routes" and sbt "project hello" eezoDev.
What
The launcher walks up to the build root and selects the project whose directory contains you. --project names one when the directory does not. dev, build, db, routes and config then run sbt from that root as project hello; eezoDev or hello/run routes. A single-project build stays unscoped. eezoDev stays a command.
ModuleChoice is the shared rule. The launcher applies it to the projects it read from the build definition, before sbt starts. eezoDev applies it to sbt's own project list when the current project does not enable the plugin. Several eezo projects at the aggregate stay a refusal. A selected project that does not enable the plugin is a refusal too, so a sibling is not taken in its place.
DevProcess is one application per project base. Restarting one does not drop another. eezoStop stops that base. The shutdown hook still reaps every slot.
docs/reference/cli.md records that a module directory is a valid place to stand, and that --project names one at a build root with several projects. The hello README's console line is sbt "project hello" eezoDev.
Verification
bin/eezo-module-test sources the launcher and asserts the command string without starting sbt (single and multi project, nested paths, --project, unreadable builds). CI and bin/gate run it.
DevCommandSuite covers ModuleChoice.choose and forConsole.
Fixes #293