From ee2e5e5c8f3dc529ad4308b8cfd6b43105eaebcf Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Thu, 15 Aug 2024 19:20:08 +0300 Subject: build --- src/luarocks/build/builtin.lua | 3 - src/luarocks/build/builtin.tl | 3 - src/luarocks/build/cmake.lua | 51 +++++++-------- src/luarocks/build/command.lua | 22 +++---- src/luarocks/build/originals/cmake-original.lua | 78 ----------------------- src/luarocks/build/originals/command-original.lua | 41 ------------ 6 files changed, 30 insertions(+), 168 deletions(-) delete mode 100644 src/luarocks/build/originals/cmake-original.lua delete mode 100644 src/luarocks/build/originals/command-original.lua diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index 3d00a176..853b0318 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua @@ -8,9 +8,6 @@ local builtin = {} -local InstallDirs = i.InstallDirs - - diff --git a/src/luarocks/build/builtin.tl b/src/luarocks/build/builtin.tl index d052edf6..8bd92d87 100644 --- a/src/luarocks/build/builtin.tl +++ b/src/luarocks/build/builtin.tl @@ -7,9 +7,6 @@ end local type r = require("luarocks.core.types.rockspec") local type Rockspec = r.Rockspec -local type i = require("luarocks.core.types.installs") -local type InstallDirs = i.InstallDirs - local type b = require("luarocks.core.types.build") local type BuiltinBuild = b.BuiltinBuild local type Build = b.Build diff --git a/src/luarocks/build/cmake.lua b/src/luarocks/build/cmake.lua index ea245444..b7a4786e 100644 --- a/src/luarocks/build/cmake.lua +++ b/src/luarocks/build/cmake.lua @@ -1,30 +1,24 @@ -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 +--- Build back-end for CMake-based modules. local cmake = {} - local fs = require("luarocks.fs") local util = require("luarocks.util") local cfg = require("luarocks.core.cfg") - - - - - - - - - - +--- Driver function for the "cmake" build back-end. +-- @param rockspec table: the loaded rockspec. +-- @return boolean or (nil, string): true if no errors occurred, +-- nil and an error message otherwise. function cmake.run(rockspec, no_install) + assert(rockspec:type() == "rockspec") local build = rockspec.build local variables = build.variables or {} - - variables.CMAKE_MODULE_PATH = os.getenv("CMAKE_MODULE_PATH") - variables.CMAKE_LIBRARY_PATH = os.getenv("CMAKE_LIBRARY_PATH") - variables.CMAKE_INCLUDE_PATH = os.getenv("CMAKE_INCLUDE_PATH") + -- Pass Env variables + variables.CMAKE_MODULE_PATH=os.getenv("CMAKE_MODULE_PATH") + variables.CMAKE_LIBRARY_PATH=os.getenv("CMAKE_LIBRARY_PATH") + variables.CMAKE_INCLUDE_PATH=os.getenv("CMAKE_INCLUDE_PATH") util.variable_substitutions(variables, rockspec.variables) @@ -33,35 +27,34 @@ function cmake.run(rockspec, no_install) return nil, err_msg end - - local build_cmake = build.cmake - if type(build_cmake) == "string" then - local cmake_handler = assert((io.open(fs.current_dir() .. "/CMakeLists.txt", "w"))) + -- If inline cmake is present create CMakeLists.txt from it. + if type(build.cmake) == "string" then + local cmake_handler = assert(io.open(fs.current_dir().."/CMakeLists.txt", "w")) cmake_handler:write(build.cmake) cmake_handler:close() end - + -- Execute cmake with variables. local args = "" - + -- Try to pick the best generator. With msvc and x64, CMake does not select it by default so we need to be explicit. if cfg.cmake_generator then - args = args .. ' -G"' .. cfg.cmake_generator .. '"' + args = args .. ' -G"'..cfg.cmake_generator.. '"' elseif cfg.is_platform("windows") and cfg.target_cpu:match("x86_64$") then args = args .. " -DCMAKE_GENERATOR_PLATFORM=x64" end - for k, v in pairs(variables) do - args = args .. ' -D' .. k .. '="' .. tostring(v) .. '"' + for k,v in pairs(variables) do + args = args .. ' -D' ..k.. '="' ..tostring(v).. '"' end - if not fs.execute_string(rockspec.variables.CMAKE .. " -H. -Bbuild.luarocks " .. args) then + if not fs.execute_string(rockspec.variables.CMAKE.." -H. -Bbuild.luarocks "..args) then return nil, "Failed cmake." end local do_build, do_install if rockspec:format_is_at_least("3.0") then - do_build = (build.build_pass == nil) and true or build.build_pass + do_build = (build.build_pass == nil) and true or build.build_pass do_install = (build.install_pass == nil) and true or build.install_pass else do_build = true @@ -69,12 +62,12 @@ function cmake.run(rockspec, no_install) end if do_build then - if not fs.execute_string(rockspec.variables.CMAKE .. " --build build.luarocks --config Release") then + if not fs.execute_string(rockspec.variables.CMAKE.." --build build.luarocks --config Release") then return nil, "Failed building." end end if do_install and not no_install then - if not fs.execute_string(rockspec.variables.CMAKE .. " --build build.luarocks --target install --config Release") then + if not fs.execute_string(rockspec.variables.CMAKE.." --build build.luarocks --target install --config Release") then return nil, "Failed installing." end end diff --git a/src/luarocks/build/command.lua b/src/luarocks/build/command.lua index 181bc56b..b0c4aa79 100644 --- a/src/luarocks/build/command.lua +++ b/src/luarocks/build/command.lua @@ -1,23 +1,17 @@ - +--- Build back-end for raw listing of commands in rockspec files. local command = {} - local fs = require("luarocks.fs") local util = require("luarocks.util") local cfg = require("luarocks.core.cfg") - - - - - - - - - - +--- Driver function for the "command" build back-end. +-- @param rockspec table: the loaded rockspec. +-- @return boolean or (nil, string): true if no errors occurred, +-- nil and an error message otherwise. function command.run(rockspec, not_install) + assert(rockspec:type() == "rockspec") local build = rockspec.build @@ -25,8 +19,8 @@ function command.run(rockspec, not_install) local env = { CC = cfg.variables.CC, - - + --LD = cfg.variables.LD, + --CFLAGS = cfg.variables.CFLAGS, } if build.build_command then diff --git a/src/luarocks/build/originals/cmake-original.lua b/src/luarocks/build/originals/cmake-original.lua deleted file mode 100644 index b7a4786e..00000000 --- a/src/luarocks/build/originals/cmake-original.lua +++ /dev/null @@ -1,78 +0,0 @@ - ---- Build back-end for CMake-based modules. -local cmake = {} - -local fs = require("luarocks.fs") -local util = require("luarocks.util") -local cfg = require("luarocks.core.cfg") - ---- Driver function for the "cmake" build back-end. --- @param rockspec table: the loaded rockspec. --- @return boolean or (nil, string): true if no errors occurred, --- nil and an error message otherwise. -function cmake.run(rockspec, no_install) - assert(rockspec:type() == "rockspec") - local build = rockspec.build - local variables = build.variables or {} - - -- Pass Env variables - variables.CMAKE_MODULE_PATH=os.getenv("CMAKE_MODULE_PATH") - variables.CMAKE_LIBRARY_PATH=os.getenv("CMAKE_LIBRARY_PATH") - variables.CMAKE_INCLUDE_PATH=os.getenv("CMAKE_INCLUDE_PATH") - - util.variable_substitutions(variables, rockspec.variables) - - local ok, err_msg = fs.is_tool_available(rockspec.variables.CMAKE, "CMake") - if not ok then - return nil, err_msg - end - - -- If inline cmake is present create CMakeLists.txt from it. - if type(build.cmake) == "string" then - local cmake_handler = assert(io.open(fs.current_dir().."/CMakeLists.txt", "w")) - cmake_handler:write(build.cmake) - cmake_handler:close() - end - - -- Execute cmake with variables. - local args = "" - - -- Try to pick the best generator. With msvc and x64, CMake does not select it by default so we need to be explicit. - if cfg.cmake_generator then - args = args .. ' -G"'..cfg.cmake_generator.. '"' - elseif cfg.is_platform("windows") and cfg.target_cpu:match("x86_64$") then - args = args .. " -DCMAKE_GENERATOR_PLATFORM=x64" - end - - for k,v in pairs(variables) do - args = args .. ' -D' ..k.. '="' ..tostring(v).. '"' - end - - if not fs.execute_string(rockspec.variables.CMAKE.." -H. -Bbuild.luarocks "..args) then - return nil, "Failed cmake." - end - - local do_build, do_install - if rockspec:format_is_at_least("3.0") then - do_build = (build.build_pass == nil) and true or build.build_pass - do_install = (build.install_pass == nil) and true or build.install_pass - else - do_build = true - do_install = true - end - - if do_build then - if not fs.execute_string(rockspec.variables.CMAKE.." --build build.luarocks --config Release") then - return nil, "Failed building." - end - end - if do_install and not no_install then - if not fs.execute_string(rockspec.variables.CMAKE.." --build build.luarocks --target install --config Release") then - return nil, "Failed installing." - end - end - - return true -end - -return cmake diff --git a/src/luarocks/build/originals/command-original.lua b/src/luarocks/build/originals/command-original.lua deleted file mode 100644 index b0c4aa79..00000000 --- a/src/luarocks/build/originals/command-original.lua +++ /dev/null @@ -1,41 +0,0 @@ - ---- Build back-end for raw listing of commands in rockspec files. -local command = {} - -local fs = require("luarocks.fs") -local util = require("luarocks.util") -local cfg = require("luarocks.core.cfg") - ---- Driver function for the "command" build back-end. --- @param rockspec table: the loaded rockspec. --- @return boolean or (nil, string): true if no errors occurred, --- nil and an error message otherwise. -function command.run(rockspec, not_install) - assert(rockspec:type() == "rockspec") - - local build = rockspec.build - - util.variable_substitutions(build, rockspec.variables) - - local env = { - CC = cfg.variables.CC, - --LD = cfg.variables.LD, - --CFLAGS = cfg.variables.CFLAGS, - } - - if build.build_command then - util.printout(build.build_command) - if not fs.execute_env(env, build.build_command) then - return nil, "Failed building." - end - end - if build.install_command and not not_install then - util.printout(build.install_command) - if not fs.execute_env(env, build.install_command) then - return nil, "Failed installing." - end - end - return true -end - -return command -- cgit v1.2.3-55-g6feb