Skip to content

Commit

Permalink
Merge pull request #241 from savi-lang/add/load-from-deps-dir
Browse files Browse the repository at this point in the history
Add ability to load 3rd-party deps from the `deps` dir, by version.
  • Loading branch information
jemc authored Feb 28, 2022
2 parents 52af0c9 + cbe223c commit 184dd58
Show file tree
Hide file tree
Showing 29 changed files with 169 additions and 89 deletions.
6 changes: 3 additions & 3 deletions examples/adventofcode/2018/manifest.savi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:manifest "adventofcode-2018"
:sources "src/*.savi"

:dependency Spec "TODO: specify version"
:dependency Map "TODO: specify version"
:dependency Time "TODO: specify version"
:dependency Spec v0
:dependency Map v0
:dependency Time v0
10 changes: 5 additions & 5 deletions examples/http/manifest.savi
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
:manifest "http-example"
:sources "src/*.savi"

:dependency HTTPServer "TODO: specify version"
:dependency TCP "TODO: specify version"
:dependency IO "TODO: specify version"
:transitive dependency ByteStream "TODO: specify version"
:transitive dependency OSError "TODO: specify version"
:dependency HTTPServer v0
:dependency TCP v0
:dependency IO v0
:transitive dependency ByteStream v0
:transitive dependency OSError v0
4 changes: 2 additions & 2 deletions packages/ByteStream.manifest.savi
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
:copies ByteStream
:sources "spec/ByteStream/**/*.savi"

:dependency Spec "TODO: specify version"
:transitive dependency Map "TODO: specify version"
:dependency Spec v0
:transitive dependency Map v0
6 changes: 3 additions & 3 deletions packages/DeterministicRandom.manifest.savi
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
:manifest lib DeterministicRandom
:sources "src/DeterministicRandom/**/*.savi"

:dependency Random "TODO: specify version"
:dependency Random v0

:manifest bin "spec-DeterministicRandom"
:copies DeterministicRandom
:sources "spec/DeterministicRandom/**/*.savi"

:dependency Spec "TODO: specify version"
:transitive dependency Map "TODO: specify version"
:dependency Spec v0
:transitive dependency Map v0
6 changes: 3 additions & 3 deletions packages/HTTPServer.manifest.savi
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
:manifest lib HTTPServer
:sources "src/HTTPServer/**/*.savi"

:dependency ByteStream "TODO: specify version"
:dependency ByteStream v0

:manifest bin "spec-HTTPServer"
:copies HTTPServer
:sources "spec/HTTPServer/**/*.savi"

:dependency Spec "TODO: specify version"
:transitive dependency Map "TODO: specify version"
:dependency Spec v0
:transitive dependency Map v0
4 changes: 2 additions & 2 deletions packages/IO.manifest.savi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:manifest lib IO
:sources "src/IO/**/*.savi"

:dependency ByteStream "TODO: specify version"
:dependency OSError "TODO: specify version"
:dependency ByteStream v0
:dependency OSError v0
4 changes: 2 additions & 2 deletions packages/JSON.manifest.savi
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
:copies JSON
:sources "spec/JSON/**/*.savi"

:dependency Spec "TODO: specify version"
:transitive dependency Map "TODO: specify version"
:dependency Spec v0
:transitive dependency Map v0
4 changes: 2 additions & 2 deletions packages/Map.manifest.savi
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
:copies Map
:sources "spec/Map/**/*.savi"

:dependency Spec "TODO: specify version"
:transitive dependency Map "TODO: specify version"
:dependency Spec v0
:transitive dependency Map v0
6 changes: 3 additions & 3 deletions packages/Random.manifest.savi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:copies Random
:sources "spec/Random/**/*.savi"

:dependency Spec "TODO: specify version"
:transitive dependency Map "TODO: specify version"
:dependency Spec v0
:transitive dependency Map v0

:dependency DeterministicRandom "TODO: specify version"
:dependency DeterministicRandom v0
4 changes: 2 additions & 2 deletions packages/Regex.manifest.savi
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
:copies Regex
:sources "spec/Regex/**/*.savi"

:dependency Spec "TODO: specify version"
:transitive dependency Map "TODO: specify version"
:dependency Spec v0
:transitive dependency Map v0
4 changes: 2 additions & 2 deletions packages/Savi.manifest.savi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:manifest bin "spec-Savi"
:sources "spec/Savi/**/*.savi"

:dependency Spec "TODO: specify version"
:transitive dependency Map "TODO: specify version"
:dependency Spec v0
:transitive dependency Map v0
2 changes: 1 addition & 1 deletion packages/Spec.manifest.savi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
:manifest lib Spec
:sources "src/Spec/**/*.savi"

:dependency Map "TODO: specify version"
:dependency Map v0

:manifest bin "spec-Spec"
:copies Spec
Expand Down
6 changes: 3 additions & 3 deletions packages/StdIn.manifest.savi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:manifest lib StdIn
:sources "src/StdIn/**/*.savi"

:dependency ByteStream "TODO: specify version"
:dependency IO "TODO: specify version"
:transitive dependency OSError "TODO: specify version"
:dependency ByteStream v0
:dependency IO v0
:transitive dependency OSError v0
10 changes: 5 additions & 5 deletions packages/TCP.manifest.savi
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
:manifest lib TCP
:sources "src/TCP/**/*.savi"

:dependency ByteStream "TODO: specify version"
:dependency IO "TODO: specify version"
:dependency OSError "TODO: specify version"
:dependency ByteStream v0
:dependency IO v0
:dependency OSError v0

:manifest bin "spec-TCP"
:copies TCP
:sources "spec/TCP/**/*.savi"

:dependency Spec "TODO: specify version"
:transitive dependency Map "TODO: specify version"
:dependency Spec v0
:transitive dependency Map v0
4 changes: 2 additions & 2 deletions packages/Time.manifest.savi
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
:copies Time
:sources "spec/Time/**/*.savi"

:dependency Spec "TODO: specify version"
:transitive dependency Map "TODO: specify version"
:dependency Spec v0
:transitive dependency Map v0
4 changes: 2 additions & 2 deletions packages/Unicode.manifest.savi
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
:copies Unicode
:sources "spec/Unicode/**/*.savi"

:dependency Spec "TODO: specify version"
:transitive dependency Map "TODO: specify version"
:dependency Spec v0
:transitive dependency Map v0
4 changes: 2 additions & 2 deletions packages/src/Savi/declarators/declarators.savi
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@
:begins manifest_dependency

:term name Name
:term version String
:term version Name

// TODO: Document this.
:declarator transitive
Expand All @@ -512,7 +512,7 @@

:keyword dependency
:term name Name
:term version String
:term version Name

// TODO: Document this.
:declarator from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ from ./manifest.savi:1:

- this transitive dependency needs to be added:
from ../../../packages/TCP.manifest.savi:4:
:dependency ByteStream "TODO: specify version"
:dependency ByteStream v0
^~~~~~~~~~

- it is required by this existing dependency:
from ./manifest.savi:4:
:dependency TCP "TODO: specify version"
:dependency TCP v0
^~~

- run again with --fix to auto-fix this issue.
Expand All @@ -29,12 +29,12 @@ from ./manifest.savi:1:

- this transitive dependency needs to be added:
from ../../../packages/TCP.manifest.savi:5:
:dependency IO "TODO: specify version"
:dependency IO v0
^~

- it is required by this existing dependency:
from ./manifest.savi:4:
:dependency TCP "TODO: specify version"
:dependency TCP v0
^~~

- run again with --fix to auto-fix this issue.
Expand All @@ -48,12 +48,12 @@ from ./manifest.savi:1:

- this transitive dependency needs to be added:
from ../../../packages/TCP.manifest.savi:6:
:dependency OSError "TODO: specify version"
:dependency OSError v0
^~~~~~~

- it is required by this existing dependency:
from ./manifest.savi:4:
:dependency TCP "TODO: specify version"
:dependency TCP v0
^~~

- run again with --fix to auto-fix this issue.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
:manifest "example"
:sources "main.savi"

:dependency TCP "TODO: specify version"
:dependency TCP v0

:transitive dependency ByteStream "TODO: specify version"
:transitive dependency ByteStream v0

:transitive dependency IO "TODO: specify version"
:transitive dependency IO v0

:transitive dependency OSError "TODO: specify version"
:transitive dependency OSError v0
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:manifest "example"
:sources "main.savi"

:dependency TCP "TODO: specify version"
:dependency TCP v0
8 changes: 4 additions & 4 deletions spec/integration/run-stdin-from-file/manifest.savi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
:manifest "example"
:sources "src/*.savi"

:dependency StdIn "TODO: specify version"
:dependency IO "TODO: specify version"
:transitive dependency ByteStream "TODO: specify version"
:transitive dependency OSError "TODO: specify version"
:dependency StdIn v0
:dependency IO v0
:transitive dependency ByteStream v0
:transitive dependency OSError v0
8 changes: 4 additions & 4 deletions spec/integration/run-stdin-from-pipe-large/manifest.savi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
:manifest "example"
:sources "src/*.savi"

:dependency StdIn "TODO: specify version"
:dependency IO "TODO: specify version"
:transitive dependency ByteStream "TODO: specify version"
:transitive dependency OSError "TODO: specify version"
:dependency StdIn v0
:dependency IO v0
:transitive dependency ByteStream v0
:transitive dependency OSError v0
8 changes: 4 additions & 4 deletions spec/integration/run-stdin-from-pipe/manifest.savi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
:manifest "example"
:sources "src/*.savi"

:dependency StdIn "TODO: specify version"
:dependency IO "TODO: specify version"
:transitive dependency ByteStream "TODO: specify version"
:transitive dependency OSError "TODO: specify version"
:dependency StdIn v0
:dependency IO v0
:transitive dependency ByteStream v0
:transitive dependency OSError v0
2 changes: 1 addition & 1 deletion spec/integration/run-stdout/manifest.savi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:manifest "example"
:sources "src/*.savi"

:dependency ByteStream "TODO: specify version"
:dependency ByteStream v0
2 changes: 1 addition & 1 deletion src/savi/compiler/context.cr
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Savi::Compiler::Context
return if @program.manifests.any?(&.name.pos.source.package.path.==(path))

# Otherwise go ahead and load the manifests.
sources = compiler.source_service.get_manifest_sources_at_or_above(path)
sources = compiler.source_service.get_manifest_sources_at(path)
docs = sources.map { |source| Parser.parse(source) }
package = compile_package(sources.first.package, docs)
self
Expand Down
19 changes: 13 additions & 6 deletions src/savi/compiler/manifests.cr
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Savi::Compiler::Manifests

# Prove that all transitive dependencies are accounted for.
manifest.dependencies.each { |dep|
@manifests_by_name[dep.name.value].dependencies.each { |dep_dep|
@manifests_by_name[dep.name.value]?.try(&.dependencies.each { |dep_dep|
next if @manifests_by_name[dep_dep.name.value]?

ctx.error_at manifest.name,
Expand All @@ -49,10 +49,10 @@ class Savi::Compiler::Manifests
], [
{manifest.append_pos, [
"\n",
" :transitive dependency #{dep_dep.name.value} #{dep_dep.version_node.value.inspect}"
" :transitive dependency #{dep_dep.name.value} #{dep_dep.version.value}"
].join("\n")}
]
}
})
}

basic_manifest_checks(ctx)
Expand Down Expand Up @@ -118,9 +118,16 @@ class Savi::Compiler::Manifests
orig_manifests_size = manifests.size

# Compile all manifests at the path where the dep is to be found.
# TODO: actually use the given path from the dep information.
# Currently, this assumes all dependencies come from the standard package.
dep_path = ctx.compiler.source_service.standard_package_path
dep_path = if dep.location_nodes.empty?
# If not specified assume it come from the standard packages path.
# TODO: In the future, we should remove this option and source all
# standard library packages from individual GitHub repos, so that they
# can be versioned independently of one another.
ctx.compiler.source_service.standard_package_path
else
ctx.compiler.source_service.find_latest_in_deps(ctx, dep)
end
return unless dep_path
ctx.compile_manifests_at_path(dep_path)

# Limit the manifests we look at to just the set of newly added ones.
Expand Down
Loading

0 comments on commit 184dd58

Please sign in to comment.