Last active
September 3, 2015 17:11
-
-
Save abbradar/ee0d0523486ffcc92e6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env julia | |
dbpath = "$(pwd())/updatedb" | |
mkpath(dbpath) | |
Pkg.update() | |
metadata = Pkg.dir("METADATA") | |
function readpkg(name :: ASCIIString) | |
version = Pkg.available(name)[end] | |
# uncomment this for no segfault! | |
#println("got version") | |
metadata_file = "$metadata/$name/versions/$version/requires" | |
requires = begin | |
try | |
f = open(metadata_file) | |
try | |
clear = x -> x | |
Set{ASCIIString}(map(clear, readlines(f))) | |
finally | |
close(f) | |
end | |
catch | |
Set{ASCIIString}() | |
end | |
end | |
url = split(readall("$metadata/$name/url"), "\n")[1] | |
rev = split(readall("$metadata/$name/versions/$version/sha1"), "\n")[1] | |
cd(dbpath) | |
sha256 = begin | |
try | |
if ! isdir(name) | |
mkdir(name) | |
cd(name) | |
run(`git init`) | |
else | |
cd(name) | |
try | |
run(`git remote remove origin`) | |
catch | |
end | |
end | |
# or remove any of these | |
run(`git remote add origin $url`) | |
run(`git fetch -t origin`) | |
"aaabbb" | |
catch | |
rethrow() | |
end | |
end | |
# remove "try" block for no segfault! | |
try | |
"aaaa" | |
catch | |
# or remove this! | |
println("$name $version $requires $url $rev $sha256") | |
rethrow() | |
end | |
end | |
map(readpkg, Pkg.available()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env julia | |
#dbpath = "$(homedir()).julia-updatedb" | |
dbpath = "$(pwd())/updatedb" | |
mkpath(dbpath) | |
Pkg.update() | |
metadata = Pkg.dir("METADATA") | |
immutable Package | |
version :: VersionNumber | |
requires :: Set{ASCIIString} | |
url :: ASCIIString | |
rev :: ASCIIString | |
# Not supported in Julia <0.4 | |
#sha256 :: Nullable{ASCIIString} | |
sha256 :: ASCIIString | |
end | |
function readpkg(name :: ASCIIString) | |
version = Pkg.available(name)[end] | |
# uncomment this for a hang (what?) | |
#println("rainbows") | |
metadata_file = "$metadata/$name/versions/$version/requires" | |
requires = try | |
f = open(metadata_file) | |
try | |
# FIXME: actual conversion | |
clear = x -> x | |
Set{ASCIIString}(map(clear, readlines(f))) | |
finally | |
close(f) | |
end | |
catch | |
Set{ASCIIString}() | |
end | |
url = split(readall("$metadata/$name/url"), "\n")[1] | |
rev = split(readall("$metadata/$name/versions/$version/sha1"), "\n")[1] | |
cd(dbpath) | |
sha256 = try | |
if ! isdir(name) | |
mkdir(name) | |
cd(name) | |
run(`git init`) | |
else | |
cd(name) | |
try | |
run(`git remote remove origin`) | |
catch | |
end | |
end | |
run(`git remote add origin $url`) | |
run(`git fetch -t origin`) | |
#output = readlines(`nix-prefetch-git --leave-dotGit file://$dbpath/$name $rev`) | |
#Nullable(output[3]) | |
#output[3] | |
"foobarbazdeadbeef" | |
catch e | |
showerror(STDERR, e) | |
#return Nullable() | |
"" | |
end | |
try | |
# No keyword arguments, https://github.com/JuliaLang/julia/issues/5333 | |
#(name, Package(version = version, requires = requires, url = url, rev = rev, sha256 = sha256)) :: (ASCIIString, Package) | |
(name, Package(version, requires, url, rev, sha256)) :: (ASCIIString, Package) | |
catch | |
println("Coerce error: $name $version $requires $url $rev $sha256") | |
rethrow() | |
end | |
end | |
function clear_invalid(pkgs :: Dict{ASCIIString, Package}) | |
#pkgs' = filter(pkg -> all((_, name) -> pkgs.haskey(name), pkg.requires), pkgs) | |
if length(pkgs') == length(pkgs) | |
pkgs' | |
else | |
clear_invalid(pkgs') | |
end | |
end | |
pkgs = begin | |
plist = map(readpkg, Pkg.available()) | |
#p = filter((_, pkg) -> !pkg.sha256.isnull(), Dict(plist)) | |
p = filter((_, pkg) -> pkg.sha256 != "", Dict(plist)) | |
clear_invalid(p) | |
end | |
println(""" | |
/* julia-packages.nix is an auto-generated file -- DO NOT EDIT! */ | |
{ callPackage }: | |
self: { | |
""") | |
for (name, pkg) in pkgs | |
requires_input = foldl((a,b) -> a * ", " * b, "mkDerivation", pkg.requires) | |
requires_list = foldl((a,b) -> a * " " * b, "", pkg.requires) | |
println(""" | |
\"$name\" = callPackage | |
({ $requires_input }: | |
mkDerivation { | |
pname = "$name"; | |
version = "$pkg.version"; | |
url = "$pkg.url"; | |
rev = "$pkg.rev"; | |
sha256 = "$pkg.sha256"; | |
buildInputs = [ $requires_list ]; | |
}) {}; | |
""") | |
end | |
println("}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment