Permalink
Browse files

Added version index reading and parsing. List candidates. Updated docs

  • Loading branch information...
1 parent 2be7067 commit ee0a58889de3ab47129be8be2bfb81d46fb51d76 @gian gian committed Oct 22, 2011
View
@@ -2,3 +2,13 @@ This is the start of a package manager for Standard ML libraries.
The implementation mostly just contains stubs, but the semantic versioning
library should be helpful along the way.
+
+Development notes:
+
+Create a $HOME/.smackage directory.
+
+You might like to copy doc/versions.smackspec.example to $HOME/.smackage/versions.smackspec
+
+smack install foolib 1.0.0
+
+Will list installation candidates, and attempt to create folders. Eventually these two activities will have some relation to one another.
@@ -0,0 +1,8 @@
+provides: foolib 1.0.0
+remote: git git@github.com:standardml/smackage.git
+
+provides: foolib 1.0.2
+remote: git git@github.com:standardml/smackage.git
+
+provides: foolib 2.0.0
+remote: git git@github.com:standardml/smackage.git
View
@@ -34,45 +34,25 @@ struct
raise SmackExn "Cannot find smackage home. Try setting SMACKAGE_HOME"
end
- (** Parse the versions.smackspec file to produce a list of available
- (package,version,protocol) triples. *)
- fun parseVersionsSpec () =
- let
- val fp = TextIO.openIn (smackHome ^ "/versions.smackspec")
- handle _ => raise Fail
- ("Cannot open `$SMACKAGE_HOME/versions.smackspec'. " ^
- "Try running `smack refresh' to update this file.")
-
- val stanza = ref "";
-
- fun readStanzas () =
- let
- val line = TextIO.inputLine fp
- in
- if line = NONE then [!stanza] else
- if line = SOME "\n"
- then (!stanza before stanza := "") :: readStanzas ()
- else (stanza := (!stanza) ^ (valOf line); readStanzas ())
- end
-
- val stanzas = readStanzas () handle _ => (TextIO.closeIn fp; [])
- val _ = TextIO.closeIn fp
- in
- map (Spec.toVersionSpec o Spec.fromString) stanzas
- end
(** Install a package with a given name and version.
An empty version string means "the latest version".
raises SmackExn in the event that the package is already installed or
if no such package or version is found. *)
fun install name version =
let
+ val _ = VersionIndex.loadVersions smackHome
val _ = if version = "" then
raise Fail "Install needs an explicit version for now."
else ()
val ver = SemVer.fromString version
val _ = SmackLib.install smackHome (name,ver)
+ val _ = print "Candidates:\n"
+ val candidates = VersionIndex.queryVersions name
+ val _ = List.app
+ (fn (n,v,p) => print (n ^ " " ^ SemVer.toString v ^ "\n"))
+ candidates
in
()
end
@@ -2,10 +2,11 @@ $(SML_LIB)/basis/basis.mlb
$(SML_LIB)/smlnj-lib/Util/smlnj-lib.mlb
src/semver.sml
src/protocol.sml
+src/spec.sml
+src/version-index.sml
src/get-git.sml
src/get-http.sml
src/conductor.sig
src/conductor.sml
src/smackage-path.sml
-src/spec.sml
src/smacklib.sml
View
@@ -3,6 +3,7 @@ Group is
$/smlnj-lib.cm
src/protocol.sml
src/semver.sml
+ src/version-index.sml
src/conductor.sig
src/conductor.sml
@@ -11,7 +11,7 @@ struct
(* TODO: Verify that the package and version actually exist. *)
fun install smackage_root (pkg,ver) =
(SmackagePath.createPackagePaths smackage_root (pkg,ver);
- (#get (Conductor.package smackage_root pkg)) ver)
+ (*(#get (Conductor.package smackage_root pkg)) ver)*) ())
fun uninstall smackage_root (pkg,ver) = raise Fail "Not implemented"
@@ -235,7 +235,9 @@ struct
fun parseKeyLine (line, position) =
let
- val (key :: valueParts) = String.fields (fn c => c = #":") line
+ val (key,valueParts) =
+ (fn (key :: valueParts) => (key,valueParts) | _ => raise Fail "parseKeyValues: key error")
+ (String.fields (fn c => c = #":") line)
in
if CharVector.all (fn c => Char.isAlphaNum c orelse c = #"-") key
then (key, String.concatWith ":" valueParts)
@@ -0,0 +1,40 @@
+structure VersionIndex =
+struct
+ val versionIndex = ref [] : (string * SemVer.semver * Protocol.protocol) list ref
+
+ (** Parse the versions.smackspec file to produce a list of available
+ (package,version,protocol) triples. *)
+ fun parseVersionsSpec smackage_root =
+ let
+ val fp = TextIO.openIn (smackage_root ^ "/versions.smackspec")
+ handle _ => raise Fail
+ ("Cannot open `$SMACKAGE_HOME/versions.smackspec'. " ^
+ "Try running `smack refresh' to update this file.")
+
+ val stanza = ref "";
+
+ fun readStanzas () =
+ let
+ val line = TextIO.inputLine fp
+ in
+ if line = NONE then [!stanza] else
+ if line = SOME "\n"
+ then (!stanza before stanza := "") :: readStanzas ()
+ else (stanza := (!stanza) ^ (valOf line); readStanzas ())
+ end
+
+ val stanzas = readStanzas () handle _ => (TextIO.closeIn fp; [])
+
+ val _ = TextIO.closeIn fp
+ in
+ map (Spec.toVersionSpec o Spec.fromString) stanzas
+ end
+
+ (* Avoid re-loading the version index ever again. *)
+ fun loadVersions smackage_root =
+ if length (!versionIndex) > 0 then () else
+ versionIndex := parseVersionsSpec smackage_root
+
+ fun queryVersions pkg = List.filter (fn (n,_,_) => pkg = n) (!versionIndex)
+end
+

0 comments on commit ee0a588

Please sign in to comment.