aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c>2009-10-05 19:41:53 +0000
committerhisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c>2009-10-05 19:41:53 +0000
commitf62967e6d40307974c384b7f27aaf661fea26003 (patch)
tree09234b103a58d614d2e6ef7c92ca239f04180b81
parent5e3256ced6d08a72438db6a0374f8cf7b68db55a (diff)
downloadluarocks-f62967e6d40307974c384b7f27aaf661fea26003.tar.gz
luarocks-f62967e6d40307974c384b7f27aaf661fea26003.tar.bz2
luarocks-f62967e6d40307974c384b7f27aaf661fea26003.zip
new loader improvements
git-svn-id: http://luarocks.org/svn/luarocks/trunk@69 9ca3f7c1-7366-0410-b1a3-b5c78f85698c
-rw-r--r--src/luarocks2.lua70
1 files changed, 45 insertions, 25 deletions
diff --git a/src/luarocks2.lua b/src/luarocks2.lua
index 0ca2f505..f50bddf2 100644
--- a/src/luarocks2.lua
+++ b/src/luarocks2.lua
@@ -3,7 +3,7 @@ local global_env = _G
3local package, require, assert, ipairs, pairs, os, print, table, type, next, unpack = 3local package, require, assert, ipairs, pairs, os, print, table, type, next, unpack =
4 package, require, assert, ipairs, pairs, os, print, table, type, next, unpack 4 package, require, assert, ipairs, pairs, os, print, table, type, next, unpack
5 5
6module("luarocks") 6module("luarocks2")
7 7
8local path = require("luarocks.path") 8local path = require("luarocks.path")
9local manif_core = require("luarocks.manif_core") 9local manif_core = require("luarocks.manif_core")
@@ -20,12 +20,14 @@ rocks_trees = nil
20local function load_rocks_trees() 20local function load_rocks_trees()
21 local any_ok = false 21 local any_ok = false
22 local trees = {} 22 local trees = {}
23 23 for _, tree in pairs(cfg.rocks_trees) do
24 -- FIXME select correctly file to be fetched 24 local rocks_dir = path.rocks_dir(tree)
25 local persist = require("luarocks.persist") 25 local manifest, err = manif_core.load_local_manifest(rocks_dir)
26 table.insert(trees, { manifest = persist.load_into_table("manifest2") } ) 26 if manifest then
27 any_ok = true 27 any_ok = true
28 28 table.insert(trees, {rocks_dir=rocks_dir, manifest=manifest})
29 end
30 end
29 if not any_ok then 31 if not any_ok then
30 rocks_trees = false 32 rocks_trees = false
31 return false 33 return false
@@ -40,7 +42,7 @@ end
40-- @parse version string: The version of the rock, in string format 42-- @parse version string: The version of the rock, in string format
41-- @parse manifest table: The local manifest table where this rock 43-- @parse manifest table: The local manifest table where this rock
42-- is installed. 44-- is installed.
43local function add_context(name, version) 45function add_context(name, version)
44 -- assert(type(name) == "string") 46 -- assert(type(name) == "string")
45 -- assert(type(version) == "string") 47 -- assert(type(version) == "string")
46 -- assert(type(manifest) == "table") 48 -- assert(type(manifest) == "table")
@@ -49,27 +51,34 @@ local function add_context(name, version)
49 return 51 return
50 end 52 end
51 context[name] = version 53 context[name] = version
52 --[[
53 54
54 local pkgdeps = manifest.dependencies and manifest.dependencies[name][version] 55 if not rocks_trees and not load_rocks_trees() then
55 if not pkgdeps then 56 return nil
56 return
57 end 57 end
58 for _, dep in ipairs(pkgdeps) do 58
59 local package, constraints = dep.name, dep.constraints 59 local providers = {}
60 60 for _, tree in pairs(rocks_trees) do
61 for _, tree in pairs(rocks_trees) do 61 local manifest = tree.manifest
62 local entries = tree.manifest.repository[package] 62
63 if entries then 63 local pkgdeps = manifest.dependencies and manifest.dependencies[name][version]
64 for version, packages in pairs(entries) do 64 if not pkgdeps then
65 if (not constraints) or deps.match_constraints(deps.parse_version(version), constraints) then 65 return
66 add_context(package, version, tree.manifest) 66 end
67 for _, dep in ipairs(pkgdeps) do
68 local package, constraints = dep.name, dep.constraints
69
70 for _, tree in pairs(rocks_trees) do
71 local entries = tree.manifest.repository[package]
72 if entries then
73 for version, packages in pairs(entries) do
74 if (not constraints) or deps.match_constraints(deps.parse_version(version), constraints) then
75 add_context(package, version, tree.manifest)
76 end
67 end 77 end
68 end 78 end
69 end 79 end
70 end 80 end
71 end 81 end
72 ]]
73end 82end
74 83
75--- Internal sorting function. 84--- Internal sorting function.
@@ -82,8 +91,7 @@ end
82 91
83local function call_other_loaders(module, name, version, file) 92local function call_other_loaders(module, name, version, file)
84 93
85 local actual_module = file:match("(.*)%.[^.]+$") 94 local actual_module = file:match(".*/(.*)%.[^.]+$")
86
87 for i, loader in pairs(package.loaders) do 95 for i, loader in pairs(package.loaders) do
88 if loader ~= luarocks_loader then 96 if loader ~= luarocks_loader then
89 local results = { loader(actual_module) } 97 local results = { loader(actual_module) }
@@ -106,8 +114,20 @@ local function pick_module(module)
106 for _, tree in pairs(rocks_trees) do 114 for _, tree in pairs(rocks_trees) do
107 local entries = tree.manifest.modules[module] 115 local entries = tree.manifest.modules[module]
108 if entries then 116 if entries then
109 for entry, file in pairs(entries) do 117 for i, entry in ipairs(entries) do
110 local name, version = entry:match("^([^/]*)/(.*)$") 118 local name, version = entry:match("^([^/]*)/(.*)$")
119 local file = tree.manifest.repository[name][version][1].modules[module]
120 local deploy_dir
121 if file:match(cfg.lua_extension.."$") then
122 deploy_dir = cfg.deploy_lua_dir
123 else
124 deploy_dir = cfg.deploy_bin_dir
125 end
126 if i == 1 then
127 file = deploy_dir.."/"..file
128 else
129 file = path.versioned_name(deploy_dir.."/"..file, name, version)
130 end
111 if context[name] == version then 131 if context[name] == version then
112 return name, version, file 132 return name, version, file
113 end 133 end