Skip to content

Commit

Permalink
Reorganised PackageInstaller, added support for SVN and basic depende…
Browse files Browse the repository at this point in the history
…ncy management
  • Loading branch information
josip committed Mar 10, 2010
1 parent 07782e6 commit 7514c15
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 123 deletions.
4 changes: 2 additions & 2 deletions README.textile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
h1. Eerie, package manager for Io

Eerie is an attempt to create feature-full package manager for Io, due to lack of working and usable package managers.
Eerie is modelled after "Rip":http://hellorip.com which means that there is no central repository of packages, and environments as a
tool for switching between different versions.
Eerie is modelled after "Rip":http://hellorip.com which means that there is no central repository of packages, and that environments
are used as a tool for switching between different versions.

h2. How to install

Expand Down
Empty file removed depends
Empty file.
18 changes: 11 additions & 7 deletions io/Eerie.io
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ Eerie := Object clone do(
config ::= nil
envs := List clone

sh := method(cmd,
sh := method(cmd, logFailure,
self log(cmd, "console")
cmdOut := System runCommand(cmd)
if(cmdOut exitStatus != 0,
self log("Last command exited with the following error:", "error")
self log(cmdOut stdout, "output")
self log(cmdOut stderr, "output")
System exit(1))

true)
if(cmdOut exitStatus != 0,
if(logFailure == false,
false
,
self log("Last command exited with the following error:", "error")
self log(cmdOut stdout, "output")
self log(cmdOut stderr, "output")
System exit(1))
,
true))

_logMods := Map with(
"info", " - ",
Expand Down
File renamed without changes.
19 changes: 14 additions & 5 deletions io/Eerie/Package.io
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ Package := Object clone do(
withConfig := method(config,
self clone setConfig(config))

guessName := method(_uri,
f := File with(_uri)
f exists ifTrue(
return(f baseName makeFirstCharacterUppercase))

_uri containsSeq("://") ifTrue(
return(_uri split("/") last split(".") first makeFirstCharacterUppercase)))

setInstaller := method(inst,
self installer = inst
self config atPut("installer", inst type)
Expand All @@ -65,8 +73,7 @@ Package := Object clone do(
self downloader download

self loadMetadata
self dependencies ?isEmpty ifFalse(
self installDependencies)
self installDependencies

self setInstaller(Eerie PackageInstaller detect(self path))
self installer install
Expand All @@ -77,7 +84,9 @@ Package := Object clone do(
self runHook("after" .. event))

installDependencies := method(
Eerie log("Installing depenendencies"))
deps := self dependencies("packages")
deps foreach(_uri,
self with(self guessName(_uri), _uri) install))

update := method(
self runHook("beforeUpdateDownload")
Expand Down Expand Up @@ -115,8 +124,8 @@ Package := Object clone do(
p := self config at("meta") ?at("protos")
if(p isNil, list(), p))

dependencies := method(
d := self config at("meta") ?at("dependencies")
dependencies := method(category,
d := self config at("meta") ?at("dependencies") ?at(category)
if(d isNil, list(), d))

asJson := method(
Expand Down
2 changes: 1 addition & 1 deletion io/Eerie/PackageDownloader.io
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ PackageDownloader := Object clone do(
PackageDownloader instances := Object clone
PackageDownloader instances doRelativeFile("PackageDownloader/File.io")
PackageDownloader instances doRelativeFile("PackageDownloader/Directory.io")
PackageDownloader instances doRelativeFile("PackageDownloader/Git.io")
PackageDownloader instances doRelativeFile("PackageDownloader/Vcs.io")
25 changes: 0 additions & 25 deletions io/Eerie/PackageDownloader/Git.io

This file was deleted.

48 changes: 48 additions & 0 deletions io/Eerie/PackageDownloader/Vcs.io
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
VcsDownloader := Eerie PackageDownloader clone do(
vcs := Object clone do(
git := Object clone do(
check := method(uri,
uri containsSeq("git://") or uri containsSeq(".git"))

cmd := "git"
download := list("clone #{self uri} #{self path}", "submodule init", "submodule update")
update := list("update", "submodule update")
)

svn := Object clone do(
check := method(uri,
Eerie sh("svn info " .. uri, false))

cmd := "svn"
download := list("co #{self uri} #{self path}")
update := list("up")
)
)

vcsCmd := method(args,
Eerie sh((self vcs cmd) .. " " .. args))

runCommands := method(cmds,
cmds foreach(cmd,
self vcsCmd(cmd interpolate)))

whichVcs := method(_uri,
self vcs slotNames foreach(name,
self vcs getSlot(name) check(_uri) ifTrue(
return(name)))

nil)

canDownload := method(_uri,
self whichVcs(_uri) != nil)

download := method(
self vcs := self vcs getSlot(self whichVcs(self uri))

Directory with(self path) remove
self runCommands(self vcs download))

update := method(
self vcs := self vcs getSlot(self whichVcs(self uri))
self runCommands(self vcs update))
)
92 changes: 91 additions & 1 deletion io/Eerie/PackageInstaller.io
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ PackageInstaller := Object clone do(
//doc PackageInstaller path Path to at which package is located.
path ::= nil

//doc PackageInstaller root Directory with PackageInstallers' path.
root := method(
self root = Directory with(self path))

//doc PackageInstaller config Contains contents of a package.json
config ::= nil

//doc PackageInstaller with(path)
with := method(_path,
self clone setPath(_path))

//doc PacakgeInstaller detect(path) Returns first PackageInstaller which can install package at provided path.
detect := method(_path,
self instances foreachSlot(slotName, installer,
installer canInstall(_path) ifTrue(
Expand All @@ -14,8 +23,89 @@ PackageInstaller := Object clone do(

//doc PackageInstaller canInstall(path)
canInstall := method(path, false)
//doc PackageInstaller install()

//doc PackageInstaller install
install := method(false)

//doc PackageInstaller fileNamed(name) Returns an File relative to root directory.
fileNamed := method(name,
self root fileNamed(name))

//doc PackageInstaller dirNamed(name) Returns an Directory relative to root directory.
dirNamed := method(name,
self root directoryNamed(name))

loadConfig := method(
configFile := self fileNamed("package.json")
configFile exists ifTrue(
self setConfig(Yajl parseJson(configFile openForReading contents))
configFile close))

extractDataFromPackageJson := method(
providedProtos := self config at("protos") ?join(" ")
providedProtos isNil ifTrue(
providedProtos = "")

deps := self config at("dependencies")
protoDeps := deps ?at("protos") ?join(" ")
protoDeps isNil ifTrue(
protoDeps = "")

self fileNamed("protos") create openForUpdating write(providedProtos) close
self fileNamed("depends") create openForUpdating write(protoDeps) close

self fileNamed("build.io") exists ifFalse(
headerDeps := deps ?at("headers")
libDeps := deps ?at("libs")

buildIo := "AddonBuilder clone do(\n" asMutable
libDeps ?foreach(lib,
buildIo appendSeq(" dependsOnLib(\"#{lib}\")\n"))
headerDeps ?foreach(header,
buildIo appendSeq(" dependsOnHeader(\"#{header}\")\n"))
buildIo appendSeq(")\n")

self fileNamed("build.io") create openForUpdating write(buildIo interpolate) close))

compile := method(
builderContext := Object clone
builderContext doRelativeFile("AddonBuilder.io")
prevPath := Directory currentWorkingDirectory
Directory setCurrentWorkingDirectory(self path)

addon := builderContext doFile((self path) .. "/build.io")
addon folder := Directory with(self path)
addon build(if(System platform split at(0) asLowercase == "windows",
"-MD -Zi -DWIN32 -DNDEBUG -DIOBINDINGS -D_CRT_SECURE_NO_DEPRECATE",
"-Os -g -Wall -pipe -fno-strict-aliasing -DSANE_POPEN -DIOBINDINGS"))

Directory setCurrentWorkingDirectory(prevPath)
self)

buildPackageJson := method(
package := Map with(
"dependencies", list(),
"protos", list())

providedProtos := self fileNamed("protos")
protoDeps := self fileNamed("depends")

providedProtos exists ifTrue(
providedProtos openForReading contents split(" ") foreach(pp, package at("protos") append(pp strip)))
providedProtos close

protoDeps exists ifTrue(
protoDeps openForReading contents split(" ") foreach(pd, package at("dependencies") append(pd strip)))
protoDeps close

self fileNamed("package.json") create openForUpdating write(package asJson) close

self)

copyBinaries := method(
Eerie sh("chmod +x #{self path}/bin/*" interpolate)
self dirNamed("bin") files foreach(f,
Eerie sh("ln -s #{f path} #{Eerie activeEnv path}/bin/#{f name}" interpolate)))
)

PackageInstaller instances := Object clone do(
Expand Down
9 changes: 4 additions & 5 deletions io/Eerie/PackageInstaller/Directory.io
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ DirectoryInstaller := Eerie PackageInstaller clone do(
dir exists and(dir filesWithExtension("io") isEmpty not) and(packageJson exists not))

install := method(
root := Directory with(self path)
ioDir := root directoryNamed("io") create

ioDir := self dirNamed("io") create

protosList := list()
root filesWithExtension("io") foreach(ioFile,
self root filesWithExtension("io") map(ioFile,
ioFile baseName at(0) isUppercase ifTrue(
protoList append(ioFile baseName)))

Eerie sh("mv #{self path}/*.io #{ioDir path}" interpolate)

File with((self path) .. "/package.json") create openForUpdating write(Map with(
self fileNamed("package.json") remove create openForUpdating write(Map with(
"author", User name,
"dependencies", list(),
"protos", protosList
Expand Down
4 changes: 2 additions & 2 deletions io/Eerie/PackageInstaller/File.io
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ FileInstaller := Eerie PackageInstaller clone do(
f exists and(f isRegularFile))

install := method(
File with((self path) .. "/package.json") create openForUpdating write(Map with(
self fileNamed("package.json") remove create openForUpdating write(Map with(
"author", User name,
"dependencies", list(),
"protos", list(Directory with(self path) filesWithExtension("io") first baseName makeFirstCharacterUppercase)
"protos", list(self root filesWithExtension("io") first baseName makeFirstCharacterUppercase)
) asJson) close)
)
Loading

0 comments on commit 7514c15

Please sign in to comment.