diff options
author | V1K1NGbg <victor@ilchev.com> | 2024-08-15 19:11:58 +0300 |
---|---|---|
committer | V1K1NGbg <victor@ilchev.com> | 2024-08-15 19:11:58 +0300 |
commit | 61859a26e530969d5b5662dba075535a640cec09 (patch) | |
tree | 1e333a06b385b74802f3fc711d26ddb500f7a0f7 | |
parent | 753c99c3debec5f08734645b4f48dda7b113ce87 (diff) | |
download | luarocks-61859a26e530969d5b5662dba075535a640cec09.tar.gz luarocks-61859a26e530969d5b5662dba075535a640cec09.tar.bz2 luarocks-61859a26e530969d5b5662dba075535a640cec09.zip |
build
-rw-r--r-- | src/luarocks/build.tl | 10 | ||||
-rw-r--r-- | src/luarocks/build/builtin.lua | 183 | ||||
-rw-r--r-- | src/luarocks/build/builtin.tl | 15 | ||||
-rw-r--r-- | src/luarocks/build/cmake.lua | 51 | ||||
-rw-r--r-- | src/luarocks/build/cmake.tl | 6 | ||||
-rw-r--r-- | src/luarocks/build/command.lua | 22 | ||||
-rw-r--r-- | src/luarocks/build/command.tl | 18 | ||||
-rw-r--r-- | src/luarocks/build/make.tl | 30 | ||||
-rw-r--r-- | src/luarocks/build/originals/builtin-original.lua (renamed from src/luarocks/build/builtin-incomplete.lua) | 184 | ||||
-rw-r--r-- | src/luarocks/build/originals/cmake-original.lua | 78 | ||||
-rw-r--r-- | src/luarocks/build/originals/command-original.lua | 41 | ||||
-rw-r--r-- | src/luarocks/core/cfg.d.tl | 3 | ||||
-rw-r--r-- | src/luarocks/core/types/build.d.tl | 116 | ||||
-rw-r--r-- | src/luarocks/core/types/installs.d.tl | 26 | ||||
-rw-r--r-- | src/luarocks/fs.d.tl | 2 |
15 files changed, 467 insertions, 318 deletions
diff --git a/src/luarocks/build.tl b/src/luarocks/build.tl index 5494a84d..cbafb409 100644 --- a/src/luarocks/build.tl +++ b/src/luarocks/build.tl | |||
@@ -33,8 +33,8 @@ local type r = require("luarocks.core.types.rockspec") | |||
33 | local type Rockspec = r.Rockspec | 33 | local type Rockspec = r.Rockspec |
34 | 34 | ||
35 | local type i = require("luarocks.core.types.installs") | 35 | local type i = require("luarocks.core.types.installs") |
36 | local type Installs = i.Installs | 36 | local type InstallDirs = i.InstallDirs |
37 | local type Install = i.Install | 37 | local type InstallDir = i.InstallDir |
38 | 38 | ||
39 | local type t = require("luarocks.core.types.tree") | 39 | local type t = require("luarocks.core.types.tree") |
40 | local type Tree = t.Tree | 40 | local type Tree = t.Tree |
@@ -206,15 +206,15 @@ local function fetch_and_change_to_source_dir(rockspec: Rockspec, opts: Op_b): b | |||
206 | return true | 206 | return true |
207 | end | 207 | end |
208 | 208 | ||
209 | local function prepare_install_dirs(name: string, version: string): Installs, string | 209 | local function prepare_install_dirs(name: string, version: string): InstallDirs, string |
210 | local dirs = { | 210 | local dirs: InstallDirs = { |
211 | lua = { name = path.lua_dir(name, version), is_module_path = true, perms = "read" }, | 211 | lua = { name = path.lua_dir(name, version), is_module_path = true, perms = "read" }, |
212 | lib = { name = path.lib_dir(name, version), is_module_path = true, perms = "exec" }, | 212 | lib = { name = path.lib_dir(name, version), is_module_path = true, perms = "exec" }, |
213 | bin = { name = path.bin_dir(name, version), is_module_path = false, perms = "exec" }, | 213 | bin = { name = path.bin_dir(name, version), is_module_path = false, perms = "exec" }, |
214 | conf = { name = path.conf_dir(name, version), is_module_path = false, perms = "read" }, | 214 | conf = { name = path.conf_dir(name, version), is_module_path = false, perms = "read" }, |
215 | } | 215 | } |
216 | 216 | ||
217 | for _, d in pairs(dirs as {string: Install}) do | 217 | for _, d in pairs(dirs as {string: InstallDir}) do |
218 | local ok, err = fs.make_dir(d.name) | 218 | local ok, err = fs.make_dir(d.name) |
219 | if not ok then | 219 | if not ok then |
220 | return nil, err | 220 | return nil, err |
diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index 14d13eb4..3d00a176 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua | |||
@@ -1,13 +1,25 @@ | |||
1 | local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local io = _tl_compat and _tl_compat.io or io; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local os = _tl_compat and _tl_compat.os or os; local package = _tl_compat and _tl_compat.package or package; local pairs = _tl_compat and _tl_compat.pairs or pairs; local string = _tl_compat and _tl_compat.string or string; local table = _tl_compat and _tl_compat.table or table; local _tl_table_unpack = unpack or table.unpack | ||
1 | 2 | ||
2 | --- A builtin build system: back-end to provide a portable way of building C-based Lua modules. | ||
3 | local builtin = {} | 3 | local builtin = {} |
4 | 4 | ||
5 | -- This build driver checks LUA_INCDIR and LUA_LIBDIR on demand, | 5 | |
6 | -- so that pure-Lua rocks don't need to have development headers | 6 | |
7 | -- installed. | 7 | |
8 | |||
9 | |||
10 | |||
11 | local InstallDirs = i.InstallDirs | ||
12 | |||
13 | |||
14 | |||
15 | |||
16 | |||
17 | |||
18 | |||
19 | |||
20 | |||
8 | builtin.skip_lua_inc_lib_check = true | 21 | builtin.skip_lua_inc_lib_check = true |
9 | 22 | ||
10 | local unpack = unpack or table.unpack | ||
11 | local dir_sep = package.config:sub(1, 1) | 23 | local dir_sep = package.config:sub(1, 1) |
12 | 24 | ||
13 | local fs = require("luarocks.fs") | 25 | local fs = require("luarocks.fs") |
@@ -57,7 +69,7 @@ do | |||
57 | local copy_directories | 69 | local copy_directories |
58 | 70 | ||
59 | local prefix = "" | 71 | local prefix = "" |
60 | for _, parent in ipairs({"src", "lua", "lib"}) do | 72 | for _, parent in ipairs({ "src", "lua", "lib" }) do |
61 | if fs.is_dir(parent) then | 73 | if fs.is_dir(parent) then |
62 | fs.change_dir(parent) | 74 | fs.change_dir(parent) |
63 | prefix = parent .. dir_sep | 75 | prefix = parent .. dir_sep |
@@ -74,9 +86,9 @@ do | |||
74 | else | 86 | else |
75 | local cmod = file:match("(.*)%.c$") | 87 | local cmod = file:match("(.*)%.c$") |
76 | if cmod then | 88 | if cmod then |
77 | local modname = get_cmod_name(file) or path.path_to_module(file:gsub("%.c$", ".lua")) | 89 | local modname = get_cmod_name(file) or path.path_to_module((file:gsub("%.c$", ".lua"))) |
78 | modules[modname] = { | 90 | modules[modname] = { |
79 | sources = prefix..file, | 91 | sources = prefix .. file, |
80 | libraries = libs, | 92 | libraries = libs, |
81 | incdirs = incdirs, | 93 | incdirs = incdirs, |
82 | libdirs = libdirs, | 94 | libdirs = libdirs, |
@@ -90,8 +102,8 @@ do | |||
90 | fs.pop_dir() | 102 | fs.pop_dir() |
91 | end | 103 | end |
92 | 104 | ||
93 | local bindir = (fs.is_dir(dir.path("src", "bin")) and dir.path("src", "bin")) | 105 | local bindir = (fs.is_dir(dir.path("src", "bin")) and dir.path("src", "bin")) or |
94 | or (fs.is_dir("bin") and "bin") | 106 | (fs.is_dir("bin") and "bin") |
95 | if bindir then | 107 | if bindir then |
96 | install = { bin = {} } | 108 | install = { bin = {} } |
97 | for _, file in ipairs(fs.list_dir(bindir)) do | 109 | for _, file in ipairs(fs.list_dir(bindir)) do |
@@ -112,33 +124,34 @@ do | |||
112 | end | 124 | end |
113 | end | 125 | end |
114 | 126 | ||
115 | --- Run a command displaying its execution on standard output. | 127 | |
116 | -- @return boolean: true if command succeeds (status code 0), false | 128 | |
117 | -- otherwise. | 129 | |
118 | local function execute(...) | 130 | local function execute(...) |
119 | io.stdout:write(table.concat({...}, " ").."\n") | 131 | io.stdout:write(table.concat({ ... }, " ") .. "\n") |
120 | return fs.execute(...) | 132 | return fs.execute(...) |
121 | end | 133 | end |
122 | 134 | ||
123 | --- Driver function for the builtin build back-end. | 135 | |
124 | -- @param rockspec table: the loaded rockspec. | 136 | |
125 | -- @return boolean or (nil, string): true if no errors occurred, | 137 | |
126 | -- nil and an error message otherwise. | 138 | |
127 | function builtin.run(rockspec, no_install) | 139 | function builtin.run(rockspec, no_install) |
128 | assert(rockspec:type() == "rockspec") | 140 | local compile_object |
129 | local compile_object, compile_library, compile_static_library | 141 | local compile_library |
142 | local compile_static_library | ||
130 | 143 | ||
131 | local build = rockspec.build | 144 | local build = rockspec.build |
132 | local variables = rockspec.variables | 145 | local variables = rockspec.variables |
133 | local checked_lua_h = false | 146 | local checked_lua_h = false |
134 | 147 | ||
135 | for _, var in ipairs{ "CC", "CFLAGS", "LDFLAGS" } do | 148 | for _, var in ipairs({ "CC", "CFLAGS", "LDFLAGS" }) do |
136 | variables[var] = variables[var] or os.getenv(var) or "" | 149 | variables[var] = variables[var] or os.getenv(var) or "" |
137 | end | 150 | end |
138 | 151 | ||
139 | local function add_flags(extras, flag, flags) | 152 | local function add_flags(extras, flag, flags) |
140 | if flags then | 153 | if flags then |
141 | if type(flags) ~= "table" then | 154 | if not (type(flags) == "table") then |
142 | flags = { tostring(flags) } | 155 | flags = { tostring(flags) } |
143 | end | 156 | end |
144 | util.variable_substitutions(flags, variables) | 157 | util.variable_substitutions(flags, variables) |
@@ -153,43 +166,43 @@ function builtin.run(rockspec, no_install) | |||
153 | local extras = {} | 166 | local extras = {} |
154 | add_flags(extras, "-D%s", defines) | 167 | add_flags(extras, "-D%s", defines) |
155 | add_flags(extras, "-I%s", incdirs) | 168 | add_flags(extras, "-I%s", incdirs) |
156 | return execute(variables.CC.." "..variables.CFLAGS, "-c", "-o", object, "-I"..variables.LUA_INCDIR, source, unpack(extras)) | 169 | return execute(variables.CC .. " " .. variables.CFLAGS, "-c", "-o", object, "-I" .. variables.LUA_INCDIR, source, _tl_table_unpack(extras)) |
157 | end | 170 | end |
158 | compile_library = function(library, objects, libraries, libdirs, name) | 171 | compile_library = function(library, objects, libraries, libdirs, name) |
159 | local extras = { unpack(objects) } | 172 | local extras = { _tl_table_unpack(objects) } |
160 | add_flags(extras, "-L%s", libdirs) | 173 | add_flags(extras, "-L%s", libdirs) |
161 | add_flags(extras, "-l%s", libraries) | 174 | add_flags(extras, "-l%s", libraries) |
162 | extras[#extras+1] = dir.path(variables.LUA_LIBDIR, variables.LUALIB) | 175 | extras[#extras + 1] = dir.path(variables.LUA_LIBDIR, variables.LUALIB) |
163 | 176 | ||
164 | if variables.CC == "clang" or variables.CC == "clang-cl" then | 177 | if variables.CC == "clang" or variables.CC == "clang-cl" then |
165 | local exported_name = name:gsub("%.", "_") | 178 | local exported_name = name:gsub("%.", "_") |
166 | exported_name = exported_name:match('^[^%-]+%-(.+)$') or exported_name | 179 | exported_name = exported_name:match('^[^%-]+%-(.+)$') or exported_name |
167 | extras[#extras+1] = string.format("-Wl,-export:luaopen_%s", exported_name) | 180 | extras[#extras + 1] = string.format("-Wl,-export:luaopen_%s", exported_name) |
168 | else | 181 | else |
169 | extras[#extras+1] = "-l" .. (variables.MSVCRT or "m") | 182 | extras[#extras + 1] = "-l" .. (variables.MSVCRT or "m") |
170 | end | 183 | end |
171 | 184 | ||
172 | local ok = execute(variables.LD.." "..variables.LDFLAGS.." "..variables.LIBFLAG, "-o", library, unpack(extras)) | 185 | local ok = execute(variables.LD .. " " .. variables.LDFLAGS .. " " .. variables.LIBFLAG, "-o", library, _tl_table_unpack(extras)) |
173 | return ok | ||
174 | end | ||
175 | --[[ TODO disable static libs until we fix the conflict in the manifest, which will take extending the manifest format. | ||
176 | compile_static_library = function(library, objects, libraries, libdirs, name) | ||
177 | local ok = execute(variables.AR, "rc", library, unpack(objects)) | ||
178 | if ok then | ||
179 | ok = execute(variables.RANLIB, library) | ||
180 | end | ||
181 | return ok | 186 | return ok |
182 | end | 187 | end |
183 | ]] | 188 | |
189 | |||
190 | |||
191 | |||
192 | |||
193 | |||
194 | |||
195 | |||
196 | |||
184 | elseif cfg.is_platform("win32") then | 197 | elseif cfg.is_platform("win32") then |
185 | compile_object = function(object, source, defines, incdirs) | 198 | compile_object = function(object, source, defines, incdirs) |
186 | local extras = {} | 199 | local extras = {} |
187 | add_flags(extras, "-D%s", defines) | 200 | add_flags(extras, "-D%s", defines) |
188 | add_flags(extras, "-I%s", incdirs) | 201 | add_flags(extras, "-I%s", incdirs) |
189 | return execute(variables.CC.." "..variables.CFLAGS, "-c", "-Fo"..object, "-I"..variables.LUA_INCDIR, source, unpack(extras)) | 202 | return execute(variables.CC .. " " .. variables.CFLAGS, "-c", "-Fo" .. object, "-I" .. variables.LUA_INCDIR, source, _tl_table_unpack(extras)) |
190 | end | 203 | end |
191 | compile_library = function(library, objects, libraries, libdirs, name) | 204 | compile_library = function(library, objects, libraries, libdirs, name) |
192 | local extras = { unpack(objects) } | 205 | local extras = { _tl_table_unpack(objects) } |
193 | add_flags(extras, "-libpath:%s", libdirs) | 206 | add_flags(extras, "-libpath:%s", libdirs) |
194 | add_flags(extras, "%s.lib", libraries) | 207 | add_flags(extras, "%s.lib", libraries) |
195 | local basename = dir.base_name(library):gsub(".[^.]*$", "") | 208 | local basename = dir.base_name(library):gsub(".[^.]*$", "") |
@@ -198,49 +211,49 @@ function builtin.run(rockspec, no_install) | |||
198 | local exported_name = name:gsub("%.", "_") | 211 | local exported_name = name:gsub("%.", "_") |
199 | exported_name = exported_name:match('^[^%-]+%-(.+)$') or exported_name | 212 | exported_name = exported_name:match('^[^%-]+%-(.+)$') or exported_name |
200 | def:write("EXPORTS\n") | 213 | def:write("EXPORTS\n") |
201 | def:write("luaopen_"..exported_name.."\n") | 214 | def:write("luaopen_" .. exported_name .. "\n") |
202 | def:close() | 215 | def:close() |
203 | local ok = execute(variables.LD, "-dll", "-def:"..deffile, "-out:"..library, dir.path(variables.LUA_LIBDIR, variables.LUALIB), unpack(extras)) | 216 | local ok = execute(variables.LD, "-dll", "-def:" .. deffile, "-out:" .. library, dir.path(variables.LUA_LIBDIR, variables.LUALIB), _tl_table_unpack(extras)) |
204 | local basedir = "" | 217 | local basedir = "" |
205 | if name:find("%.") ~= nil then | 218 | if name:find("%.") ~= nil then |
206 | basedir = name:gsub("%.%w+$", "\\") | 219 | basedir = name:gsub("%.%w+$", "\\") |
207 | basedir = basedir:gsub("%.", "\\") | 220 | basedir = basedir:gsub("%.", "\\") |
208 | end | 221 | end |
209 | local manifestfile = basedir .. basename..".dll.manifest" | 222 | local manifestfile = basedir .. basename .. ".dll.manifest" |
210 | 223 | ||
211 | if ok and fs.exists(manifestfile) then | 224 | if ok and fs.exists(manifestfile) then |
212 | ok = execute(variables.MT, "-manifest", manifestfile, "-outputresource:"..basedir..basename..".dll;2") | 225 | ok = execute(variables.MT, "-manifest", manifestfile, "-outputresource:" .. basedir .. basename .. ".dll;2") |
213 | end | 226 | end |
214 | return ok | 227 | return ok |
215 | end | 228 | end |
216 | --[[ TODO disable static libs until we fix the conflict in the manifest, which will take extending the manifest format. | 229 | |
217 | compile_static_library = function(library, objects, libraries, libdirs, name) | 230 | |
218 | local ok = execute(variables.AR, "-out:"..library, unpack(objects)) | 231 | |
219 | return ok | 232 | |
220 | end | 233 | |
221 | ]] | 234 | |
222 | else | 235 | else |
223 | compile_object = function(object, source, defines, incdirs) | 236 | compile_object = function(object, source, defines, incdirs) |
224 | local extras = {} | 237 | local extras = {} |
225 | add_flags(extras, "-D%s", defines) | 238 | add_flags(extras, "-D%s", defines) |
226 | add_flags(extras, "-I%s", incdirs) | 239 | add_flags(extras, "-I%s", incdirs) |
227 | return execute(variables.CC.." "..variables.CFLAGS, "-I"..variables.LUA_INCDIR, "-c", source, "-o", object, unpack(extras)) | 240 | return execute(variables.CC .. " " .. variables.CFLAGS, "-I" .. variables.LUA_INCDIR, "-c", source, "-o", object, _tl_table_unpack(extras)) |
228 | end | 241 | end |
229 | compile_library = function (library, objects, libraries, libdirs) | 242 | compile_library = function(library, objects, libraries, libdirs) |
230 | local extras = { unpack(objects) } | 243 | local extras = { _tl_table_unpack(objects) } |
231 | add_flags(extras, "-L%s", libdirs) | 244 | add_flags(extras, "-L%s", libdirs) |
232 | if cfg.gcc_rpath then | 245 | if cfg.gcc_rpath then |
233 | add_flags(extras, "-Wl,-rpath,%s", libdirs) | 246 | add_flags(extras, "-Wl,-rpath,%s", libdirs) |
234 | end | 247 | end |
235 | add_flags(extras, "-l%s", libraries) | 248 | add_flags(extras, "-l%s", libraries) |
236 | if cfg.link_lua_explicitly then | 249 | if cfg.link_lua_explicitly then |
237 | extras[#extras+1] = "-L"..variables.LUA_LIBDIR | 250 | extras[#extras + 1] = "-L" .. variables.LUA_LIBDIR |
238 | extras[#extras+1] = "-llua" | 251 | extras[#extras + 1] = "-llua" |
239 | end | 252 | end |
240 | return execute(variables.LD.." "..variables.LDFLAGS.." "..variables.LIBFLAG, "-o", library, unpack(extras)) | 253 | return execute(variables.LD .. " " .. variables.LDFLAGS .. " " .. variables.LIBFLAG, "-o", library, _tl_table_unpack(extras)) |
241 | end | 254 | end |
242 | compile_static_library = function(library, objects, libraries, libdirs, name) -- luacheck: ignore 211 | 255 | compile_static_library = function(library, objects, libraries, libdirs, name) |
243 | local ok = execute(variables.AR, "rc", library, unpack(objects)) | 256 | local ok = execute(variables.AR, "rc", library, _tl_table_unpack(objects)) |
244 | if ok then | 257 | if ok then |
245 | ok = execute(variables.RANLIB, library) | 258 | ok = execute(variables.RANLIB, library) |
246 | end | 259 | end |
@@ -285,15 +298,15 @@ function builtin.run(rockspec, no_install) | |||
285 | if ext == "lua" then | 298 | if ext == "lua" then |
286 | local filename = dir.base_name(info) | 299 | local filename = dir.base_name(info) |
287 | if filename == "init.lua" and not name:match("%.init$") then | 300 | if filename == "init.lua" and not name:match("%.init$") then |
288 | moddir = path.module_to_path(name..".init") | 301 | moddir = path.module_to_path(name .. ".init") |
289 | else | 302 | else |
290 | local basename = name:match("([^.]+)$") | 303 | local basename = name:match("([^.]+)$") |
291 | filename = basename..".lua" | 304 | filename = basename .. ".lua" |
292 | end | 305 | end |
293 | local dest = dir.path(luadir, moddir, filename) | 306 | local dest = dir.path(luadir, moddir, filename) |
294 | lua_modules[info] = dest | 307 | lua_modules[info] = dest |
295 | else | 308 | else |
296 | info = {info} | 309 | info = { info } |
297 | end | 310 | end |
298 | end | 311 | end |
299 | if type(info) == "table" then | 312 | if type(info) == "table" then |
@@ -314,21 +327,21 @@ function builtin.run(rockspec, no_install) | |||
314 | local objects = {} | 327 | local objects = {} |
315 | local sources = info.sources | 328 | local sources = info.sources |
316 | if info[1] then sources = info end | 329 | if info[1] then sources = info end |
317 | if type(sources) == "string" then sources = {sources} end | 330 | if type(sources) == "string" then sources = { sources } end |
318 | if type(sources) ~= "table" then | 331 | if not (type(sources) == "table") then |
319 | return nil, "error in rockspec: module '" .. name .. "' entry has no 'sources' list" | 332 | return nil, "error in rockspec: module '" .. name .. "' entry has no 'sources' list" |
320 | end | 333 | end |
321 | for _, source in ipairs(sources) do | 334 | for _, source in ipairs(sources) do |
322 | if type(source) ~= "string" then | 335 | if not (type(source) == "string") then |
323 | return nil, "error in rockspec: module '" .. name .. "' does not specify source correctly." | 336 | return nil, "error in rockspec: module '" .. name .. "' does not specify source correctly." |
324 | end | 337 | end |
325 | local object = source:gsub("%.[^.]*$", "."..cfg.obj_extension) | 338 | local object = source:gsub("%.[^.]*$", "." .. cfg.obj_extension) |
326 | if not object then | 339 | if not object then |
327 | object = source.."."..cfg.obj_extension | 340 | object = source .. "." .. cfg.obj_extension |
328 | end | 341 | end |
329 | ok = compile_object(object, source, info.defines, info.incdirs or autoincdirs) | 342 | ok = compile_object(object, source, info.defines, info.incdirs or autoincdirs) |
330 | if not ok then | 343 | if not ok then |
331 | return nil, "Failed compiling object "..object | 344 | return nil, "Failed compiling object " .. object |
332 | end | 345 | end |
333 | table.insert(objects, object) | 346 | table.insert(objects, object) |
334 | end | 347 | end |
@@ -338,7 +351,7 @@ function builtin.run(rockspec, no_install) | |||
338 | util.schedule_function(fs.delete, compile_temp_dir) | 351 | util.schedule_function(fs.delete, compile_temp_dir) |
339 | end | 352 | end |
340 | 353 | ||
341 | local module_name = name:match("([^.]*)$").."."..util.matchquote(cfg.lib_extension) | 354 | local module_name = name:match("([^.]*)$") .. "." .. util.matchquote(cfg.lib_extension) |
342 | if moddir ~= "" then | 355 | if moddir ~= "" then |
343 | module_name = dir.path(moddir, module_name) | 356 | module_name = dir.path(moddir, module_name) |
344 | end | 357 | end |
@@ -350,46 +363,46 @@ function builtin.run(rockspec, no_install) | |||
350 | lib_modules[build_name] = dir.path(libdir, module_name) | 363 | lib_modules[build_name] = dir.path(libdir, module_name) |
351 | ok = compile_library(build_name, objects, info.libraries, info.libdirs or autolibdirs, name) | 364 | ok = compile_library(build_name, objects, info.libraries, info.libdirs or autolibdirs, name) |
352 | if not ok then | 365 | if not ok then |
353 | return nil, "Failed compiling module "..module_name | 366 | return nil, "Failed compiling module " .. module_name |
354 | end | 367 | end |
355 | 368 | ||
356 | -- for backwards compatibility, try keeping a copy of the module | 369 | |
357 | -- in the old location (luasec-1.3.2-1 rockspec breaks otherwise) | 370 | |
358 | if cached_make_dir(dir.dir_name(module_name)) then | 371 | if cached_make_dir(dir.dir_name(module_name)) then |
359 | fs.copy(build_name, module_name) | 372 | fs.copy(build_name, module_name) |
360 | end | 373 | end |
361 | 374 | ||
362 | --[[ TODO disable static libs until we fix the conflict in the manifest, which will take extending the manifest format. | 375 | |
363 | module_name = name:match("([^.]*)$").."."..util.matchquote(cfg.static_lib_extension) | 376 | |
364 | if moddir ~= "" then | 377 | |
365 | module_name = dir.path(moddir, module_name) | 378 | |
366 | end | 379 | |
367 | lib_modules[module_name] = dir.path(libdir, module_name) | 380 | |
368 | ok = compile_static_library(module_name, objects, info.libraries, info.libdirs, name) | 381 | |
369 | if not ok then | 382 | |
370 | return nil, "Failed compiling static library "..module_name | 383 | |
371 | end | 384 | |
372 | ]] | 385 | |
373 | end | 386 | end |
374 | end | 387 | end |
375 | if not no_install then | 388 | if not no_install then |
376 | for _, mods in ipairs({{ tbl = lua_modules, perms = "read" }, { tbl = lib_modules, perms = "exec" }}) do | 389 | for _, mods in ipairs({ { tbl = lua_modules, perms = "read" }, { tbl = lib_modules, perms = "exec" } }) do |
377 | for name, dest in pairs(mods.tbl) do | 390 | for name, dest in pairs(mods.tbl) do |
378 | cached_make_dir(dir.dir_name(dest)) | 391 | cached_make_dir(dir.dir_name(dest)) |
379 | ok, err = fs.copy(name, dest, mods.perms) | 392 | ok, err = fs.copy(name, dest, mods.perms) |
380 | if not ok then | 393 | if not ok then |
381 | return nil, "Failed installing "..name.." in "..dest..": "..err | 394 | return nil, "Failed installing " .. name .. " in " .. dest .. ": " .. err |
382 | end | 395 | end |
383 | end | 396 | end |
384 | end | 397 | end |
385 | if fs.is_dir("lua") then | 398 | if fs.is_dir("lua") then |
386 | ok, err = fs.copy_contents("lua", luadir) | 399 | ok, err = fs.copy_contents("lua", luadir) |
387 | if not ok then | 400 | if not ok then |
388 | return nil, "Failed copying contents of 'lua' directory: "..err | 401 | return nil, "Failed copying contents of 'lua' directory: " .. err |
389 | end | 402 | end |
390 | end | 403 | end |
391 | end | 404 | end |
392 | return true | 405 | return true |
393 | end | 406 | end |
394 | 407 | ||
395 | return builtin \ No newline at end of file | 408 | return builtin |
diff --git a/src/luarocks/build/builtin.tl b/src/luarocks/build/builtin.tl index 2ab688dc..d052edf6 100644 --- a/src/luarocks/build/builtin.tl +++ b/src/luarocks/build/builtin.tl | |||
@@ -8,10 +8,11 @@ local type r = require("luarocks.core.types.rockspec") | |||
8 | local type Rockspec = r.Rockspec | 8 | local type Rockspec = r.Rockspec |
9 | 9 | ||
10 | local type i = require("luarocks.core.types.installs") | 10 | local type i = require("luarocks.core.types.installs") |
11 | local type Installs = i.Installs | 11 | local type InstallDirs = i.InstallDirs |
12 | 12 | ||
13 | local type b = require("luarocks.core.types.build") | 13 | local type b = require("luarocks.core.types.build") |
14 | local type BuiltinBuild = b.BuiltinBuild | 14 | local type BuiltinBuild = b.BuiltinBuild |
15 | local type Build = b.Build | ||
15 | local type Module = BuiltinBuild.Module | 16 | local type Module = BuiltinBuild.Module |
16 | 17 | ||
17 | -- This build driver checks LUA_INCDIR and LUA_LIBDIR on demand, | 18 | -- This build driver checks LUA_INCDIR and LUA_LIBDIR on demand, |
@@ -54,7 +55,7 @@ do | |||
54 | return (data:match("int%s+luaopen_([a-zA-Z0-9_]+)")) | 55 | return (data:match("int%s+luaopen_([a-zA-Z0-9_]+)")) |
55 | end | 56 | end |
56 | 57 | ||
57 | local skiplist = { | 58 | local skiplist: {string: boolean} = { |
58 | ["spec"] = true, | 59 | ["spec"] = true, |
59 | [".luarocks"] = true, | 60 | [".luarocks"] = true, |
60 | ["lua_modules"] = true, | 61 | ["lua_modules"] = true, |
@@ -62,9 +63,9 @@ do | |||
62 | ["tests.lua"] = true, | 63 | ["tests.lua"] = true, |
63 | } | 64 | } |
64 | 65 | ||
65 | function builtin.autodetect_modules(libs: {string}, incdirs: {string}, libdirs: {string}): {string : string | Module}, Installs, {string} | 66 | function builtin.autodetect_modules(libs: {string}, incdirs: {string}, libdirs: {string}): {string : string | Module}, BuiltinBuild.Install, {string} |
66 | local modules: {string: (string | Module)} = {} | 67 | local modules: {string: (string | Module)} = {} |
67 | local install: Installs | 68 | local install: BuiltinBuild.Install |
68 | local copy_directories: {string} | 69 | local copy_directories: {string} |
69 | 70 | ||
70 | local prefix = "" | 71 | local prefix = "" |
@@ -78,14 +79,14 @@ do | |||
78 | 79 | ||
79 | for _, file in ipairs(fs.find()) do | 80 | for _, file in ipairs(fs.find()) do |
80 | local base = file:match("^([^\\/]*)") | 81 | local base = file:match("^([^\\/]*)") |
81 | if not (skiplist as {string: boolean})[base] then | 82 | if not skiplist[base] then |
82 | local luamod = file:match("(.*)%.lua$") | 83 | local luamod = file:match("(.*)%.lua$") |
83 | if luamod then | 84 | if luamod then |
84 | modules[path.path_to_module(file)] = prefix .. file | 85 | modules[path.path_to_module(file)] = prefix .. file |
85 | else | 86 | else |
86 | local cmod = file:match("(.*)%.c$") | 87 | local cmod = file:match("(.*)%.c$") |
87 | if cmod then | 88 | if cmod then |
88 | local modname = get_cmod_name(file) or path.path_to_module((file:gsub("%.c$", ".lua"))) --! | 89 | local modname = get_cmod_name(file) or path.path_to_module((file:gsub("%.c$", ".lua"))) |
89 | modules[modname] = { | 90 | modules[modname] = { |
90 | sources = prefix..file, | 91 | sources = prefix..file, |
91 | libraries = libs, | 92 | libraries = libs, |
@@ -270,7 +271,7 @@ function builtin.run(rockspec: Rockspec, no_install: boolean): boolean, string, | |||
270 | 271 | ||
271 | if not build.modules then | 272 | if not build.modules then |
272 | if rockspec:format_is_at_least("3.0") then | 273 | if rockspec:format_is_at_least("3.0") then |
273 | local install, copy_directories: Installs, {string} | 274 | local install, copy_directories: Build.Install, {string} |
274 | build.modules, install, copy_directories = builtin.autodetect_modules(autolibs, autoincdirs, autolibdirs) | 275 | build.modules, install, copy_directories = builtin.autodetect_modules(autolibs, autoincdirs, autolibdirs) |
275 | build.install = build.install or install | 276 | build.install = build.install or install |
276 | build.copy_directories = build.copy_directories or copy_directories | 277 | build.copy_directories = build.copy_directories or copy_directories |
diff --git a/src/luarocks/build/cmake.lua b/src/luarocks/build/cmake.lua index b7a4786e..ea245444 100644 --- a/src/luarocks/build/cmake.lua +++ b/src/luarocks/build/cmake.lua | |||
@@ -1,24 +1,30 @@ | |||
1 | local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local assert = _tl_compat and _tl_compat.assert or assert; local io = _tl_compat and _tl_compat.io or io; local os = _tl_compat and _tl_compat.os or os; local pairs = _tl_compat and _tl_compat.pairs or pairs | ||
1 | 2 | ||
2 | --- Build back-end for CMake-based modules. | ||
3 | local cmake = {} | 3 | local cmake = {} |
4 | 4 | ||
5 | |||
5 | local fs = require("luarocks.fs") | 6 | local fs = require("luarocks.fs") |
6 | local util = require("luarocks.util") | 7 | local util = require("luarocks.util") |
7 | local cfg = require("luarocks.core.cfg") | 8 | local cfg = require("luarocks.core.cfg") |
8 | 9 | ||
9 | --- Driver function for the "cmake" build back-end. | 10 | |
10 | -- @param rockspec table: the loaded rockspec. | 11 | |
11 | -- @return boolean or (nil, string): true if no errors occurred, | 12 | |
12 | -- nil and an error message otherwise. | 13 | |
14 | |||
15 | |||
16 | |||
17 | |||
18 | |||
19 | |||
13 | function cmake.run(rockspec, no_install) | 20 | function cmake.run(rockspec, no_install) |
14 | assert(rockspec:type() == "rockspec") | ||
15 | local build = rockspec.build | 21 | local build = rockspec.build |
16 | local variables = build.variables or {} | 22 | local variables = build.variables or {} |
17 | 23 | ||
18 | -- Pass Env variables | 24 | |
19 | variables.CMAKE_MODULE_PATH=os.getenv("CMAKE_MODULE_PATH") | 25 | variables.CMAKE_MODULE_PATH = os.getenv("CMAKE_MODULE_PATH") |
20 | variables.CMAKE_LIBRARY_PATH=os.getenv("CMAKE_LIBRARY_PATH") | 26 | variables.CMAKE_LIBRARY_PATH = os.getenv("CMAKE_LIBRARY_PATH") |
21 | variables.CMAKE_INCLUDE_PATH=os.getenv("CMAKE_INCLUDE_PATH") | 27 | variables.CMAKE_INCLUDE_PATH = os.getenv("CMAKE_INCLUDE_PATH") |
22 | 28 | ||
23 | util.variable_substitutions(variables, rockspec.variables) | 29 | util.variable_substitutions(variables, rockspec.variables) |
24 | 30 | ||
@@ -27,34 +33,35 @@ function cmake.run(rockspec, no_install) | |||
27 | return nil, err_msg | 33 | return nil, err_msg |
28 | end | 34 | end |
29 | 35 | ||
30 | -- If inline cmake is present create CMakeLists.txt from it. | 36 | |
31 | if type(build.cmake) == "string" then | 37 | local build_cmake = build.cmake |
32 | local cmake_handler = assert(io.open(fs.current_dir().."/CMakeLists.txt", "w")) | 38 | if type(build_cmake) == "string" then |
39 | local cmake_handler = assert((io.open(fs.current_dir() .. "/CMakeLists.txt", "w"))) | ||
33 | cmake_handler:write(build.cmake) | 40 | cmake_handler:write(build.cmake) |
34 | cmake_handler:close() | 41 | cmake_handler:close() |
35 | end | 42 | end |
36 | 43 | ||
37 | -- Execute cmake with variables. | 44 | |
38 | local args = "" | 45 | local args = "" |
39 | 46 | ||
40 | -- Try to pick the best generator. With msvc and x64, CMake does not select it by default so we need to be explicit. | 47 | |
41 | if cfg.cmake_generator then | 48 | if cfg.cmake_generator then |
42 | args = args .. ' -G"'..cfg.cmake_generator.. '"' | 49 | args = args .. ' -G"' .. cfg.cmake_generator .. '"' |
43 | elseif cfg.is_platform("windows") and cfg.target_cpu:match("x86_64$") then | 50 | elseif cfg.is_platform("windows") and cfg.target_cpu:match("x86_64$") then |
44 | args = args .. " -DCMAKE_GENERATOR_PLATFORM=x64" | 51 | args = args .. " -DCMAKE_GENERATOR_PLATFORM=x64" |
45 | end | 52 | end |
46 | 53 | ||
47 | for k,v in pairs(variables) do | 54 | for k, v in pairs(variables) do |
48 | args = args .. ' -D' ..k.. '="' ..tostring(v).. '"' | 55 | args = args .. ' -D' .. k .. '="' .. tostring(v) .. '"' |
49 | end | 56 | end |
50 | 57 | ||
51 | if not fs.execute_string(rockspec.variables.CMAKE.." -H. -Bbuild.luarocks "..args) then | 58 | if not fs.execute_string(rockspec.variables.CMAKE .. " -H. -Bbuild.luarocks " .. args) then |
52 | return nil, "Failed cmake." | 59 | return nil, "Failed cmake." |
53 | end | 60 | end |
54 | 61 | ||
55 | local do_build, do_install | 62 | local do_build, do_install |
56 | if rockspec:format_is_at_least("3.0") then | 63 | if rockspec:format_is_at_least("3.0") then |
57 | do_build = (build.build_pass == nil) and true or build.build_pass | 64 | do_build = (build.build_pass == nil) and true or build.build_pass |
58 | do_install = (build.install_pass == nil) and true or build.install_pass | 65 | do_install = (build.install_pass == nil) and true or build.install_pass |
59 | else | 66 | else |
60 | do_build = true | 67 | do_build = true |
@@ -62,12 +69,12 @@ function cmake.run(rockspec, no_install) | |||
62 | end | 69 | end |
63 | 70 | ||
64 | if do_build then | 71 | if do_build then |
65 | if not fs.execute_string(rockspec.variables.CMAKE.." --build build.luarocks --config Release") then | 72 | if not fs.execute_string(rockspec.variables.CMAKE .. " --build build.luarocks --config Release") then |
66 | return nil, "Failed building." | 73 | return nil, "Failed building." |
67 | end | 74 | end |
68 | end | 75 | end |
69 | if do_install and not no_install then | 76 | if do_install and not no_install then |
70 | if not fs.execute_string(rockspec.variables.CMAKE.." --build build.luarocks --target install --config Release") then | 77 | if not fs.execute_string(rockspec.variables.CMAKE .. " --build build.luarocks --target install --config Release") then |
71 | return nil, "Failed installing." | 78 | return nil, "Failed installing." |
72 | end | 79 | end |
73 | end | 80 | end |
diff --git a/src/luarocks/build/cmake.tl b/src/luarocks/build/cmake.tl index b0307b08..1c00797f 100644 --- a/src/luarocks/build/cmake.tl +++ b/src/luarocks/build/cmake.tl | |||
@@ -1,6 +1,7 @@ | |||
1 | 1 | ||
2 | --- Build back-end for CMake-based modules. | 2 | --- Build back-end for CMake-based modules. |
3 | local cmake = {} | 3 | local record cmake |
4 | end | ||
4 | 5 | ||
5 | local fs = require("luarocks.fs") | 6 | local fs = require("luarocks.fs") |
6 | local util = require("luarocks.util") | 7 | local util = require("luarocks.util") |
@@ -9,9 +10,6 @@ local cfg = require("luarocks.core.cfg") | |||
9 | local type r = require("luarocks.core.types.rockspec") | 10 | local type r = require("luarocks.core.types.rockspec") |
10 | local type Rockspec = r.Rockspec | 11 | local type Rockspec = r.Rockspec |
11 | 12 | ||
12 | local type i = require("luarocks.core.types.installs") | ||
13 | local type Installs = i.Installs | ||
14 | |||
15 | local type b = require("luarocks.core.types.build") | 13 | local type b = require("luarocks.core.types.build") |
16 | local type CMakeBuild = b.CMakeBuild | 14 | local type CMakeBuild = b.CMakeBuild |
17 | 15 | ||
diff --git a/src/luarocks/build/command.lua b/src/luarocks/build/command.lua index b0c4aa79..181bc56b 100644 --- a/src/luarocks/build/command.lua +++ b/src/luarocks/build/command.lua | |||
@@ -1,17 +1,23 @@ | |||
1 | 1 | ||
2 | --- Build back-end for raw listing of commands in rockspec files. | 2 | |
3 | local command = {} | 3 | local command = {} |
4 | 4 | ||
5 | |||
5 | local fs = require("luarocks.fs") | 6 | local fs = require("luarocks.fs") |
6 | local util = require("luarocks.util") | 7 | local util = require("luarocks.util") |
7 | local cfg = require("luarocks.core.cfg") | 8 | local cfg = require("luarocks.core.cfg") |
8 | 9 | ||
9 | --- Driver function for the "command" build back-end. | 10 | |
10 | -- @param rockspec table: the loaded rockspec. | 11 | |
11 | -- @return boolean or (nil, string): true if no errors occurred, | 12 | |
12 | -- nil and an error message otherwise. | 13 | |
14 | |||
15 | |||
16 | |||
17 | |||
18 | |||
19 | |||
13 | function command.run(rockspec, not_install) | 20 | function command.run(rockspec, not_install) |
14 | assert(rockspec:type() == "rockspec") | ||
15 | 21 | ||
16 | local build = rockspec.build | 22 | local build = rockspec.build |
17 | 23 | ||
@@ -19,8 +25,8 @@ function command.run(rockspec, not_install) | |||
19 | 25 | ||
20 | local env = { | 26 | local env = { |
21 | CC = cfg.variables.CC, | 27 | CC = cfg.variables.CC, |
22 | --LD = cfg.variables.LD, | 28 | |
23 | --CFLAGS = cfg.variables.CFLAGS, | 29 | |
24 | } | 30 | } |
25 | 31 | ||
26 | if build.build_command then | 32 | if build.build_command then |
diff --git a/src/luarocks/build/command.tl b/src/luarocks/build/command.tl index b0c4aa79..c2739987 100644 --- a/src/luarocks/build/command.tl +++ b/src/luarocks/build/command.tl | |||
@@ -1,23 +1,29 @@ | |||
1 | 1 | ||
2 | --- Build back-end for raw listing of commands in rockspec files. | 2 | --- Build back-end for raw listing of commands in rockspec files. |
3 | local command = {} | 3 | local record command |
4 | end | ||
4 | 5 | ||
5 | local fs = require("luarocks.fs") | 6 | local fs = require("luarocks.fs") |
6 | local util = require("luarocks.util") | 7 | local util = require("luarocks.util") |
7 | local cfg = require("luarocks.core.cfg") | 8 | local cfg = require("luarocks.core.cfg") |
8 | 9 | ||
10 | local type r = require("luarocks.core.types.rockspec") | ||
11 | local type Rockspec = r.Rockspec | ||
12 | |||
13 | local type b = require("luarocks.core.types.build") | ||
14 | local type CommandBuild = b.CommandBuild | ||
15 | |||
9 | --- Driver function for the "command" build back-end. | 16 | --- Driver function for the "command" build back-end. |
10 | -- @param rockspec table: the loaded rockspec. | 17 | -- @param rockspec table: the loaded rockspec. |
11 | -- @return boolean or (nil, string): true if no errors occurred, | 18 | -- @return boolean or (nil, string): true if no errors occurred, |
12 | -- nil and an error message otherwise. | 19 | -- nil and an error message otherwise. |
13 | function command.run(rockspec, not_install) | 20 | function command.run(rockspec: Rockspec, not_install: boolean): boolean, string, string |
14 | assert(rockspec:type() == "rockspec") | ||
15 | 21 | ||
16 | local build = rockspec.build | 22 | local build = rockspec.build as CommandBuild |
17 | 23 | ||
18 | util.variable_substitutions(build, rockspec.variables) | 24 | util.variable_substitutions(build as {string: string}, rockspec.variables) |
19 | 25 | ||
20 | local env = { | 26 | local env: {string: string} = { |
21 | CC = cfg.variables.CC, | 27 | CC = cfg.variables.CC, |
22 | --LD = cfg.variables.LD, | 28 | --LD = cfg.variables.LD, |
23 | --CFLAGS = cfg.variables.CFLAGS, | 29 | --CFLAGS = cfg.variables.CFLAGS, |
diff --git a/src/luarocks/build/make.tl b/src/luarocks/build/make.tl index 4345ddff..58fc6e2e 100644 --- a/src/luarocks/build/make.tl +++ b/src/luarocks/build/make.tl | |||
@@ -1,13 +1,18 @@ | |||
1 | 1 | ||
2 | --- Build back-end for using Makefile-based packages. | 2 | --- Build back-end for using Makefile-based packages. |
3 | local make = {} | 3 | local record make |
4 | 4 | end | |
5 | local unpack = unpack or table.unpack | ||
6 | 5 | ||
7 | local fs = require("luarocks.fs") | 6 | local fs = require("luarocks.fs") |
8 | local util = require("luarocks.util") | 7 | local util = require("luarocks.util") |
9 | local cfg = require("luarocks.core.cfg") | 8 | local cfg = require("luarocks.core.cfg") |
10 | 9 | ||
10 | local type r = require("luarocks.core.types.rockspec") | ||
11 | local type Rockspec = r.Rockspec | ||
12 | |||
13 | local type b = require("luarocks.core.types.build") | ||
14 | local type MakeBuild = b.MakeBuild | ||
15 | |||
11 | --- Call "make" with given target and variables | 16 | --- Call "make" with given target and variables |
12 | -- @param make_cmd string: the make command to be used (typically | 17 | -- @param make_cmd string: the make command to be used (typically |
13 | -- configured through variables.MAKE in the config files, or | 18 | -- configured through variables.MAKE in the config files, or |
@@ -18,17 +23,13 @@ local cfg = require("luarocks.core.cfg") | |||
18 | -- @param variables table: A table containing string-string key-value | 23 | -- @param variables table: A table containing string-string key-value |
19 | -- pairs representing variable assignments to be passed to make. | 24 | -- pairs representing variable assignments to be passed to make. |
20 | -- @return boolean: false if any errors occurred, true otherwise. | 25 | -- @return boolean: false if any errors occurred, true otherwise. |
21 | local function make_pass(make_cmd, pass, target, variables) | 26 | local function make_pass(make_cmd: string, pass: boolean, target: string, variables: {string: string}): boolean, string, string |
22 | assert(type(pass) == "boolean") | 27 | local assignments: {string} = {} |
23 | assert(type(target) == "string") | ||
24 | assert(type(variables) == "table") | ||
25 | |||
26 | local assignments = {} | ||
27 | for k,v in pairs(variables) do | 28 | for k,v in pairs(variables) do |
28 | table.insert(assignments, k.."="..v) | 29 | table.insert(assignments, k.."="..v) |
29 | end | 30 | end |
30 | if pass then | 31 | if pass then |
31 | return fs.execute(make_cmd.." "..target, unpack(assignments)) | 32 | return fs.execute(make_cmd.." "..target, table.unpack(assignments)) |
32 | else | 33 | else |
33 | return true | 34 | return true |
34 | end | 35 | end |
@@ -38,10 +39,9 @@ end | |||
38 | -- @param rockspec table: the loaded rockspec. | 39 | -- @param rockspec table: the loaded rockspec. |
39 | -- @return boolean or (nil, string): true if no errors occurred, | 40 | -- @return boolean or (nil, string): true if no errors occurred, |
40 | -- nil and an error message otherwise. | 41 | -- nil and an error message otherwise. |
41 | function make.run(rockspec, not_install) | 42 | function make.run(rockspec: Rockspec, not_install: boolean): boolean, string, string |
42 | assert(rockspec:type() == "rockspec") | ||
43 | 43 | ||
44 | local build = rockspec.build | 44 | local build = rockspec.build as MakeBuild |
45 | 45 | ||
46 | if build.build_pass == nil then build.build_pass = true end | 46 | if build.build_pass == nil then build.build_pass = true end |
47 | if build.install_pass == nil then build.install_pass = true end | 47 | if build.install_pass == nil then build.install_pass = true end |
@@ -64,13 +64,13 @@ function make.run(rockspec, not_install) | |||
64 | end | 64 | end |
65 | 65 | ||
66 | util.warn_if_not_used(build.build_variables, { CFLAGS=true }, "variable %s was not passed in build_variables") | 66 | util.warn_if_not_used(build.build_variables, { CFLAGS=true }, "variable %s was not passed in build_variables") |
67 | 67 | -- Here, `util.warn_if_not_used(build.build_variables, { CFLAGS=true }, "variable %s was not passed in build_variables")` isn't the type of `build.build_variables`, `{string: string}`, like `variables` | |
68 | util.variable_substitutions(build.build_variables, rockspec.variables) | 68 | util.variable_substitutions(build.build_variables, rockspec.variables) |
69 | util.variable_substitutions(build.install_variables, rockspec.variables) | 69 | util.variable_substitutions(build.install_variables, rockspec.variables) |
70 | 70 | ||
71 | local auto_variables = { "CC" } | 71 | local auto_variables = { "CC" } |
72 | 72 | ||
73 | for _, variable in pairs(auto_variables) do | 73 | for _, variable in ipairs(auto_variables) do |
74 | if not build.build_variables[variable] then | 74 | if not build.build_variables[variable] then |
75 | build.build_variables[variable] = rockspec.variables[variable] | 75 | build.build_variables[variable] = rockspec.variables[variable] |
76 | end | 76 | end |
diff --git a/src/luarocks/build/builtin-incomplete.lua b/src/luarocks/build/originals/builtin-original.lua index 76b50d9f..14d13eb4 100644 --- a/src/luarocks/build/builtin-incomplete.lua +++ b/src/luarocks/build/originals/builtin-original.lua | |||
@@ -1,24 +1,13 @@ | |||
1 | local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local io = _tl_compat and _tl_compat.io or io; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local os = _tl_compat and _tl_compat.os or os; local package = _tl_compat and _tl_compat.package or package; local pairs = _tl_compat and _tl_compat.pairs or pairs; local string = _tl_compat and _tl_compat.string or string; local table = _tl_compat and _tl_compat.table or table; local _tl_table_unpack = unpack or table.unpack | ||
2 | 1 | ||
2 | --- A builtin build system: back-end to provide a portable way of building C-based Lua modules. | ||
3 | local builtin = {} | 3 | local builtin = {} |
4 | 4 | ||
5 | 5 | -- This build driver checks LUA_INCDIR and LUA_LIBDIR on demand, | |
6 | 6 | -- so that pure-Lua rocks don't need to have development headers | |
7 | 7 | -- installed. | |
8 | |||
9 | |||
10 | |||
11 | |||
12 | |||
13 | |||
14 | |||
15 | |||
16 | |||
17 | |||
18 | |||
19 | |||
20 | builtin.skip_lua_inc_lib_check = true | 8 | builtin.skip_lua_inc_lib_check = true |
21 | 9 | ||
10 | local unpack = unpack or table.unpack | ||
22 | local dir_sep = package.config:sub(1, 1) | 11 | local dir_sep = package.config:sub(1, 1) |
23 | 12 | ||
24 | local fs = require("luarocks.fs") | 13 | local fs = require("luarocks.fs") |
@@ -68,7 +57,7 @@ do | |||
68 | local copy_directories | 57 | local copy_directories |
69 | 58 | ||
70 | local prefix = "" | 59 | local prefix = "" |
71 | for _, parent in ipairs({ "src", "lua", "lib" }) do | 60 | for _, parent in ipairs({"src", "lua", "lib"}) do |
72 | if fs.is_dir(parent) then | 61 | if fs.is_dir(parent) then |
73 | fs.change_dir(parent) | 62 | fs.change_dir(parent) |
74 | prefix = parent .. dir_sep | 63 | prefix = parent .. dir_sep |
@@ -78,16 +67,16 @@ do | |||
78 | 67 | ||
79 | for _, file in ipairs(fs.find()) do | 68 | for _, file in ipairs(fs.find()) do |
80 | local base = file:match("^([^\\/]*)") | 69 | local base = file:match("^([^\\/]*)") |
81 | if not (skiplist)[base] then | 70 | if not skiplist[base] then |
82 | local luamod = file:match("(.*)%.lua$") | 71 | local luamod = file:match("(.*)%.lua$") |
83 | if luamod then | 72 | if luamod then |
84 | modules[path.path_to_module(file)] = prefix .. file | 73 | modules[path.path_to_module(file)] = prefix .. file |
85 | else | 74 | else |
86 | local cmod = file:match("(.*)%.c$") | 75 | local cmod = file:match("(.*)%.c$") |
87 | if cmod then | 76 | if cmod then |
88 | local modname = get_cmod_name(file) or path.path_to_module((file:gsub("%.c$", ".lua"))) | 77 | local modname = get_cmod_name(file) or path.path_to_module(file:gsub("%.c$", ".lua")) |
89 | modules[modname] = { | 78 | modules[modname] = { |
90 | sources = prefix .. file, | 79 | sources = prefix..file, |
91 | libraries = libs, | 80 | libraries = libs, |
92 | incdirs = incdirs, | 81 | incdirs = incdirs, |
93 | libdirs = libdirs, | 82 | libdirs = libdirs, |
@@ -101,8 +90,8 @@ do | |||
101 | fs.pop_dir() | 90 | fs.pop_dir() |
102 | end | 91 | end |
103 | 92 | ||
104 | local bindir = (fs.is_dir(dir.path("src", "bin")) and dir.path("src", "bin")) or | 93 | local bindir = (fs.is_dir(dir.path("src", "bin")) and dir.path("src", "bin")) |
105 | (fs.is_dir("bin") and "bin") | 94 | or (fs.is_dir("bin") and "bin") |
106 | if bindir then | 95 | if bindir then |
107 | install = { bin = {} } | 96 | install = { bin = {} } |
108 | for _, file in ipairs(fs.list_dir(bindir)) do | 97 | for _, file in ipairs(fs.list_dir(bindir)) do |
@@ -123,34 +112,33 @@ do | |||
123 | end | 112 | end |
124 | end | 113 | end |
125 | 114 | ||
126 | 115 | --- Run a command displaying its execution on standard output. | |
127 | 116 | -- @return boolean: true if command succeeds (status code 0), false | |
128 | 117 | -- otherwise. | |
129 | local function execute(...) | 118 | local function execute(...) |
130 | io.stdout:write(table.concat({ ... }, " ") .. "\n") | 119 | io.stdout:write(table.concat({...}, " ").."\n") |
131 | return fs.execute(...) | 120 | return fs.execute(...) |
132 | end | 121 | end |
133 | 122 | ||
134 | 123 | --- Driver function for the builtin build back-end. | |
135 | 124 | -- @param rockspec table: the loaded rockspec. | |
136 | 125 | -- @return boolean or (nil, string): true if no errors occurred, | |
137 | 126 | -- nil and an error message otherwise. | |
138 | function builtin.run(rockspec, no_install) | 127 | function builtin.run(rockspec, no_install) |
139 | local compile_object | 128 | assert(rockspec:type() == "rockspec") |
140 | local compile_library | 129 | local compile_object, compile_library, compile_static_library |
141 | local compile_static_library | ||
142 | 130 | ||
143 | local build = rockspec.build | 131 | local build = rockspec.build |
144 | local variables = rockspec.variables | 132 | local variables = rockspec.variables |
145 | local checked_lua_h = false | 133 | local checked_lua_h = false |
146 | 134 | ||
147 | for _, var in ipairs({ "CC", "CFLAGS", "LDFLAGS" }) do | 135 | for _, var in ipairs{ "CC", "CFLAGS", "LDFLAGS" } do |
148 | variables[var] = variables[var] or os.getenv(var) or "" | 136 | variables[var] = variables[var] or os.getenv(var) or "" |
149 | end | 137 | end |
150 | 138 | ||
151 | local function add_flags(extras, flag, flags) | 139 | local function add_flags(extras, flag, flags) |
152 | if flags then | 140 | if flags then |
153 | if not (type(flags) == "table") then | 141 | if type(flags) ~= "table" then |
154 | flags = { tostring(flags) } | 142 | flags = { tostring(flags) } |
155 | end | 143 | end |
156 | util.variable_substitutions(flags, variables) | 144 | util.variable_substitutions(flags, variables) |
@@ -165,43 +153,43 @@ function builtin.run(rockspec, no_install) | |||
165 | local extras = {} | 153 | local extras = {} |
166 | add_flags(extras, "-D%s", defines) | 154 | add_flags(extras, "-D%s", defines) |
167 | add_flags(extras, "-I%s", incdirs) | 155 | add_flags(extras, "-I%s", incdirs) |
168 | return execute(variables.CC .. " " .. variables.CFLAGS, "-c", "-o", object, "-I" .. variables.LUA_INCDIR, source, _tl_table_unpack(extras)) | 156 | return execute(variables.CC.." "..variables.CFLAGS, "-c", "-o", object, "-I"..variables.LUA_INCDIR, source, unpack(extras)) |
169 | end | 157 | end |
170 | compile_library = function(library, objects, libraries, libdirs, name) | 158 | compile_library = function(library, objects, libraries, libdirs, name) |
171 | local extras = { _tl_table_unpack(objects) } | 159 | local extras = { unpack(objects) } |
172 | add_flags(extras, "-L%s", libdirs) | 160 | add_flags(extras, "-L%s", libdirs) |
173 | add_flags(extras, "-l%s", libraries) | 161 | add_flags(extras, "-l%s", libraries) |
174 | extras[#extras + 1] = dir.path(variables.LUA_LIBDIR, variables.LUALIB) | 162 | extras[#extras+1] = dir.path(variables.LUA_LIBDIR, variables.LUALIB) |
175 | 163 | ||
176 | if variables.CC == "clang" or variables.CC == "clang-cl" then | 164 | if variables.CC == "clang" or variables.CC == "clang-cl" then |
177 | local exported_name = name:gsub("%.", "_") | 165 | local exported_name = name:gsub("%.", "_") |
178 | exported_name = exported_name:match('^[^%-]+%-(.+)$') or exported_name | 166 | exported_name = exported_name:match('^[^%-]+%-(.+)$') or exported_name |
179 | extras[#extras + 1] = string.format("-Wl,-export:luaopen_%s", exported_name) | 167 | extras[#extras+1] = string.format("-Wl,-export:luaopen_%s", exported_name) |
180 | else | 168 | else |
181 | extras[#extras + 1] = "-l" .. (variables.MSVCRT or "m") | 169 | extras[#extras+1] = "-l" .. (variables.MSVCRT or "m") |
182 | end | 170 | end |
183 | 171 | ||
184 | local ok = execute(variables.LD .. " " .. variables.LDFLAGS .. " " .. variables.LIBFLAG, "-o", library, _tl_table_unpack(extras)) | 172 | local ok = execute(variables.LD.." "..variables.LDFLAGS.." "..variables.LIBFLAG, "-o", library, unpack(extras)) |
185 | return ok | 173 | return ok |
186 | end | 174 | end |
187 | 175 | --[[ TODO disable static libs until we fix the conflict in the manifest, which will take extending the manifest format. | |
188 | 176 | compile_static_library = function(library, objects, libraries, libdirs, name) | |
189 | 177 | local ok = execute(variables.AR, "rc", library, unpack(objects)) | |
190 | 178 | if ok then | |
191 | 179 | ok = execute(variables.RANLIB, library) | |
192 | 180 | end | |
193 | 181 | return ok | |
194 | 182 | end | |
195 | 183 | ]] | |
196 | elseif cfg.is_platform("win32") then | 184 | elseif cfg.is_platform("win32") then |
197 | compile_object = function(object, source, defines, incdirs) | 185 | compile_object = function(object, source, defines, incdirs) |
198 | local extras = {} | 186 | local extras = {} |
199 | add_flags(extras, "-D%s", defines) | 187 | add_flags(extras, "-D%s", defines) |
200 | add_flags(extras, "-I%s", incdirs) | 188 | add_flags(extras, "-I%s", incdirs) |
201 | return execute(variables.CC .. " " .. variables.CFLAGS, "-c", "-Fo" .. object, "-I" .. variables.LUA_INCDIR, source, _tl_table_unpack(extras)) | 189 | return execute(variables.CC.." "..variables.CFLAGS, "-c", "-Fo"..object, "-I"..variables.LUA_INCDIR, source, unpack(extras)) |
202 | end | 190 | end |
203 | compile_library = function(library, objects, libraries, libdirs, name) | 191 | compile_library = function(library, objects, libraries, libdirs, name) |
204 | local extras = { _tl_table_unpack(objects) } | 192 | local extras = { unpack(objects) } |
205 | add_flags(extras, "-libpath:%s", libdirs) | 193 | add_flags(extras, "-libpath:%s", libdirs) |
206 | add_flags(extras, "%s.lib", libraries) | 194 | add_flags(extras, "%s.lib", libraries) |
207 | local basename = dir.base_name(library):gsub(".[^.]*$", "") | 195 | local basename = dir.base_name(library):gsub(".[^.]*$", "") |
@@ -210,49 +198,49 @@ function builtin.run(rockspec, no_install) | |||
210 | local exported_name = name:gsub("%.", "_") | 198 | local exported_name = name:gsub("%.", "_") |
211 | exported_name = exported_name:match('^[^%-]+%-(.+)$') or exported_name | 199 | exported_name = exported_name:match('^[^%-]+%-(.+)$') or exported_name |
212 | def:write("EXPORTS\n") | 200 | def:write("EXPORTS\n") |
213 | def:write("luaopen_" .. exported_name .. "\n") | 201 | def:write("luaopen_"..exported_name.."\n") |
214 | def:close() | 202 | def:close() |
215 | local ok = execute(variables.LD, "-dll", "-def:" .. deffile, "-out:" .. library, dir.path(variables.LUA_LIBDIR, variables.LUALIB), _tl_table_unpack(extras)) | 203 | local ok = execute(variables.LD, "-dll", "-def:"..deffile, "-out:"..library, dir.path(variables.LUA_LIBDIR, variables.LUALIB), unpack(extras)) |
216 | local basedir = "" | 204 | local basedir = "" |
217 | if name:find("%.") ~= nil then | 205 | if name:find("%.") ~= nil then |
218 | basedir = name:gsub("%.%w+$", "\\") | 206 | basedir = name:gsub("%.%w+$", "\\") |
219 | basedir = basedir:gsub("%.", "\\") | 207 | basedir = basedir:gsub("%.", "\\") |
220 | end | 208 | end |
221 | local manifestfile = basedir .. basename .. ".dll.manifest" | 209 | local manifestfile = basedir .. basename..".dll.manifest" |
222 | 210 | ||
223 | if ok and fs.exists(manifestfile) then | 211 | if ok and fs.exists(manifestfile) then |
224 | ok = execute(variables.MT, "-manifest", manifestfile, "-outputresource:" .. basedir .. basename .. ".dll;2") | 212 | ok = execute(variables.MT, "-manifest", manifestfile, "-outputresource:"..basedir..basename..".dll;2") |
225 | end | 213 | end |
226 | return ok | 214 | return ok |
227 | end | 215 | end |
228 | 216 | --[[ TODO disable static libs until we fix the conflict in the manifest, which will take extending the manifest format. | |
229 | 217 | compile_static_library = function(library, objects, libraries, libdirs, name) | |
230 | 218 | local ok = execute(variables.AR, "-out:"..library, unpack(objects)) | |
231 | 219 | return ok | |
232 | 220 | end | |
233 | 221 | ]] | |
234 | else | 222 | else |
235 | compile_object = function(object, source, defines, incdirs) | 223 | compile_object = function(object, source, defines, incdirs) |
236 | local extras = {} | 224 | local extras = {} |
237 | add_flags(extras, "-D%s", defines) | 225 | add_flags(extras, "-D%s", defines) |
238 | add_flags(extras, "-I%s", incdirs) | 226 | add_flags(extras, "-I%s", incdirs) |
239 | return execute(variables.CC .. " " .. variables.CFLAGS, "-I" .. variables.LUA_INCDIR, "-c", source, "-o", object, _tl_table_unpack(extras)) | 227 | return execute(variables.CC.." "..variables.CFLAGS, "-I"..variables.LUA_INCDIR, "-c", source, "-o", object, unpack(extras)) |
240 | end | 228 | end |
241 | compile_library = function(library, objects, libraries, libdirs) | 229 | compile_library = function (library, objects, libraries, libdirs) |
242 | local extras = { _tl_table_unpack(objects) } | 230 | local extras = { unpack(objects) } |
243 | add_flags(extras, "-L%s", libdirs) | 231 | add_flags(extras, "-L%s", libdirs) |
244 | if cfg.gcc_rpath then | 232 | if cfg.gcc_rpath then |
245 | add_flags(extras, "-Wl,-rpath,%s", libdirs) | 233 | add_flags(extras, "-Wl,-rpath,%s", libdirs) |
246 | end | 234 | end |
247 | add_flags(extras, "-l%s", libraries) | 235 | add_flags(extras, "-l%s", libraries) |
248 | if cfg.link_lua_explicitly then | 236 | if cfg.link_lua_explicitly then |
249 | extras[#extras + 1] = "-L" .. variables.LUA_LIBDIR | 237 | extras[#extras+1] = "-L"..variables.LUA_LIBDIR |
250 | extras[#extras + 1] = "-llua" | 238 | extras[#extras+1] = "-llua" |
251 | end | 239 | end |
252 | return execute(variables.LD .. " " .. variables.LDFLAGS .. " " .. variables.LIBFLAG, "-o", library, _tl_table_unpack(extras)) | 240 | return execute(variables.LD.." "..variables.LDFLAGS.." "..variables.LIBFLAG, "-o", library, unpack(extras)) |
253 | end | 241 | end |
254 | compile_static_library = function(library, objects, libraries, libdirs, name) | 242 | compile_static_library = function(library, objects, libraries, libdirs, name) -- luacheck: ignore 211 |
255 | local ok = execute(variables.AR, "rc", library, _tl_table_unpack(objects)) | 243 | local ok = execute(variables.AR, "rc", library, unpack(objects)) |
256 | if ok then | 244 | if ok then |
257 | ok = execute(variables.RANLIB, library) | 245 | ok = execute(variables.RANLIB, library) |
258 | end | 246 | end |
@@ -297,15 +285,15 @@ function builtin.run(rockspec, no_install) | |||
297 | if ext == "lua" then | 285 | if ext == "lua" then |
298 | local filename = dir.base_name(info) | 286 | local filename = dir.base_name(info) |
299 | if filename == "init.lua" and not name:match("%.init$") then | 287 | if filename == "init.lua" and not name:match("%.init$") then |
300 | moddir = path.module_to_path(name .. ".init") | 288 | moddir = path.module_to_path(name..".init") |
301 | else | 289 | else |
302 | local basename = name:match("([^.]+)$") | 290 | local basename = name:match("([^.]+)$") |
303 | filename = basename .. ".lua" | 291 | filename = basename..".lua" |
304 | end | 292 | end |
305 | local dest = dir.path(luadir, moddir, filename) | 293 | local dest = dir.path(luadir, moddir, filename) |
306 | lua_modules[info] = dest | 294 | lua_modules[info] = dest |
307 | else | 295 | else |
308 | info = { info } | 296 | info = {info} |
309 | end | 297 | end |
310 | end | 298 | end |
311 | if type(info) == "table" then | 299 | if type(info) == "table" then |
@@ -326,21 +314,21 @@ function builtin.run(rockspec, no_install) | |||
326 | local objects = {} | 314 | local objects = {} |
327 | local sources = info.sources | 315 | local sources = info.sources |
328 | if info[1] then sources = info end | 316 | if info[1] then sources = info end |
329 | if type(sources) == "string" then sources = { sources } end | 317 | if type(sources) == "string" then sources = {sources} end |
330 | if not (type(sources) == "table") then | 318 | if type(sources) ~= "table" then |
331 | return nil, "error in rockspec: module '" .. name .. "' entry has no 'sources' list" | 319 | return nil, "error in rockspec: module '" .. name .. "' entry has no 'sources' list" |
332 | end | 320 | end |
333 | for _, source in ipairs(sources) do | 321 | for _, source in ipairs(sources) do |
334 | if not (type(source) == "string") then | 322 | if type(source) ~= "string" then |
335 | return nil, "error in rockspec: module '" .. name .. "' does not specify source correctly." | 323 | return nil, "error in rockspec: module '" .. name .. "' does not specify source correctly." |
336 | end | 324 | end |
337 | local object = source:gsub("%.[^.]*$", "." .. cfg.obj_extension) | 325 | local object = source:gsub("%.[^.]*$", "."..cfg.obj_extension) |
338 | if not object then | 326 | if not object then |
339 | object = source .. "." .. cfg.obj_extension | 327 | object = source.."."..cfg.obj_extension |
340 | end | 328 | end |
341 | ok = compile_object(object, source, info.defines, info.incdirs or autoincdirs) | 329 | ok = compile_object(object, source, info.defines, info.incdirs or autoincdirs) |
342 | if not ok then | 330 | if not ok then |
343 | return nil, "Failed compiling object " .. object | 331 | return nil, "Failed compiling object "..object |
344 | end | 332 | end |
345 | table.insert(objects, object) | 333 | table.insert(objects, object) |
346 | end | 334 | end |
@@ -350,7 +338,7 @@ function builtin.run(rockspec, no_install) | |||
350 | util.schedule_function(fs.delete, compile_temp_dir) | 338 | util.schedule_function(fs.delete, compile_temp_dir) |
351 | end | 339 | end |
352 | 340 | ||
353 | local module_name = name:match("([^.]*)$") .. "." .. util.matchquote(cfg.lib_extension) | 341 | local module_name = name:match("([^.]*)$").."."..util.matchquote(cfg.lib_extension) |
354 | if moddir ~= "" then | 342 | if moddir ~= "" then |
355 | module_name = dir.path(moddir, module_name) | 343 | module_name = dir.path(moddir, module_name) |
356 | end | 344 | end |
@@ -362,46 +350,46 @@ function builtin.run(rockspec, no_install) | |||
362 | lib_modules[build_name] = dir.path(libdir, module_name) | 350 | lib_modules[build_name] = dir.path(libdir, module_name) |
363 | ok = compile_library(build_name, objects, info.libraries, info.libdirs or autolibdirs, name) | 351 | ok = compile_library(build_name, objects, info.libraries, info.libdirs or autolibdirs, name) |
364 | if not ok then | 352 | if not ok then |
365 | return nil, "Failed compiling module " .. module_name | 353 | return nil, "Failed compiling module "..module_name |
366 | end | 354 | end |
367 | 355 | ||
368 | 356 | -- for backwards compatibility, try keeping a copy of the module | |
369 | 357 | -- in the old location (luasec-1.3.2-1 rockspec breaks otherwise) | |
370 | if cached_make_dir(dir.dir_name(module_name)) then | 358 | if cached_make_dir(dir.dir_name(module_name)) then |
371 | fs.copy(build_name, module_name) | 359 | fs.copy(build_name, module_name) |
372 | end | 360 | end |
373 | 361 | ||
374 | 362 | --[[ TODO disable static libs until we fix the conflict in the manifest, which will take extending the manifest format. | |
375 | 363 | module_name = name:match("([^.]*)$").."."..util.matchquote(cfg.static_lib_extension) | |
376 | 364 | if moddir ~= "" then | |
377 | 365 | module_name = dir.path(moddir, module_name) | |
378 | 366 | end | |
379 | 367 | lib_modules[module_name] = dir.path(libdir, module_name) | |
380 | 368 | ok = compile_static_library(module_name, objects, info.libraries, info.libdirs, name) | |
381 | 369 | if not ok then | |
382 | 370 | return nil, "Failed compiling static library "..module_name | |
383 | 371 | end | |
384 | 372 | ]] | |
385 | end | 373 | end |
386 | end | 374 | end |
387 | if not no_install then | 375 | if not no_install then |
388 | for _, mods in ipairs({ { tbl = lua_modules, perms = "read" }, { tbl = lib_modules, perms = "exec" } }) do | 376 | for _, mods in ipairs({{ tbl = lua_modules, perms = "read" }, { tbl = lib_modules, perms = "exec" }}) do |
389 | for name, dest in pairs(mods.tbl) do | 377 | for name, dest in pairs(mods.tbl) do |
390 | cached_make_dir(dir.dir_name(dest)) | 378 | cached_make_dir(dir.dir_name(dest)) |
391 | ok, err = fs.copy(name, dest, mods.perms) | 379 | ok, err = fs.copy(name, dest, mods.perms) |
392 | if not ok then | 380 | if not ok then |
393 | return nil, "Failed installing " .. name .. " in " .. dest .. ": " .. err | 381 | return nil, "Failed installing "..name.." in "..dest..": "..err |
394 | end | 382 | end |
395 | end | 383 | end |
396 | end | 384 | end |
397 | if fs.is_dir("lua") then | 385 | if fs.is_dir("lua") then |
398 | ok, err = fs.copy_contents("lua", luadir) | 386 | ok, err = fs.copy_contents("lua", luadir) |
399 | if not ok then | 387 | if not ok then |
400 | return nil, "Failed copying contents of 'lua' directory: " .. err | 388 | return nil, "Failed copying contents of 'lua' directory: "..err |
401 | end | 389 | end |
402 | end | 390 | end |
403 | end | 391 | end |
404 | return true | 392 | return true |
405 | end | 393 | end |
406 | 394 | ||
407 | return builtin | 395 | return builtin \ No newline at end of file |
diff --git a/src/luarocks/build/originals/cmake-original.lua b/src/luarocks/build/originals/cmake-original.lua new file mode 100644 index 00000000..b7a4786e --- /dev/null +++ b/src/luarocks/build/originals/cmake-original.lua | |||
@@ -0,0 +1,78 @@ | |||
1 | |||
2 | --- Build back-end for CMake-based modules. | ||
3 | local cmake = {} | ||
4 | |||
5 | local fs = require("luarocks.fs") | ||
6 | local util = require("luarocks.util") | ||
7 | local cfg = require("luarocks.core.cfg") | ||
8 | |||
9 | --- Driver function for the "cmake" build back-end. | ||
10 | -- @param rockspec table: the loaded rockspec. | ||
11 | -- @return boolean or (nil, string): true if no errors occurred, | ||
12 | -- nil and an error message otherwise. | ||
13 | function cmake.run(rockspec, no_install) | ||
14 | assert(rockspec:type() == "rockspec") | ||
15 | local build = rockspec.build | ||
16 | local variables = build.variables or {} | ||
17 | |||
18 | -- Pass Env variables | ||
19 | variables.CMAKE_MODULE_PATH=os.getenv("CMAKE_MODULE_PATH") | ||
20 | variables.CMAKE_LIBRARY_PATH=os.getenv("CMAKE_LIBRARY_PATH") | ||
21 | variables.CMAKE_INCLUDE_PATH=os.getenv("CMAKE_INCLUDE_PATH") | ||
22 | |||
23 | util.variable_substitutions(variables, rockspec.variables) | ||
24 | |||
25 | local ok, err_msg = fs.is_tool_available(rockspec.variables.CMAKE, "CMake") | ||
26 | if not ok then | ||
27 | return nil, err_msg | ||
28 | end | ||
29 | |||
30 | -- If inline cmake is present create CMakeLists.txt from it. | ||
31 | if type(build.cmake) == "string" then | ||
32 | local cmake_handler = assert(io.open(fs.current_dir().."/CMakeLists.txt", "w")) | ||
33 | cmake_handler:write(build.cmake) | ||
34 | cmake_handler:close() | ||
35 | end | ||
36 | |||
37 | -- Execute cmake with variables. | ||
38 | local args = "" | ||
39 | |||
40 | -- Try to pick the best generator. With msvc and x64, CMake does not select it by default so we need to be explicit. | ||
41 | if cfg.cmake_generator then | ||
42 | args = args .. ' -G"'..cfg.cmake_generator.. '"' | ||
43 | elseif cfg.is_platform("windows") and cfg.target_cpu:match("x86_64$") then | ||
44 | args = args .. " -DCMAKE_GENERATOR_PLATFORM=x64" | ||
45 | end | ||
46 | |||
47 | for k,v in pairs(variables) do | ||
48 | args = args .. ' -D' ..k.. '="' ..tostring(v).. '"' | ||
49 | end | ||
50 | |||
51 | if not fs.execute_string(rockspec.variables.CMAKE.." -H. -Bbuild.luarocks "..args) then | ||
52 | return nil, "Failed cmake." | ||
53 | end | ||
54 | |||
55 | local do_build, do_install | ||
56 | if rockspec:format_is_at_least("3.0") then | ||
57 | do_build = (build.build_pass == nil) and true or build.build_pass | ||
58 | do_install = (build.install_pass == nil) and true or build.install_pass | ||
59 | else | ||
60 | do_build = true | ||
61 | do_install = true | ||
62 | end | ||
63 | |||
64 | if do_build then | ||
65 | if not fs.execute_string(rockspec.variables.CMAKE.." --build build.luarocks --config Release") then | ||
66 | return nil, "Failed building." | ||
67 | end | ||
68 | end | ||
69 | if do_install and not no_install then | ||
70 | if not fs.execute_string(rockspec.variables.CMAKE.." --build build.luarocks --target install --config Release") then | ||
71 | return nil, "Failed installing." | ||
72 | end | ||
73 | end | ||
74 | |||
75 | return true | ||
76 | end | ||
77 | |||
78 | return cmake | ||
diff --git a/src/luarocks/build/originals/command-original.lua b/src/luarocks/build/originals/command-original.lua new file mode 100644 index 00000000..b0c4aa79 --- /dev/null +++ b/src/luarocks/build/originals/command-original.lua | |||
@@ -0,0 +1,41 @@ | |||
1 | |||
2 | --- Build back-end for raw listing of commands in rockspec files. | ||
3 | local command = {} | ||
4 | |||
5 | local fs = require("luarocks.fs") | ||
6 | local util = require("luarocks.util") | ||
7 | local cfg = require("luarocks.core.cfg") | ||
8 | |||
9 | --- Driver function for the "command" build back-end. | ||
10 | -- @param rockspec table: the loaded rockspec. | ||
11 | -- @return boolean or (nil, string): true if no errors occurred, | ||
12 | -- nil and an error message otherwise. | ||
13 | function command.run(rockspec, not_install) | ||
14 | assert(rockspec:type() == "rockspec") | ||
15 | |||
16 | local build = rockspec.build | ||
17 | |||
18 | util.variable_substitutions(build, rockspec.variables) | ||
19 | |||
20 | local env = { | ||
21 | CC = cfg.variables.CC, | ||
22 | --LD = cfg.variables.LD, | ||
23 | --CFLAGS = cfg.variables.CFLAGS, | ||
24 | } | ||
25 | |||
26 | if build.build_command then | ||
27 | util.printout(build.build_command) | ||
28 | if not fs.execute_env(env, build.build_command) then | ||
29 | return nil, "Failed building." | ||
30 | end | ||
31 | end | ||
32 | if build.install_command and not not_install then | ||
33 | util.printout(build.install_command) | ||
34 | if not fs.execute_env(env, build.install_command) then | ||
35 | return nil, "Failed installing." | ||
36 | end | ||
37 | end | ||
38 | return true | ||
39 | end | ||
40 | |||
41 | return command | ||
diff --git a/src/luarocks/core/cfg.d.tl b/src/luarocks/core/cfg.d.tl index 1e03445a..409d2441 100644 --- a/src/luarocks/core/cfg.d.tl +++ b/src/luarocks/core/cfg.d.tl | |||
@@ -86,6 +86,9 @@ local record cfg | |||
86 | -- cmake | 86 | -- cmake |
87 | cmake_generator: string | 87 | cmake_generator: string |
88 | target_cpu: string | 88 | target_cpu: string |
89 | -- make | ||
90 | makefile: string | ||
91 | make: string | ||
89 | end | 92 | end |
90 | 93 | ||
91 | return cfg \ No newline at end of file | 94 | return cfg \ No newline at end of file |
diff --git a/src/luarocks/core/types/build.d.tl b/src/luarocks/core/types/build.d.tl index 061741bb..e2acdda3 100644 --- a/src/luarocks/core/types/build.d.tl +++ b/src/luarocks/core/types/build.d.tl | |||
@@ -1,60 +1,66 @@ | |||
1 | local type i = require("luarocks.core.types.installs") | ||
2 | local type Installs = i.Installs | ||
3 | |||
4 | local record build | 1 | local record build |
5 | 2 | ||
6 | interface Build | 3 | interface Build |
7 | type: string | 4 | record Install |
8 | install: Installs | 5 | lua: {string} |
9 | copy_directories: {string} | 6 | lib: {string} |
10 | patches: {string : string} | 7 | conf: {string} |
11 | extra_files: {string : string} | 8 | bin: {string} |
12 | macosx_deployment_target: string | 9 | end |
13 | end | 10 | |
14 | 11 | type: string | |
15 | record BuiltinBuild | 12 | install: Install |
16 | is Build | 13 | copy_directories: {string} |
17 | where self.type == "builtin" | 14 | patches: {string : string} |
18 | 15 | extra_files: {string : string} | |
19 | record Module | 16 | macosx_deployment_target: string |
20 | is {string} | 17 | end |
21 | sources: string | {string} | 18 | |
22 | libraries: string | {string} | 19 | record BuiltinBuild |
23 | defines: {string} | 20 | is Build |
24 | incdirs: {string} | 21 | where self.type == "builtin" |
25 | libdirs: {string} | 22 | |
26 | end | 23 | record Module |
27 | 24 | is {string} | |
28 | modules: {string: (string | Module)} | 25 | sources: string | {string} |
29 | end | 26 | libraries: string | {string} |
30 | 27 | defines: {string} | |
31 | 28 | incdirs: {string} | |
32 | record CMakeBuild | 29 | libdirs: {string} |
33 | is Build where self.type == "cmake" | 30 | end |
34 | 31 | ||
35 | cmake: string | 32 | modules: {string: (string | Module)} |
36 | variables: {string: string} | 33 | end |
37 | end | 34 | |
38 | 35 | ||
39 | record CommandBuild | 36 | record CMakeBuild |
40 | is Build where self.type == "command" | 37 | is Build where self.type == "cmake" |
41 | 38 | ||
42 | build_command: string | 39 | cmake: string |
43 | install_command: string | 40 | variables: {string: string} |
44 | end | 41 | build_pass: boolean |
45 | 42 | install_pass: boolean | |
46 | record MakeBuild | 43 | end |
47 | is Build where self.type == "make" | 44 | |
48 | 45 | record CommandBuild | |
49 | makefile: string | 46 | is Build where self.type == "command" |
50 | build_target: string | 47 | |
51 | build_pass: boolean | 48 | build_command: string |
52 | install_target: string | 49 | install_command: string |
53 | install_pass: boolean | 50 | end |
54 | build_variables: {string} --! | 51 | |
55 | install_variables: {string} | 52 | record MakeBuild |
56 | variables: {string: string} | 53 | is Build where self.type == "make" |
57 | end | 54 | |
55 | makefile: string | ||
56 | build_target: string | ||
57 | build_pass: boolean | ||
58 | install_target: string | ||
59 | install_pass: boolean | ||
60 | build_variables: {string: string} | ||
61 | install_variables: {string: string} | ||
62 | variables: {string: string} | ||
63 | end | ||
58 | end | 64 | end |
59 | 65 | ||
60 | return build \ No newline at end of file | 66 | return build \ No newline at end of file |
diff --git a/src/luarocks/core/types/installs.d.tl b/src/luarocks/core/types/installs.d.tl index 92e58658..57ad750a 100644 --- a/src/luarocks/core/types/installs.d.tl +++ b/src/luarocks/core/types/installs.d.tl | |||
@@ -1,17 +1,17 @@ | |||
1 | local record installs | 1 | local record installs |
2 | record Install | 2 | record InstallDir |
3 | is {string} | 3 | name: string |
4 | name: string | 4 | is_module_path: boolean |
5 | is_module_path: boolean | 5 | perms: string |
6 | perms: string | 6 | end |
7 | end | 7 | |
8 | 8 | record InstallDirs | |
9 | record Installs | 9 | lua: InstallDir |
10 | lua: Install | 10 | lib: InstallDir |
11 | lib: Install | 11 | conf: InstallDir |
12 | conf: Install | 12 | bin: InstallDir |
13 | bin: Install | 13 | end |
14 | end | 14 | |
15 | end | 15 | end |
16 | 16 | ||
17 | return installs \ No newline at end of file | 17 | return installs \ No newline at end of file |
diff --git a/src/luarocks/fs.d.tl b/src/luarocks/fs.d.tl index ce055567..3e099af5 100644 --- a/src/luarocks/fs.d.tl +++ b/src/luarocks/fs.d.tl | |||
@@ -62,6 +62,8 @@ local record fs | |||
62 | -- build | 62 | -- build |
63 | apply_patch: function(string, string, boolean): boolean, string | 63 | apply_patch: function(string, string, boolean): boolean, string |
64 | copy_contents: function(string, string): boolean, string | 64 | copy_contents: function(string, string): boolean, string |
65 | --command | ||
66 | execute_env: function({any: any}, string, ...:string): boolean | ||
65 | end | 67 | end |
66 | 68 | ||
67 | return fs | 69 | return fs |