Skip to content

Commit

Permalink
add-pkgdependency checkpoint functional
Browse files Browse the repository at this point in the history
  • Loading branch information
jwatson0 committed Mar 10, 2024
1 parent a489270 commit 3bb3abf
Show file tree
Hide file tree
Showing 12 changed files with 664 additions and 165 deletions.
2 changes: 1 addition & 1 deletion slm.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "slm"
version = "0.5.6"
version = "0.5.9"

[dependencies]
stanza-toml = { git = "StanzaOrg/stanza-toml", version = "0.4.0" }
Expand Down
2 changes: 2 additions & 0 deletions src/commands/build.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ public defn build (cmd-args:CommandArgs) -> False:
val platform = get-platform()
set-env("SLM_PLATFORM", platform)

debug("calling slm/dependencies/fetch-and-sync")
val dependencies = slm/dependencies/fetch-and-sync(cfg, force-build)

debug("calling get-cwd")
val slm-dir = path-join(get-cwd(), SLM_DIR)

val stanza-exe = get-stanza-exe(compiler?(cfg))
Expand Down
339 changes: 339 additions & 0 deletions src/conan-utils.stanza

Large diffs are not rendered by default.

61 changes: 42 additions & 19 deletions src/dependencies.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ defpackage slm/dependencies:

public defn fetch-and-sync (cfg:SlmToml, force:True|False) -> Tuple<Dependency>:

debug("fetch-and-sync: calling ensure-slm-dir-structure-exists")
ensure-slm-dir-structure-exists()

debug("fetch-and-sync: calling resolve-deps")
val deps = resolve-deps(cfg)

debug("fetch-and-sync: calling check-stanza-compatible-deps")
check-stanza-compatible-deps(cfg, deps, force)

debug("fetch-and-sync: returning deps")
deps

defn resolve-deps (cfg:SlmToml) -> Tuple<Dependency> :
Expand All @@ -35,18 +40,24 @@ defn resolve-deps (cfg:SlmToml) -> Tuple<Dependency> :
; 2. Otherwise we use the slm.toml
if file-exists?(SLM_LOCK_NAME):
val lock-cfg = within f = open(SLM_LOCK_NAME):
debug("resolve-deps: calling parse-slm-lock-file")
parse-slm-lock-file(f)
debug("resolve-deps: calling parse-slm-lock-and-resolve-dependencies")
parse-slm-lock-and-resolve-dependencies(cfg, lock-cfg)
else:
debug("resolve-deps: calling parse-slm-toml-and-resolve-dependencies")
val deps = parse-slm-toml-and-resolve-dependencies(cfg)

; We only write this
within f = open(SLM_STANZA_PROJ, false):
debug("resolve-deps: calling write-build-stanza-proj")
write-build-stanza-proj(f, deps)

within f = open(SLM_LOCK_NAME, false):
debug("resolve-deps: calling write-slm-lock-file")
write-slm-lock-file(f, deps)

debug("resolve-deps: returning deps")
deps

defn check-stanza-compatible-deps (cfg:SlmToml, deps:Tuple<Dependency>, force:True|False) :
Expand Down Expand Up @@ -75,14 +86,23 @@ defn ensure-slm-dir-structure-exists () -> False:
false

public-when(TESTING) defn write-build-stanza-proj (f:OutputStream, dependencies: Tuple<Dependency>) -> False:
val deps* = recursive-deps-only(dependencies)
for dep in deps* do:
val dep-path = path-join(path(dep), "stanza.proj")
val stanza-proj? = resolve-path(dep-path)
val dep-stanza-proj = un-norm-path $ match(stanza-proj?):
(x:False): throw $ Exception("Failed to Resolve Path %_. Double check path dependencies and confirm expected git repos in '.slm/deps'" % [dep-path])
(x:String): x
println(f, to-string(\<>include "%_"<> % [dep-stanza-proj]))
label<False> return:
val deps* = recursive-deps-only(dependencies)
for dep in deps* do:
val dep-path = path-join(path(dep), "stanza.proj")
val stanza-proj? = resolve-path(dep-path)
val dep-stanza-proj = un-norm-path $ match(stanza-proj?):
(x:False):
; pkg dependencies may or may not have a stanza.proj
match(dep):
(pkgdep:PkgDependency):
if not file-exists?(dep-path):
debug("stanza.proj doesn't exist for pkg \"%_\", skipping dep-path = \"%_\"" % [name(dep), dep-path])
return(false)
(d): false
throw $ Exception("Failed to Resolve Path %_. Double check path dependencies and confirm expected git repos in '.slm/deps'" % [dep-path])
(x:String): x
println(f, to-string(\<>include "%_"<> % [dep-stanza-proj]))


defn parse-slm-lock-and-resolve-dependencies (cfg:SlmToml, lock-cfg:Tuple<LockedDependency>):
Expand Down Expand Up @@ -130,14 +150,12 @@ defn parse-slm-lock-and-resolve-dependencies (cfg:SlmToml, lock-cfg:Tuple<Locked
val slm-toml-dep? = get?(slm-toml-dependencies, name(dep))
match(slm-toml-dep?):
(slm-toml-dep:PkgDependency):
val tomlver = version(value-or-throw(pkg?(slm-toml-dep), InvalidPkgDependency(name(dep), "No 'pkg' key found")))
val lockver = version(value-or-throw(pkg?(pkg-dep), InvalidPkgDependency(name(dep), "No 'pkg' key found")))
if not compatible?(tomlver, lockver):
if version(slm-toml-dep) != version(pkg-dep):
error("'%_' (version %_) specified in 'slm.toml'.\n\
This conflicts with locked version ('%_') from 'slm.lock'\n\
If you wish to use the version from your 'slm.toml', \
run 'slm clean', then re-run this command."
% [name(dep), tomlver, lockver])
% [name(dep), version(slm-toml-dep), version(pkg-dep)])
else:
fetch-or-sync-pkgver(pkg-dep)
pkg-dep
Expand Down Expand Up @@ -263,9 +281,11 @@ defn parse-slm-toml-and-resolve-dependencies (cfg:SlmToml) -> Tuple<Dependency>:
You can't have path dependencies in dependencies \
(path dependencies can only be specified in a top-level slm.toml)"
% [/name(dep), parent-name])
(dep: PkgDependency):
fetch-or-sync-pkgver(dep, parent-name, dep-path)
(dep: TaskDependency):
run-task-dep(dep, parent-name, dep-path)
(_): fatal("unreachable")
(_): fatal("parse-slm-toml-and-resolve-dependencies: unexpected dependency type: %_" % [dep])

debug("done resolving '%_'" % [parent-name])

Expand All @@ -277,12 +297,15 @@ defn parse-slm-toml-and-resolve-dependencies (cfg:SlmToml) -> Tuple<Dependency>:
val resolved* = recursive-deps-only(resolved)
for dep in resolved* do:
val next-slm-toml = path-join(path(dep), SLM_TOML_NAME)
debug("parsing '%_'" % [next-slm-toml])
val [dep-path, _] = split-filepath(next-slm-toml)
debug("dep-path: %_" % [dep-path])
val next-cfg = within f = open(next-slm-toml):
parse-slm-toml(f)
loop(next-cfg, dep-path, false)
if not file-exists?(next-slm-toml):
debug("skipping '%_': does not exist" % [next-slm-toml])
else:
debug("parsing '%_'" % [next-slm-toml])
val [dep-path, _] = split-filepath(next-slm-toml)
debug("dep-path: %_" % [dep-path])
val next-cfg = within f = open(next-slm-toml):
parse-slm-toml(f)
loop(next-cfg, dep-path, false)

debug("done parsing dependency graph")
for dep in values(resolved-dependencies) do:
Expand Down
7 changes: 3 additions & 4 deletions src/lock.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ with:

public defstruct LockedPkgDependency <: LockedDependency:
name: String with: (as-method => true)
version: SemanticVersion
version: String
type: String
options: Tuple<KeyValue<String, String>>
with:
Expand All @@ -66,7 +66,7 @@ public defn parse-slm-lock-file (f:InputStream) -> Tuple<LockedDependency>:
LockedGitDependency(name, locator, version, hash)
(locator?: None, type?: One, version?: One, options?: One, hash?: None):
val type = value!(type?) as String
val version = value!(version?) $> parse-semver $> value!
val version = value!(version?) as String
val options = value!(options?) as Tuple<KeyValue<String, String>>
LockedPkgDependency(name, version, type, options)
(locator?: None, type?: None, version?: None, options?: None, hash?: One):
Expand All @@ -86,9 +86,8 @@ public defn write-slm-lock-file (f:OutputStream, dependencies: Tuple<Dependency>
println(f, "%_={locator=%~,version=%~,hash=%~}"
% [name(dep), locator(dep), to-string(version(dep)), hash(dep)])
(dep: PkgDependency):
val pkg = value-or-throw(pkg?(dep), InvalidPkgDependency(name(dep), "No 'pkg' key found"))
println(f, "%_={version=%~,type=%~,options=%~}"
% [name(dep), to-string(version(pkg)), type(pkg), to-string(options(pkg))])
% [name(dep), to-string(version(dep)), type(dep), to-string(options(dep))])
(dep: PathDependency):
println(f, "%_={}" % [name(dep)])
(dep: TaskDependency):
Expand Down
Loading

0 comments on commit 3bb3abf

Please sign in to comment.