aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-15 19:25:34 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-15 19:25:34 +0300
commitc64e6b23b630c52ed28f581376cdb10c9360fd54 (patch)
tree863c8959815850d65038846d6a5e98670795e477
parentee2e5e5c8f3dc529ad4308b8cfd6b43105eaebcf (diff)
downloadluarocks-c64e6b23b630c52ed28f581376cdb10c9360fd54.tar.gz
luarocks-c64e6b23b630c52ed28f581376cdb10c9360fd54.tar.bz2
luarocks-c64e6b23b630c52ed28f581376cdb10c9360fd54.zip
build_cmake, build_command
-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
4 files changed, 162 insertions, 30 deletions
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 @@
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
1 2
2--- Build back-end for CMake-based modules.
3local cmake = {} 3local cmake = {}
4 4
5
5local fs = require("luarocks.fs") 6local fs = require("luarocks.fs")
6local util = require("luarocks.util") 7local util = require("luarocks.util")
7local cfg = require("luarocks.core.cfg") 8local 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
13function cmake.run(rockspec, no_install) 20function 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/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
3local command = {} 3local command = {}
4 4
5
5local fs = require("luarocks.fs") 6local fs = require("luarocks.fs")
6local util = require("luarocks.util") 7local util = require("luarocks.util")
7local cfg = require("luarocks.core.cfg") 8local 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
13function command.run(rockspec, not_install) 20function 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/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.
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
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.
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