Skip to content

Commit

Permalink
[Refactor] Changed stanza.proj tree structure
Browse files Browse the repository at this point in the history
Closes JITX-7191

This commit changes the way that the `stanza.proj` files are created for
projects.

In the old way, the `.slm/stanza.proj` was effectively the `root` stanza
project file. This meant that to build, slm had to change directories to `.slm`
and then run the `stanza build` there.

This caused a lot of complexity. It meant that I couldn't just run
`stanza build` at the root directory. It also broke dependency resolution
in vscode via the stanza language server.

This commit creates the root `stanza.proj` at the root of the project
and then has the root `stanza.proj` import `.slm/stanza.proj`. The
`.slm/stanza.proj` still manages all of the resolved dependencies of
the project and abstracts that away from the end user. With this setup:

1.  The user can run `stanza build` from the root
2.  VSCode language server continues to work as expected.
3.  The structure of the project is a lot more clear.
4.  We can more easily define configuration options that affect the build
    without hiding them inside the `slm` executable. Specifically - I
    moved the `-pkg pkgs` command line option and put it  in the `stanza.proj`
    file for the `main` target. This means `stanza build` will just work.
  • Loading branch information
callendorph committed Nov 23, 2023
1 parent b7ebfbf commit e1fd9d2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/commands/build.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ defn write-build-stanza-proj (dependencies: Tuple<Dependency>) -> False:
for dep in dependencies do:
val dep-path = get-cwd() $> parse-path $> relative-to-dir{_, dep $> /path}
println(f, to-string(\<>include "%_/stanza.proj"<> % [dep-path]))
println(f, \<>include "../stanza.proj"<>)

defn write-slm-lock-file (dependencies: Tuple<Dependency>) -> False:
within f = open("slm.lock", false):
Expand Down Expand Up @@ -89,13 +88,17 @@ public defn build (cmd-args:CommandArgs) -> False:
val build-args = get-build-args()
debug("with build args '%,'" % [build-args])

val args = to-tuple $ cat-all([[stanza-exe, "build"], targ?, build-args, ["-pkg", "pkgs"]])
; In general - we want all of the options for the project to be
; captured in the `stanza.proj` file - not as options passed to this command.
; Otherwise, the user will have to remember to pass `-pkg pkgs` on the command
; line to the `stanza build` if they want to run the compiler directly instead
; of through `slm`
val args = to-tuple $ cat-all([[stanza-exe, "build"], targ?, build-args])
val vStr = version(cfg)
debug("Build Version: %_" % [vStr])
val env-vars = ["SLM_BUILD_VERSION" => vStr]
debug("Stanza: %," % [args])
ProcessBuilder(args)
$> in-dir{_, slm-dir}
$> with-env-vars{_, env-vars}
$> build
$> wait-process-throw-on-nonzero{_, "build failed!"}
Expand Down
9 changes: 6 additions & 3 deletions src/commands/init.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public defn init (cmd-args:CommandArgs) -> False:

; Create empty .slm directory structure
create-dir(slm-dir-path)
create-dir(to-string("%_/pkgs/" % [slm-dir-path]))
val pkg-path = to-string("%_/pkgs/" % [slm-dir-path])
create-dir(pkg-path)
create-dir(to-string("%_/deps/" % [slm-dir-path]))
create-empty-file(to-string("%_/stanza.proj" % [slm-dir-path]))

Expand All @@ -76,13 +77,15 @@ public defn init (cmd-args:CommandArgs) -> False:
val main-package = to-string("%_/main" % [project-name])
val stanza-proj-path = to-string("%_/stanza.proj" % [project-dir])
if not file-exists?(stanza-proj-path):
spit(stanza-proj-path, \<>include "src/stanza.proj"
spit(stanza-proj-path, \<>include ".slm/stanza.proj" ; Dependencies
include "src/stanza.proj" ; Project Sources

build main:
inputs: %_
pkg: "%_"
o: "%_"
<>
% [main-package, project-name])
% [main-package, pkg-path, project-name])

; Create src/
val project-src-dir = to-string("%_/src/" % [project-dir])
Expand Down
3 changes: 1 addition & 2 deletions src/commands/repl.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public defn repl (cmd-args:CommandArgs) -> False:
val cfg = parse-slm-toml("slm.toml")
val stanza-exe = get-stanza-exe(compiler?(cfg))
val repl-args = get-repl-args()
val args = to-tuple $ cat-all([[stanza-exe, "repl"], repl-args, ["-pkg", "pkgs"]])
val args = to-tuple $ cat-all([[stanza-exe, "repl"], repl-args])
val slm-dir = to-string("%_/.slm" % [get-cwd()])

val vStr = version(cfg)
Expand All @@ -27,7 +27,6 @@ public defn repl (cmd-args:CommandArgs) -> False:
debug("Stanza: %," % [args])

ProcessBuilder(args)
$> in-dir{_, slm-dir}
$> with-env-vars{_, env-vars}
$> build
$> run-and-get-exit-code
Expand Down
1 change: 1 addition & 0 deletions stanza.proj
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include ".slm/stanza.proj"
include "src/stanza.proj"

build main:
Expand Down

0 comments on commit e1fd9d2

Please sign in to comment.