aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2024-02-18 22:46:01 -0300
committerHisham Muhammad <hisham@gobolinux.org>2024-02-19 08:26:10 -0300
commit272921b2adf6136448dda9011425f8304c9d508d (patch)
tree9146488b7737d5f6a117f676f038afaa58f0c740
parent21b08e29ec1d4aa887d61a27b8fa8a75232522af (diff)
downloadluarocks-272921b2adf6136448dda9011425f8304c9d508d.tar.gz
luarocks-272921b2adf6136448dda9011425f8304c9d508d.tar.bz2
luarocks-272921b2adf6136448dda9011425f8304c9d508d.zip
fix(builtin): compile C modules in a temp directory
Fixes #1492.
-rw-r--r--src/luarocks/build.lua2
-rw-r--r--src/luarocks/build/builtin.lua38
2 files changed, 34 insertions, 6 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua
index d5c474ca..471de427 100644
--- a/src/luarocks/build.lua
+++ b/src/luarocks/build.lua
@@ -296,7 +296,7 @@ do
296 local ok, err = fs.make_dir(dest) 296 local ok, err = fs.make_dir(dest)
297 if not ok then return nil, err end 297 if not ok then return nil, err end
298 end 298 end
299 local ok = fs.copy(dir.path(file), dir.path(dest, filename), perms) 299 local ok = fs.copy(file, dir.path(dest, filename), perms)
300 if not ok then 300 if not ok then
301 return nil, "Failed copying "..file 301 return nil, "Failed copying "..file
302 end 302 end
diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua
index 73337544..70210bab 100644
--- a/src/luarocks/build/builtin.lua
+++ b/src/luarocks/build/builtin.lua
@@ -291,6 +291,18 @@ function builtin.run(rockspec, no_install)
291 return nil, "Missing build.modules table" 291 return nil, "Missing build.modules table"
292 end 292 end
293 end 293 end
294
295 local compile_temp_dir
296
297 local mkdir_cache = {}
298 local function cached_make_dir(name)
299 if name == "" or mkdir_cache[name] then
300 return true
301 end
302 mkdir_cache[name] = true
303 return fs.make_dir(name)
304 end
305
294 for name, info in pairs(build.modules) do 306 for name, info in pairs(build.modules) do
295 local moddir = path.module_to_path(name) 307 local moddir = path.module_to_path(name)
296 if type(info) == "string" then 308 if type(info) == "string" then
@@ -339,17 +351,33 @@ function builtin.run(rockspec, no_install)
339 end 351 end
340 table.insert(objects, object) 352 table.insert(objects, object)
341 end 353 end
354
355 if not compile_temp_dir then
356 compile_temp_dir = fs.make_temp_dir("build-" .. rockspec.package .. "-" .. rockspec.version)
357 util.schedule_function(fs.delete, compile_temp_dir)
358 end
359
342 local module_name = name:match("([^.]*)$").."."..util.matchquote(cfg.lib_extension) 360 local module_name = name:match("([^.]*)$").."."..util.matchquote(cfg.lib_extension)
343 if moddir ~= "" then 361 if moddir ~= "" then
344 module_name = dir.path(moddir, module_name) 362 module_name = dir.path(moddir, module_name)
345 ok, err = fs.make_dir(moddir)
346 if not ok then return nil, err end
347 end 363 end
348 lib_modules[module_name] = dir.path(libdir, module_name) 364
349 ok = compile_library(module_name, objects, info.libraries, info.libdirs or autolibdirs, name) 365 local build_name = dir.path(compile_temp_dir, module_name)
366 local build_dir = dir.dir_name(build_name)
367 cached_make_dir(build_dir)
368
369 lib_modules[build_name] = dir.path(libdir, module_name)
370 ok = compile_library(build_name, objects, info.libraries, info.libdirs or autolibdirs, name)
350 if not ok then 371 if not ok then
351 return nil, "Failed compiling module "..module_name 372 return nil, "Failed compiling module "..module_name
352 end 373 end
374
375 -- for backwards compatibility, try keeping a copy of the module
376 -- in the old location (luasec-1.3.2-1 rockspec breaks otherwise)
377 if cached_make_dir(dir.dir_name(module_name)) then
378 fs.copy(build_name, module_name)
379 end
380
353 --[[ TODO disable static libs until we fix the conflict in the manifest, which will take extending the manifest format. 381 --[[ TODO disable static libs until we fix the conflict in the manifest, which will take extending the manifest format.
354 module_name = name:match("([^.]*)$").."."..util.matchquote(cfg.static_lib_extension) 382 module_name = name:match("([^.]*)$").."."..util.matchquote(cfg.static_lib_extension)
355 if moddir ~= "" then 383 if moddir ~= "" then
@@ -366,7 +394,7 @@ function builtin.run(rockspec, no_install)
366 if not no_install then 394 if not no_install then
367 for _, mods in ipairs({{ tbl = lua_modules, perms = "read" }, { tbl = lib_modules, perms = "exec" }}) do 395 for _, mods in ipairs({{ tbl = lua_modules, perms = "read" }, { tbl = lib_modules, perms = "exec" }}) do
368 for name, dest in pairs(mods.tbl) do 396 for name, dest in pairs(mods.tbl) do
369 fs.make_dir(dir.dir_name(dest)) 397 cached_make_dir(dir.dir_name(dest))
370 ok, err = fs.copy(name, dest, mods.perms) 398 ok, err = fs.copy(name, dest, mods.perms)
371 if not ok then 399 if not ok then
372 return nil, "Failed installing "..name.." in "..dest..": "..err 400 return nil, "Failed installing "..name.." in "..dest..": "..err