aboutsummaryrefslogtreecommitdiff
path: root/src/luarocks/path.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/luarocks/path.lua')
-rw-r--r--src/luarocks/path.lua103
1 files changed, 57 insertions, 46 deletions
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua
index 596b73b8..05e04b43 100644
--- a/src/luarocks/path.lua
+++ b/src/luarocks/path.lua
@@ -17,28 +17,48 @@ function rockspec_name_from_rock(rock_name)
17end 17end
18 18
19function rocks_dir(repo) 19function rocks_dir(repo)
20 assert(type(repo) == "string") 20 if type(repo) == "string" then
21 return dir.path(repo, "lib", "luarocks", "rocks") 21 return dir.path(repo, "lib", "luarocks", "rocks")
22 else
23 assert(type(repo) == "table")
24 return repo.rocks_dir or dir.path(repo.root, "lib", "luarocks", "rocks")
25 end
22end 26end
23 27
24function deploy_bin_dir(repo) 28function deploy_bin_dir(repo)
25 assert(type(repo) == "string") 29 if type(repo) == "string" then
26 return dir.path(repo, "bin") 30 return dir.path(repo, "bin")
31 else
32 assert(type(repo) == "table")
33 return repo.bin_dir or dir.path(repo.root, "bin")
34 end
27end 35end
28 36
29function deploy_lua_dir(repo) 37function deploy_lua_dir(repo)
30 assert(type(repo) == "string") 38 if type(repo) == "string" then
31 return dir.path(repo, "share", "lua", "5.1") 39 return dir.path(repo, "share", "lua", "5.1")
40 else
41 assert(type(repo) == "table")
42 return repo.lua_dir or dir.path(repo.root, "share", "lua", "5.1")
43 end
32end 44end
33 45
34function deploy_lib_dir(repo) 46function deploy_lib_dir(repo)
35 assert(type(repo) == "string") 47 if type(repo) == "string" then
36 return dir.path(repo, "lib", "lua", "5.1") 48 return dir.path(repo, "lib", "lua", "5.1")
49 else
50 assert(type(repo) == "table")
51 return repo.lib_dir or dir.path(repo.root, "lib", "lua", "5.1")
52 end
37end 53end
38 54
39function manifest_file(repo) 55function manifest_file(repo)
40 assert(type(repo) == "string") 56 if type(repo) == "string" then
41 return dir.path(repo, "lib", "luarocks", "rocks", "manifest") 57 return dir.path(repo, "lib", "luarocks", "rocks", "manifest")
58 else
59 assert(type(repo) == "table")
60 return (repo.rocks_dir and dir.path(repo.rocks_dir, "manifest")) or dir.path(repo.root, "lib", "luarocks", "rocks", "manifest")
61 end
42end 62end
43 63
44--- Get the repository directory for all versions of a package. 64--- Get the repository directory for all versions of a package.
@@ -46,11 +66,10 @@ end
46-- @return string: The resulting path -- does not guarantee that 66-- @return string: The resulting path -- does not guarantee that
47-- @param rocks_dir string or nil: If given, specifies the local repository to use. 67-- @param rocks_dir string or nil: If given, specifies the local repository to use.
48-- the package (and by extension, the path) exists. 68-- the package (and by extension, the path) exists.
49function versions_dir(name, rocks_dir) 69function versions_dir(name, repo)
50 assert(type(name) == "string") 70 assert(type(name) == "string")
51 assert(not rocks_dir or type(rocks_dir) == "string") 71 repo = repo or cfg.root_dir
52 72 return dir.path(rocks_dir(repo), name)
53 return dir.path(rocks_dir or cfg.rocks_dir, name)
54end 73end
55 74
56--- Get the local installation directory (prefix) for a package. 75--- Get the local installation directory (prefix) for a package.
@@ -59,12 +78,11 @@ end
59-- @param rocks_dir string or nil: If given, specifies the local repository to use. 78-- @param rocks_dir string or nil: If given, specifies the local repository to use.
60-- @return string: The resulting path -- does not guarantee that 79-- @return string: The resulting path -- does not guarantee that
61-- the package (and by extension, the path) exists. 80-- the package (and by extension, the path) exists.
62function install_dir(name, version, rocks_dir) 81function install_dir(name, version, repo)
63 assert(type(name) == "string") 82 assert(type(name) == "string")
64 assert(type(version) == "string") 83 assert(type(version) == "string")
65 assert(not rocks_dir or type(rocks_dir) == "string") 84 repo = repo or cfg.root_dir
66 85 return dir.path(rocks_dir(repo), name, version)
67 return dir.path(rocks_dir or cfg.rocks_dir, name, version)
68end 86end
69 87
70--- Get the local filename of the rockspec of an installed rock. 88--- Get the local filename of the rockspec of an installed rock.
@@ -73,12 +91,11 @@ end
73-- @param rocks_dir string or nil: If given, specifies the local repository to use. 91-- @param rocks_dir string or nil: If given, specifies the local repository to use.
74-- @return string: The resulting path -- does not guarantee that 92-- @return string: The resulting path -- does not guarantee that
75-- the package (and by extension, the file) exists. 93-- the package (and by extension, the file) exists.
76function rockspec_file(name, version, rocks_dir) 94function rockspec_file(name, version, repo)
77 assert(type(name) == "string") 95 assert(type(name) == "string")
78 assert(type(version) == "string") 96 assert(type(version) == "string")
79 assert(not rocks_dir or type(rocks_dir) == "string") 97 repo = repo or cfg.root_dir
80 98 return dir.path(rocks_dir(repo), name, version, name.."-"..version..".rockspec")
81 return dir.path(rocks_dir or cfg.rocks_dir, name, version, name.."-"..version..".rockspec")
82end 99end
83 100
84--- Get the local filename of the rock_manifest file of an installed rock. 101--- Get the local filename of the rock_manifest file of an installed rock.
@@ -87,12 +104,11 @@ end
87-- @param rocks_dir string or nil: If given, specifies the local repository to use. 104-- @param rocks_dir string or nil: If given, specifies the local repository to use.
88-- @return string: The resulting path -- does not guarantee that 105-- @return string: The resulting path -- does not guarantee that
89-- the package (and by extension, the file) exists. 106-- the package (and by extension, the file) exists.
90function rock_manifest_file(name, version, rocks_dir) 107function rock_manifest_file(name, version, repo)
91 assert(type(name) == "string") 108 assert(type(name) == "string")
92 assert(type(version) == "string") 109 assert(type(version) == "string")
93 assert(not rocks_dir or type(rocks_dir) == "string") 110 repo = repo or cfg.root_dir
94 111 return dir.path(rocks_dir(repo), name, version, "rock_manifest")
95 return dir.path(rocks_dir or cfg.rocks_dir, name, version, "rock_manifest")
96end 112end
97 113
98--- Get the local installation directory for C libraries of a package. 114--- Get the local installation directory for C libraries of a package.
@@ -101,12 +117,11 @@ end
101-- @param rocks_dir string or nil: If given, specifies the local repository to use. 117-- @param rocks_dir string or nil: If given, specifies the local repository to use.
102-- @return string: The resulting path -- does not guarantee that 118-- @return string: The resulting path -- does not guarantee that
103-- the package (and by extension, the path) exists. 119-- the package (and by extension, the path) exists.
104function lib_dir(name, version, rocks_dir) 120function lib_dir(name, version, repo)
105 assert(type(name) == "string") 121 assert(type(name) == "string")
106 assert(type(version) == "string") 122 assert(type(version) == "string")
107 assert(not rocks_dir or type(rocks_dir) == "string") 123 repo = repo or cfg.root_dir
108 124 return dir.path(rocks_dir(repo), name, version, "lib")
109 return dir.path(rocks_dir or cfg.rocks_dir, name, version, "lib")
110end 125end
111 126
112--- Get the local installation directory for Lua modules of a package. 127--- Get the local installation directory for Lua modules of a package.
@@ -115,12 +130,11 @@ end
115-- @param rocks_dir string or nil: If given, specifies the local repository to use. 130-- @param rocks_dir string or nil: If given, specifies the local repository to use.
116-- @return string: The resulting path -- does not guarantee that 131-- @return string: The resulting path -- does not guarantee that
117-- the package (and by extension, the path) exists. 132-- the package (and by extension, the path) exists.
118function lua_dir(name, version, rocks_dir) 133function lua_dir(name, version, repo)
119 assert(type(name) == "string") 134 assert(type(name) == "string")
120 assert(type(version) == "string") 135 assert(type(version) == "string")
121 assert(not rocks_dir or type(rocks_dir) == "string") 136 repo = repo or cfg.root_dir
122 137 return dir.path(rocks_dir(repo), name, version, "lua")
123 return dir.path(rocks_dir or cfg.rocks_dir, name, version, "lua")
124end 138end
125 139
126--- Get the local installation directory for documentation of a package. 140--- Get the local installation directory for documentation of a package.
@@ -129,12 +143,11 @@ end
129-- @param rocks_dir string or nil: If given, specifies the local repository to use. 143-- @param rocks_dir string or nil: If given, specifies the local repository to use.
130-- @return string: The resulting path -- does not guarantee that 144-- @return string: The resulting path -- does not guarantee that
131-- the package (and by extension, the path) exists. 145-- the package (and by extension, the path) exists.
132function doc_dir(name, version, rocks_dir) 146function doc_dir(name, version, repo)
133 assert(type(name) == "string") 147 assert(type(name) == "string")
134 assert(type(version) == "string") 148 assert(type(version) == "string")
135 assert(not rocks_dir or type(rocks_dir) == "string") 149 repo = repo or cfg.root_dir
136 150 return dir.path(rocks_dir(repo), name, version, "doc")
137 return dir.path(rocks_dir or cfg.rocks_dir, name, version, "doc")
138end 151end
139 152
140--- Get the local installation directory for configuration files of a package. 153--- Get the local installation directory for configuration files of a package.
@@ -143,12 +156,11 @@ end
143-- @param rocks_dir string or nil: If given, specifies the local repository to use. 156-- @param rocks_dir string or nil: If given, specifies the local repository to use.
144-- @return string: The resulting path -- does not guarantee that 157-- @return string: The resulting path -- does not guarantee that
145-- the package (and by extension, the path) exists. 158-- the package (and by extension, the path) exists.
146function conf_dir(name, version, rocks_dir) 159function conf_dir(name, version, repo)
147 assert(type(name) == "string") 160 assert(type(name) == "string")
148 assert(type(version) == "string") 161 assert(type(version) == "string")
149 assert(not rocks_dir or type(rocks_dir) == "string") 162 repo = repo or cfg.root_dir
150 163 return dir.path(rocks_dir(repo), name, version, "conf")
151 return dir.path(rocks_dir or cfg.rocks_dir, name, version, "conf")
152end 164end
153 165
154--- Get the local installation directory for command-line scripts 166--- Get the local installation directory for command-line scripts
@@ -158,12 +170,11 @@ end
158-- @param rocks_dir string or nil: If given, specifies the local repository to use. 170-- @param rocks_dir string or nil: If given, specifies the local repository to use.
159-- @return string: The resulting path -- does not guarantee that 171-- @return string: The resulting path -- does not guarantee that
160-- the package (and by extension, the path) exists. 172-- the package (and by extension, the path) exists.
161function bin_dir(name, version, rocks_dir) 173function bin_dir(name, version, repo)
162 assert(type(name) == "string") 174 assert(type(name) == "string")
163 assert(type(version) == "string") 175 assert(type(version) == "string")
164 assert(not rocks_dir or type(rocks_dir) == "string") 176 repo = repo or cfg.root_dir
165 177 return dir.path(rocks_dir(repo), name, version, "bin")
166 return dir.path(rocks_dir or cfg.rocks_dir, name, version, "bin")
167end 178end
168 179
169--- Extract name, version and arch of a rock filename. 180--- Extract name, version and arch of a rock filename.