diff options
Diffstat (limited to 'src/luarocks/path.lua')
| -rw-r--r-- | src/luarocks/path.lua | 103 |
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) | |||
| 17 | end | 17 | end |
| 18 | 18 | ||
| 19 | function rocks_dir(repo) | 19 | function 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 | ||
| 22 | end | 26 | end |
| 23 | 27 | ||
| 24 | function deploy_bin_dir(repo) | 28 | function 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 | ||
| 27 | end | 35 | end |
| 28 | 36 | ||
| 29 | function deploy_lua_dir(repo) | 37 | function 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 | ||
| 32 | end | 44 | end |
| 33 | 45 | ||
| 34 | function deploy_lib_dir(repo) | 46 | function 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 | ||
| 37 | end | 53 | end |
| 38 | 54 | ||
| 39 | function manifest_file(repo) | 55 | function 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 | ||
| 42 | end | 62 | end |
| 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. |
| 49 | function versions_dir(name, rocks_dir) | 69 | function 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) | ||
| 54 | end | 73 | end |
| 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. |
| 62 | function install_dir(name, version, rocks_dir) | 81 | function 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) | ||
| 68 | end | 86 | end |
| 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. |
| 76 | function rockspec_file(name, version, rocks_dir) | 94 | function 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") | ||
| 82 | end | 99 | end |
| 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. |
| 90 | function rock_manifest_file(name, version, rocks_dir) | 107 | function 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") | ||
| 96 | end | 112 | end |
| 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. |
| 104 | function lib_dir(name, version, rocks_dir) | 120 | function 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") | ||
| 110 | end | 125 | end |
| 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. |
| 118 | function lua_dir(name, version, rocks_dir) | 133 | function 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") | ||
| 124 | end | 138 | end |
| 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. |
| 132 | function doc_dir(name, version, rocks_dir) | 146 | function 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") | ||
| 138 | end | 151 | end |
| 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. |
| 146 | function conf_dir(name, version, rocks_dir) | 159 | function 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") | ||
| 152 | end | 164 | end |
| 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. |
| 161 | function bin_dir(name, version, rocks_dir) | 173 | function 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") | ||
| 167 | end | 178 | end |
| 168 | 179 | ||
| 169 | --- Extract name, version and arch of a rock filename. | 180 | --- Extract name, version and arch of a rock filename. |
