aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-15 19:20:08 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-15 19:20:08 +0300
commitee2e5e5c8f3dc529ad4308b8cfd6b43105eaebcf (patch)
treec52cacd05a4427b354450e0b9f89005f3752b65f
parent61859a26e530969d5b5662dba075535a640cec09 (diff)
downloadluarocks-ee2e5e5c8f3dc529ad4308b8cfd6b43105eaebcf.tar.gz
luarocks-ee2e5e5c8f3dc529ad4308b8cfd6b43105eaebcf.tar.bz2
luarocks-ee2e5e5c8f3dc529ad4308b8cfd6b43105eaebcf.zip
build
-rw-r--r--src/luarocks/build/builtin.lua3
-rw-r--r--src/luarocks/build/builtin.tl3
-rw-r--r--src/luarocks/build/cmake.lua51
-rw-r--r--src/luarocks/build/command.lua22
-rw-r--r--src/luarocks/build/originals/cmake-original.lua78
-rw-r--r--src/luarocks/build/originals/command-original.lua41
6 files changed, 30 insertions, 168 deletions
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 = {}
8 8
9 9
10 10
11local InstallDirs = i.InstallDirs
12
13
14 11
15 12
16 13
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
7local type r = require("luarocks.core.types.rockspec") 7local type r = require("luarocks.core.types.rockspec")
8local type Rockspec = r.Rockspec 8local type Rockspec = r.Rockspec
9 9
10local type i = require("luarocks.core.types.installs")
11local type InstallDirs = i.InstallDirs
12
13local type b = require("luarocks.core.types.build") 10local type b = require("luarocks.core.types.build")
14local type BuiltinBuild = b.BuiltinBuild 11local type BuiltinBuild = b.BuiltinBuild
15local type Build = b.Build 12local 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 @@
1local _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
2 1
2--- Build back-end for CMake-based modules.
3local cmake = {} 3local cmake = {}
4 4
5
6local fs = require("luarocks.fs") 5local fs = require("luarocks.fs")
7local util = require("luarocks.util") 6local util = require("luarocks.util")
8local cfg = require("luarocks.core.cfg") 7local cfg = require("luarocks.core.cfg")
9 8
10 9--- Driver function for the "cmake" build back-end.
11 10-- @param rockspec table: the loaded rockspec.
12 11-- @return boolean or (nil, string): true if no errors occurred,
13 12-- nil and an error message otherwise.
14
15
16
17
18
19
20function cmake.run(rockspec, no_install) 13function cmake.run(rockspec, no_install)
14 assert(rockspec:type() == "rockspec")
21 local build = rockspec.build 15 local build = rockspec.build
22 local variables = build.variables or {} 16 local variables = build.variables or {}
23 17
24 18 -- Pass Env variables
25 variables.CMAKE_MODULE_PATH = os.getenv("CMAKE_MODULE_PATH") 19 variables.CMAKE_MODULE_PATH=os.getenv("CMAKE_MODULE_PATH")
26 variables.CMAKE_LIBRARY_PATH = os.getenv("CMAKE_LIBRARY_PATH") 20 variables.CMAKE_LIBRARY_PATH=os.getenv("CMAKE_LIBRARY_PATH")
27 variables.CMAKE_INCLUDE_PATH = os.getenv("CMAKE_INCLUDE_PATH") 21 variables.CMAKE_INCLUDE_PATH=os.getenv("CMAKE_INCLUDE_PATH")
28 22
29 util.variable_substitutions(variables, rockspec.variables) 23 util.variable_substitutions(variables, rockspec.variables)
30 24
@@ -33,35 +27,34 @@ function cmake.run(rockspec, no_install)
33 return nil, err_msg 27 return nil, err_msg
34 end 28 end
35 29
36 30 -- If inline cmake is present create CMakeLists.txt from it.
37 local build_cmake = build.cmake 31 if type(build.cmake) == "string" then
38 if type(build_cmake) == "string" then 32 local cmake_handler = assert(io.open(fs.current_dir().."/CMakeLists.txt", "w"))
39 local cmake_handler = assert((io.open(fs.current_dir() .. "/CMakeLists.txt", "w")))
40 cmake_handler:write(build.cmake) 33 cmake_handler:write(build.cmake)
41 cmake_handler:close() 34 cmake_handler:close()
42 end 35 end
43 36
44 37 -- Execute cmake with variables.
45 local args = "" 38 local args = ""
46 39
47 40 -- Try to pick the best generator. With msvc and x64, CMake does not select it by default so we need to be explicit.
48 if cfg.cmake_generator then 41 if cfg.cmake_generator then
49 args = args .. ' -G"' .. cfg.cmake_generator .. '"' 42 args = args .. ' -G"'..cfg.cmake_generator.. '"'
50 elseif cfg.is_platform("windows") and cfg.target_cpu:match("x86_64$") then 43 elseif cfg.is_platform("windows") and cfg.target_cpu:match("x86_64$") then
51 args = args .. " -DCMAKE_GENERATOR_PLATFORM=x64" 44 args = args .. " -DCMAKE_GENERATOR_PLATFORM=x64"
52 end 45 end
53 46
54 for k, v in pairs(variables) do 47 for k,v in pairs(variables) do
55 args = args .. ' -D' .. k .. '="' .. tostring(v) .. '"' 48 args = args .. ' -D' ..k.. '="' ..tostring(v).. '"'
56 end 49 end
57 50
58 if not fs.execute_string(rockspec.variables.CMAKE .. " -H. -Bbuild.luarocks " .. args) then 51 if not fs.execute_string(rockspec.variables.CMAKE.." -H. -Bbuild.luarocks "..args) then
59 return nil, "Failed cmake." 52 return nil, "Failed cmake."
60 end 53 end
61 54
62 local do_build, do_install 55 local do_build, do_install
63 if rockspec:format_is_at_least("3.0") then 56 if rockspec:format_is_at_least("3.0") then
64 do_build = (build.build_pass == nil) and true or build.build_pass 57 do_build = (build.build_pass == nil) and true or build.build_pass
65 do_install = (build.install_pass == nil) and true or build.install_pass 58 do_install = (build.install_pass == nil) and true or build.install_pass
66 else 59 else
67 do_build = true 60 do_build = true
@@ -69,12 +62,12 @@ function cmake.run(rockspec, no_install)
69 end 62 end
70 63
71 if do_build then 64 if do_build then
72 if not fs.execute_string(rockspec.variables.CMAKE .. " --build build.luarocks --config Release") then 65 if not fs.execute_string(rockspec.variables.CMAKE.." --build build.luarocks --config Release") then
73 return nil, "Failed building." 66 return nil, "Failed building."
74 end 67 end
75 end 68 end
76 if do_install and not no_install then 69 if do_install and not no_install then
77 if not fs.execute_string(rockspec.variables.CMAKE .. " --build build.luarocks --target install --config Release") then 70 if not fs.execute_string(rockspec.variables.CMAKE.." --build build.luarocks --target install --config Release") then
78 return nil, "Failed installing." 71 return nil, "Failed installing."
79 end 72 end
80 end 73 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 @@
1 1
2 2--- Build back-end for raw listing of commands in rockspec files.
3local command = {} 3local command = {}
4 4
5
6local fs = require("luarocks.fs") 5local fs = require("luarocks.fs")
7local util = require("luarocks.util") 6local util = require("luarocks.util")
8local cfg = require("luarocks.core.cfg") 7local cfg = require("luarocks.core.cfg")
9 8
10 9--- Driver function for the "command" build back-end.
11 10-- @param rockspec table: the loaded rockspec.
12 11-- @return boolean or (nil, string): true if no errors occurred,
13 12-- nil and an error message otherwise.
14
15
16
17
18
19
20function command.run(rockspec, not_install) 13function command.run(rockspec, not_install)
14 assert(rockspec:type() == "rockspec")
21 15
22 local build = rockspec.build 16 local build = rockspec.build
23 17
@@ -25,8 +19,8 @@ function command.run(rockspec, not_install)
25 19
26 local env = { 20 local env = {
27 CC = cfg.variables.CC, 21 CC = cfg.variables.CC,
28 22 --LD = cfg.variables.LD,
29 23 --CFLAGS = cfg.variables.CFLAGS,
30 } 24 }
31 25
32 if build.build_command then 26 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 @@
1
2--- Build back-end for CMake-based modules.
3local cmake = {}
4
5local fs = require("luarocks.fs")
6local util = require("luarocks.util")
7local 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.
13function 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
76end
77
78return 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 @@
1
2--- Build back-end for raw listing of commands in rockspec files.
3local command = {}
4
5local fs = require("luarocks.fs")
6local util = require("luarocks.util")
7local 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.
13function 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
39end
40
41return command