aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/luarocks/build/cmake.lua5
-rw-r--r--src/luarocks/build/cmake.tl5
-rw-r--r--src/luarocks/cmd/upload.lua5
-rw-r--r--src/luarocks/cmd/upload.tl3
-rw-r--r--src/luarocks/core/cfg.lua15
-rw-r--r--src/luarocks/core/manif.lua11
-rw-r--r--src/luarocks/core/manif.tl9
-rw-r--r--src/luarocks/core/persist.lua30
-rw-r--r--src/luarocks/core/persist.tl30
-rw-r--r--src/luarocks/deps.lua21
-rw-r--r--src/luarocks/deps.tl25
-rw-r--r--src/luarocks/fetch.lua9
-rw-r--r--src/luarocks/fetch.tl9
-rw-r--r--src/luarocks/fs/unix.lua5
-rw-r--r--src/luarocks/manif.lua6
-rw-r--r--src/luarocks/manif.tl4
-rw-r--r--src/luarocks/rockspecs.lua19
-rw-r--r--src/luarocks/rockspecs.tl19
-rw-r--r--src/luarocks/tools/patch.lua11
-rw-r--r--src/luarocks/tools/patch.tl13
-rw-r--r--src/luarocks/type/rockspec.lua5
-rw-r--r--src/luarocks/type/rockspec.tl7
-rw-r--r--src/luarocks/vendor/dkjson.d.tl2
23 files changed, 204 insertions, 64 deletions
diff --git a/src/luarocks/build/cmake.lua b/src/luarocks/build/cmake.lua
index ea132a3e..b9954cf4 100644
--- a/src/luarocks/build/cmake.lua
+++ b/src/luarocks/build/cmake.lua
@@ -27,11 +27,6 @@ function cmake.run(rockspec, no_install)
27 local build = rockspec.build 27 local build = rockspec.build
28 local variables = build.variables or {} 28 local variables = build.variables or {}
29 29
30
31 variables.CMAKE_MODULE_PATH = os.getenv("CMAKE_MODULE_PATH")
32 variables.CMAKE_LIBRARY_PATH = os.getenv("CMAKE_LIBRARY_PATH")
33 variables.CMAKE_INCLUDE_PATH = os.getenv("CMAKE_INCLUDE_PATH")
34
35 util.variable_substitutions(variables, rockspec.variables) 30 util.variable_substitutions(variables, rockspec.variables)
36 31
37 local ok, err_msg = fs.is_tool_available(rockspec.variables.CMAKE, "CMake") 32 local ok, err_msg = fs.is_tool_available(rockspec.variables.CMAKE, "CMake")
diff --git a/src/luarocks/build/cmake.tl b/src/luarocks/build/cmake.tl
index 9a512d1e..35e64bd6 100644
--- a/src/luarocks/build/cmake.tl
+++ b/src/luarocks/build/cmake.tl
@@ -27,11 +27,6 @@ function cmake.run(rockspec: Rockspec, no_install: boolean): boolean, string, st
27 local build = rockspec.build as cmake.CMakeBuild 27 local build = rockspec.build as cmake.CMakeBuild
28 local variables = build.variables or {} 28 local variables = build.variables or {}
29 29
30 -- Pass Env variables
31 variables.CMAKE_MODULE_PATH=os.getenv("CMAKE_MODULE_PATH")
32 variables.CMAKE_LIBRARY_PATH=os.getenv("CMAKE_LIBRARY_PATH")
33 variables.CMAKE_INCLUDE_PATH=os.getenv("CMAKE_INCLUDE_PATH")
34
35 util.variable_substitutions(variables, rockspec.variables) 30 util.variable_substitutions(variables, rockspec.variables)
36 31
37 local ok, err_msg = fs.is_tool_available(rockspec.variables.CMAKE, "CMake") 32 local ok, err_msg = fs.is_tool_available(rockspec.variables.CMAKE, "CMake")
diff --git a/src/luarocks/cmd/upload.lua b/src/luarocks/cmd/upload.lua
index 755dd4e7..e4319bb1 100644
--- a/src/luarocks/cmd/upload.lua
+++ b/src/luarocks/cmd/upload.lua
@@ -1,4 +1,4 @@
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 string = _tl_compat and _tl_compat.string or string 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 math = _tl_compat and _tl_compat.math or math; local string = _tl_compat and _tl_compat.string or string
2local upload = { Response = { version = {} } } 2local upload = { Response = { version = {} } }
3 3
4 4
@@ -132,7 +132,8 @@ function upload.command(args)
132 return nil, "Invalid response from server." 132 return nil, "Invalid response from server."
133 end 133 end
134 util.printout(("Sending " .. tostring(rock_fname) .. " ...")) 134 util.printout(("Sending " .. tostring(rock_fname) .. " ..."))
135 res, err = api:method("upload_rock/" .. ("%d"):format(res.version.id), nil, { 135 local id = math.tointeger(res.version.id)
136 res, err = api:method("upload_rock/" .. ("%d"):format(id), nil, {
136 rock_file = multipart.new_file(rock_fname), 137 rock_file = multipart.new_file(rock_fname),
137 rock_sig = rock_sigfname and multipart.new_file(rock_sigfname), 138 rock_sig = rock_sigfname and multipart.new_file(rock_sigfname),
138 }) 139 })
diff --git a/src/luarocks/cmd/upload.tl b/src/luarocks/cmd/upload.tl
index 5b6e3314..a12b30c0 100644
--- a/src/luarocks/cmd/upload.tl
+++ b/src/luarocks/cmd/upload.tl
@@ -132,7 +132,8 @@ function upload.command(args: Args): boolean, string, string
132 return nil, "Invalid response from server." 132 return nil, "Invalid response from server."
133 end 133 end
134 util.printout(("Sending " .. tostring(rock_fname) .. " ...")) 134 util.printout(("Sending " .. tostring(rock_fname) .. " ..."))
135 res, err = api:method("upload_rock/" .. ("%d"):format(res.version.id), nil, { 135 local id = math.tointeger(res.version.id)
136 res, err = api:method("upload_rock/" .. ("%d"):format(id), nil, {
136 rock_file = multipart.new_file(rock_fname), 137 rock_file = multipart.new_file(rock_fname),
137 rock_sig = rock_sigfname and multipart.new_file(rock_sigfname), 138 rock_sig = rock_sigfname and multipart.new_file(rock_sigfname),
138 }) as (Response, string) 139 }) as (Response, string)
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua
index 8c2d7d79..7e1294cd 100644
--- a/src/luarocks/core/cfg.lua
+++ b/src/luarocks/core/cfg.lua
@@ -21,7 +21,7 @@ local vers = require("luarocks.core.vers")
21 21
22-------------------------------------------------------------------------------- 22--------------------------------------------------------------------------------
23 23
24local program_version = "dev" 24local program_version = "3.12.2"
25 25
26local is_windows = package.config:sub(1,1) == "\\" 26local is_windows = package.config:sub(1,1) == "\\"
27 27
@@ -413,13 +413,24 @@ local function make_defaults(lua_version, target_cpu, platforms, home)
413 end 413 end
414 414
415 if platforms.cygwin then 415 if platforms.cygwin then
416 defaults.lib_extension = "so" -- can be overridden in the config file for mingw builds 416 defaults.lib_extension = "dll"
417 defaults.arch = "cygwin-"..target_cpu 417 defaults.arch = "cygwin-"..target_cpu
418 defaults.cmake_generator = "Unix Makefiles" 418 defaults.cmake_generator = "Unix Makefiles"
419 defaults.variables.CC = "echo -llua | xargs " .. (os.getenv("CC") or "gcc") 419 defaults.variables.CC = "echo -llua | xargs " .. (os.getenv("CC") or "gcc")
420 defaults.variables.LD = "echo -llua | xargs " .. (os.getenv("CC") or "gcc") 420 defaults.variables.LD = "echo -llua | xargs " .. (os.getenv("CC") or "gcc")
421 defaults.variables.LIBFLAG = "-shared" 421 defaults.variables.LIBFLAG = "-shared"
422 defaults.link_lua_explicitly = true 422 defaults.link_lua_explicitly = true
423 defaults.external_deps_patterns = {
424 bin = { "?.exe", "?.bat", "?" },
425 lib = { "cyg?.dll", "lib?.so", "lib?.so.*", "lib?.dll.a", "?.dll.a",
426 "lib?.a", "lib?.dll", "?.dll" },
427 include = { "?.h" }
428 }
429 defaults.runtime_external_deps_patterns = {
430 bin = { "?.exe", "?.bat" },
431 lib = { "cyg?.dll", "lib?.so", "?.dll", "lib?.dll" },
432 include = { "?.h" }
433 }
423 end 434 end
424 435
425 if platforms.msys then 436 if platforms.msys then
diff --git a/src/luarocks/core/manif.lua b/src/luarocks/core/manif.lua
index 4c5e0441..c5ee158e 100644
--- a/src/luarocks/core/manif.lua
+++ b/src/luarocks/core/manif.lua
@@ -1,4 +1,4 @@
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 ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local table = _tl_compat and _tl_compat.table or table; local type = type 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 ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local string = _tl_compat and _tl_compat.string or string; local table = _tl_compat and _tl_compat.table or table; local type = type
2 2
3local manif = {} 3local manif = {}
4 4
@@ -52,7 +52,14 @@ end
52 52
53 53
54function manif.manifest_loader(file, repo_url, lua_version) 54function manif.manifest_loader(file, repo_url, lua_version)
55 local manifest, err, errcode = persist.load_into_table(file) 55 local manifest, err, errcode
56
57 if file:match(".*%.json$") then
58 manifest, err, errcode = persist.load_json_into_table(file)
59 else
60 manifest, err, errcode = persist.load_into_table(file)
61 end
62
56 if not manifest and type(err) == "string" then 63 if not manifest and type(err) == "string" then
57 return nil, "Failed loading manifest for " .. repo_url .. ": " .. err, errcode 64 return nil, "Failed loading manifest for " .. repo_url .. ": " .. err, errcode
58 end 65 end
diff --git a/src/luarocks/core/manif.tl b/src/luarocks/core/manif.tl
index 1f3b3659..0a96d47e 100644
--- a/src/luarocks/core/manif.tl
+++ b/src/luarocks/core/manif.tl
@@ -52,7 +52,14 @@ end
52-- @return table or (nil, string, string): the manifest or nil, 52-- @return table or (nil, string, string): the manifest or nil,
53-- error message and error code ("open", "load", "run"). 53-- error message and error code ("open", "load", "run").
54function manif.manifest_loader(file: string, repo_url: string, lua_version: string): Manifest, string | {any: any}, string 54function manif.manifest_loader(file: string, repo_url: string, lua_version: string): Manifest, string | {any: any}, string
55 local manifest, err, errcode = persist.load_into_table(file) 55 local manifest, err, errcode: {string: any}, {string: boolean} | string, string
56
57 if file:match(".*%.json$") then
58 manifest, err, errcode = persist.load_json_into_table(file)
59 else
60 manifest, err, errcode = persist.load_into_table(file)
61 end
62
56 if not manifest and err is string then 63 if not manifest and err is string then
57 return nil, "Failed loading manifest for "..repo_url..": " .. err, errcode 64 return nil, "Failed loading manifest for "..repo_url..": " .. err, errcode
58 end 65 end
diff --git a/src/luarocks/core/persist.lua b/src/luarocks/core/persist.lua
index 258a42c0..c9ccb4a0 100644
--- a/src/luarocks/core/persist.lua
+++ b/src/luarocks/core/persist.lua
@@ -2,6 +2,8 @@ local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 th
2local persist = {} 2local persist = {}
3 3
4 4
5local json = require("luarocks.vendor.dkjson")
6
5 7
6 8
7 9
@@ -67,4 +69,32 @@ function persist.load_into_table(filename, tbl)
67 return result, globals 69 return result, globals
68end 70end
69 71
72
73
74
75
76
77
78
79
80
81
82function persist.load_json_into_table(filename)
83 local fd, open_err = io.open(filename)
84 if not fd then
85 return nil, open_err, "open"
86 end
87 local str, read_err = fd:read("*a")
88 fd:close()
89 if not str then
90 return nil, read_err, "open"
91 end
92 local manifest, _, err = json.decode(str)
93 if not manifest then
94 return nil, "Failed decode manifest: " .. err, "load"
95 end
96
97 return manifest, {}
98end
99
70return persist 100return persist
diff --git a/src/luarocks/core/persist.tl b/src/luarocks/core/persist.tl
index 4694afcb..268d2bb6 100644
--- a/src/luarocks/core/persist.tl
+++ b/src/luarocks/core/persist.tl
@@ -2,6 +2,8 @@
2local record persist 2local record persist
3end 3end
4 4
5local json = require("luarocks.vendor.dkjson")
6
5-------------------------------------------------------------------------------- 7--------------------------------------------------------------------------------
6 8
7--- Load and run a Lua file in an environment. 9--- Load and run a Lua file in an environment.
@@ -67,5 +69,33 @@ function persist.load_into_table(filename: string, tbl?: {string:any}) : {string
67 return result, globals 69 return result, globals
68end 70end
69 71
72--- Load a JSON file containing assignments, storing them in a table.
73-- The global environment is not propagated to the loaded file.
74-- @param filename string: the name of the file.
75-- @param tbl table or nil: if given, this table is used to store
76-- loaded values.
77-- @return (table, table) or (nil, string, string): a table with the file's assignments
78-- as fields and set of undefined globals accessed in file,
79-- or nil, an error message and an error code ("open"; couldn't open the file,
80-- "load"; compile-time error, or "run"; run-time error)
81-- in case of errors.
82function persist.load_json_into_table(filename: string) : {string: any}, {string: boolean} | string, string
83 local fd, open_err = io.open(filename)
84 if not fd then
85 return nil, open_err, "open"
86 end
87 local str, read_err = fd:read("*a")
88 fd:close()
89 if not str then
90 return nil, read_err, "open"
91 end
92 local manifest, _, err = json.decode(str)
93 if not manifest then
94 return nil, "Failed decode manifest: " .. err, "load"
95 end
96
97 return manifest, {}
98end
99
70return persist 100return persist
71 101
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua
index e02d4694..13b531f6 100644
--- a/src/luarocks/deps.lua
+++ b/src/luarocks/deps.lua
@@ -1,4 +1,4 @@
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 ipairs = _tl_compat and _tl_compat.ipairs or ipairs; 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 type = type 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 ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local math = _tl_compat and _tl_compat.math or math; 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 type = type
2 2
3local deps = {} 3local deps = {}
4 4
@@ -201,7 +201,7 @@ function deps.report_missing_dependencies(name, version, dependencies, deps_mode
201 first_missing_dep = false 201 first_missing_dep = false
202 end 202 end
203 203
204 util.printout((" %s (%s)"):format(tostring(depq), rock_status(depq, get_versions))) 204 util.printout((" %s (%s)"):format(tostring(depq), (rock_status(depq, get_versions))))
205 end 205 end
206 end 206 end
207end 207end
@@ -301,7 +301,7 @@ function deps.fulfill_dependencies(rockspec, depskey, deps_mode, verify, deplock
301 local depq = queries.new(dname, dnamespace, dversion) 301 local depq = queries.new(dname, dnamespace, dversion)
302 302
303 util.printout(("%s %s is pinned to %s (%s)"):format( 303 util.printout(("%s %s is pinned to %s (%s)"):format(
304 name, version, tostring(depq), rock_status(depq, get_versions))) 304 name, version, tostring(depq), (rock_status(depq, get_versions))))
305 305
306 local okfullfill, errfullfill = deps.fulfill_dependency(depq, "none", rocks_provided, verify, depskey) 306 local okfullfill, errfullfill = deps.fulfill_dependency(depq, "none", rocks_provided, verify, depskey)
307 if not okfullfill then 307 if not okfullfill then
@@ -327,11 +327,14 @@ function deps.fulfill_dependencies(rockspec, depskey, deps_mode, verify, deplock
327 for _, depq in ipairs((rockspec)[depskey].queries) do 327 for _, depq in ipairs((rockspec)[depskey].queries) do
328 328
329 util.printout(("%s %s depends on %s (%s)"):format( 329 util.printout(("%s %s depends on %s (%s)"):format(
330 name, version, tostring(depq), rock_status(depq, get_versions))) 330 name, version, tostring(depq), (rock_status(depq, get_versions))))
331 331
332 local okfulfill, found_or_err, _ = deps.fulfill_dependency(depq, deps_mode, rocks_provided, verify, depskey) 332 local okfulfill, version_or_err, tree = deps.fulfill_dependency(depq, deps_mode, rocks_provided, verify, depskey)
333 if okfulfill then 333 if okfulfill then
334 deplocks.add(depskey, depq.name, found_or_err) 334 deplocks.add(depskey, depq.name, version_or_err)
335 if tree and rockspec:format_is_at_least("3.1") then
336 rockspec.variables[depq.name:upper() .. "_ROCKDIR"] = path.install_dir(depq.name, version_or_err, tree)
337 end
335 else 338 else
336 if depq.constraints and depq.constraints[1] and depq.constraints[1].no_upgrade then 339 if depq.constraints and depq.constraints[1] and depq.constraints[1].no_upgrade then
337 util.printerr("This version of " .. name .. " is designed for use with") 340 util.printerr("This version of " .. name .. " is designed for use with")
@@ -341,7 +344,7 @@ function deps.fulfill_dependencies(rockspec, depskey, deps_mode, verify, deplock
341 util.printerr("or look for a suitable version of " .. name .. " with") 344 util.printerr("or look for a suitable version of " .. name .. " with")
342 util.printerr(" luarocks search " .. name) 345 util.printerr(" luarocks search " .. name)
343 end 346 end
344 return nil, found_or_err 347 return nil, version_or_err
345 end 348 end
346 end 349 end
347 350
@@ -703,7 +706,7 @@ end
703 706
704local function lua_h_exists(d, luaver) 707local function lua_h_exists(d, luaver)
705 local major, minor = luaver:match("(%d+)%.(%d+)") 708 local major, minor = luaver:match("(%d+)%.(%d+)")
706 local luanum = ("%s%02d"):format(major, tonumber(minor)) 709 local luanum = ("%s%02d"):format(major, math.tointeger(minor))
707 710
708 local lua_h = dir.path(d, "lua.h") 711 local lua_h = dir.path(d, "lua.h")
709 local fd = io.open(lua_h) 712 local fd = io.open(lua_h)
@@ -808,7 +811,7 @@ function deps.check_lua_libdir(vars)
808 local err 811 local err
809 if ok then 812 if ok then
810 local filename = dir.path(vars.LUA_LIBDIR, vars.LUA_LIBDIR_FILE) 813 local filename = dir.path(vars.LUA_LIBDIR, vars.LUA_LIBDIR_FILE)
811 local fd = io.open(filename, "r") 814 local fd = io.open(filename, "rb")
812 if fd then 815 if fd then
813 if not vars.LUA_LIBDIR_FILE:match((cfg.lua_version:gsub("%.", "%%.?"))) then 816 if not vars.LUA_LIBDIR_FILE:match((cfg.lua_version:gsub("%.", "%%.?"))) then
814 817
diff --git a/src/luarocks/deps.tl b/src/luarocks/deps.tl
index 5ca9c879..98fad54d 100644
--- a/src/luarocks/deps.tl
+++ b/src/luarocks/deps.tl
@@ -201,7 +201,7 @@ function deps.report_missing_dependencies(name: string, version: string, depende
201 first_missing_dep = false 201 first_missing_dep = false
202 end 202 end
203 203
204 util.printout((" %s (%s)"):format(tostring(depq), rock_status(depq, get_versions))) 204 util.printout((" %s (%s)"):format(tostring(depq), (rock_status(depq, get_versions))))
205 end 205 end
206 end 206 end
207end 207end
@@ -301,7 +301,7 @@ function deps.fulfill_dependencies(rockspec: Rockspec, depskey: DepsKey, deps_mo
301 local depq = queries.new(dname, dnamespace, dversion) 301 local depq = queries.new(dname, dnamespace, dversion)
302 302
303 util.printout(("%s %s is pinned to %s (%s)"):format( 303 util.printout(("%s %s is pinned to %s (%s)"):format(
304 name, version, tostring(depq), rock_status(depq, get_versions))) 304 name, version, tostring(depq), (rock_status(depq, get_versions))))
305 305
306 local okfullfill, errfullfill = deps.fulfill_dependency(depq, "none", rocks_provided, verify, depskey) 306 local okfullfill, errfullfill = deps.fulfill_dependency(depq, "none", rocks_provided, verify, depskey)
307 if not okfullfill then 307 if not okfullfill then
@@ -327,11 +327,14 @@ function deps.fulfill_dependencies(rockspec: Rockspec, depskey: DepsKey, deps_mo
327 for _, depq in ipairs((rockspec as {string: Dependencies})[depskey].queries) do 327 for _, depq in ipairs((rockspec as {string: Dependencies})[depskey].queries) do
328 328
329 util.printout(("%s %s depends on %s (%s)"):format( 329 util.printout(("%s %s depends on %s (%s)"):format(
330 name, version, tostring(depq), rock_status(depq, get_versions))) 330 name, version, tostring(depq), (rock_status(depq, get_versions))))
331 331
332 local okfulfill, found_or_err, _ = deps.fulfill_dependency(depq, deps_mode, rocks_provided, verify, depskey) 332 local okfulfill, version_or_err, tree = deps.fulfill_dependency(depq, deps_mode, rocks_provided, verify, depskey)
333 if okfulfill then 333 if okfulfill then
334 deplocks.add(depskey, depq.name, found_or_err) 334 deplocks.add(depskey, depq.name, version_or_err)
335 if tree and rockspec:format_is_at_least("3.1") then
336 rockspec.variables[depq.name:upper() .. "_ROCKDIR"] = path.install_dir(depq.name, version_or_err, tree)
337 end
335 else 338 else
336 if depq.constraints and depq.constraints[1] and depq.constraints[1].no_upgrade then 339 if depq.constraints and depq.constraints[1] and depq.constraints[1].no_upgrade then
337 util.printerr("This version of "..name.." is designed for use with") 340 util.printerr("This version of "..name.." is designed for use with")
@@ -341,7 +344,7 @@ function deps.fulfill_dependencies(rockspec: Rockspec, depskey: DepsKey, deps_mo
341 util.printerr("or look for a suitable version of "..name.." with") 344 util.printerr("or look for a suitable version of "..name.." with")
342 util.printerr(" luarocks search "..name) 345 util.printerr(" luarocks search "..name)
343 end 346 end
344 return nil, found_or_err 347 return nil, version_or_err
345 end 348 end
346 end 349 end
347 350
@@ -703,7 +706,7 @@ end
703 706
704local function lua_h_exists(d: string, luaver: string): boolean, string, string, integer 707local function lua_h_exists(d: string, luaver: string): boolean, string, string, integer
705 local major, minor = luaver:match("(%d+)%.(%d+)") 708 local major, minor = luaver:match("(%d+)%.(%d+)")
706 local luanum = ("%s%02d"):format(major, tonumber(minor)) 709 local luanum = ("%s%02d"):format(major, math.tointeger(minor))
707 710
708 local lua_h = dir.path(d, "lua.h") 711 local lua_h = dir.path(d, "lua.h")
709 local fd = io.open(lua_h) 712 local fd = io.open(lua_h)
@@ -749,7 +752,7 @@ local function find_lua_incdir(prefix: string, luaver: string, luajitver: string
749end 752end
750 753
751function deps.check_lua_incdir(vars: {string: string}): boolean, string, string 754function deps.check_lua_incdir(vars: {string: string}): boolean, string, string
752 if vars.LUA_INCDIR_OK == "ok" 755 if vars.LUA_INCDIR_OK == "ok"
753 then return true 756 then return true
754 end 757 end
755 758
@@ -777,7 +780,7 @@ function deps.check_lua_incdir(vars: {string: string}): boolean, string, string
777end 780end
778 781
779function deps.check_lua_libdir(vars: {string: string}): boolean, string, string, {string : {string}} 782function deps.check_lua_libdir(vars: {string: string}): boolean, string, string, {string : {string}}
780 if vars.LUA_LIBDIR_OK == "ok" 783 if vars.LUA_LIBDIR_OK == "ok"
781 then return true 784 then return true
782 end 785 end
783 786
@@ -808,13 +811,13 @@ function deps.check_lua_libdir(vars: {string: string}): boolean, string, string,
808 local err: string 811 local err: string
809 if ok then 812 if ok then
810 local filename = dir.path(vars.LUA_LIBDIR, vars.LUA_LIBDIR_FILE) 813 local filename = dir.path(vars.LUA_LIBDIR, vars.LUA_LIBDIR_FILE)
811 local fd = io.open(filename, "r") 814 local fd = io.open(filename, "rb")
812 if fd then 815 if fd then
813 if not vars.LUA_LIBDIR_FILE:match((cfg.lua_version:gsub("%.", "%%.?"))) then 816 if not vars.LUA_LIBDIR_FILE:match((cfg.lua_version:gsub("%.", "%%.?"))) then
814 -- if filename isn't versioned, check file contents 817 -- if filename isn't versioned, check file contents
815 local txt = fd:read("*a") 818 local txt = fd:read("*a")
816 ok = txt:find("Lua " .. cfg.lua_version, 1, true) 819 ok = txt:find("Lua " .. cfg.lua_version, 1, true)
817 or txt:find("lua" .. (cfg.lua_version:gsub("%.", "")), 1, true) 820 or txt:find("lua" .. (cfg.lua_version:gsub("%.", "")), 1, true)
818 and true 821 and true
819 if not ok then 822 if not ok then
820 err = "Lua library at " .. filename .. " does not match Lua version " .. cfg.lua_version .. ". You can use `luarocks config variables.LUA_LIBDIR <path>` to set the correct location." 823 err = "Lua library at " .. filename .. " does not match Lua version " .. cfg.lua_version .. ". You can use `luarocks config variables.LUA_LIBDIR <path>` to set the correct location."
diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua
index 07c4bf94..50363cc0 100644
--- a/src/luarocks/fetch.lua
+++ b/src/luarocks/fetch.lua
@@ -49,12 +49,15 @@ function fetch.fetch_caching(url, mirroring)
49 local repo_url, filename = url:match("^(.*)/([^/]+)$") 49 local repo_url, filename = url:match("^(.*)/([^/]+)$")
50 local name = repo_url:gsub("[/:]", "_") 50 local name = repo_url:gsub("[/:]", "_")
51 local cache_dir = dir.path(cfg.local_cache, name) 51 local cache_dir = dir.path(cfg.local_cache, name)
52 local ok = fs.make_dir(cache_dir) 52 local ok = fs.exists(cfg.local_cache)
53 if ok then
54 ok = fs.make_dir(cache_dir)
55 end
53 56
54 local cachefile = dir.path(cache_dir, filename) 57 local cachefile = dir.path(cache_dir, filename)
55 local checkfile = cachefile .. ".check" 58 local checkfile = cachefile .. ".check"
56 59
57 if (fs.file_age(checkfile) < 10 or 60 if (fs.exists(checkfile) and fs.file_age(checkfile) < 10 or
58 cfg.aggressive_cache and (not name:match("^manifest"))) and fs.exists(cachefile) then 61 cfg.aggressive_cache and (not name:match("^manifest"))) and fs.exists(cachefile) then
59 62
60 return cachefile, nil, nil, true 63 return cachefile, nil, nil, true
@@ -75,6 +78,8 @@ function fetch.fetch_caching(url, mirroring)
75 if not ok then 78 if not ok then
76 return nil, "Failed creating temporary cache directory " .. cache_dir 79 return nil, "Failed creating temporary cache directory " .. cache_dir
77 end 80 end
81 cachefile = dir.path(cache_dir, filename)
82 checkfile = cachefile .. ".check"
78 lock = fs.lock_access(cache_dir) 83 lock = fs.lock_access(cache_dir)
79 end 84 end
80 85
diff --git a/src/luarocks/fetch.tl b/src/luarocks/fetch.tl
index 2f81ac0c..75f0a157 100644
--- a/src/luarocks/fetch.tl
+++ b/src/luarocks/fetch.tl
@@ -49,12 +49,15 @@ function fetch.fetch_caching(url: string, mirroring?: string): string, string, s
49 local repo_url, filename = url:match("^(.*)/([^/]+)$") 49 local repo_url, filename = url:match("^(.*)/([^/]+)$")
50 local name = repo_url:gsub("[/:]","_") 50 local name = repo_url:gsub("[/:]","_")
51 local cache_dir = dir.path(cfg.local_cache, name) 51 local cache_dir = dir.path(cfg.local_cache, name)
52 local ok = fs.make_dir(cache_dir) 52 local ok = fs.exists(cfg.local_cache)
53 if ok then
54 ok = fs.make_dir(cache_dir)
55 end
53 56
54 local cachefile = dir.path(cache_dir, filename) 57 local cachefile = dir.path(cache_dir, filename)
55 local checkfile = cachefile .. ".check" 58 local checkfile = cachefile .. ".check"
56 59
57 if (fs.file_age(checkfile) < 10 or 60 if (fs.exists(checkfile) and fs.file_age(checkfile) < 10 or
58 cfg.aggressive_cache and (not name:match("^manifest"))) and fs.exists(cachefile) 61 cfg.aggressive_cache and (not name:match("^manifest"))) and fs.exists(cachefile)
59 then 62 then
60 return cachefile, nil, nil, true 63 return cachefile, nil, nil, true
@@ -75,6 +78,8 @@ function fetch.fetch_caching(url: string, mirroring?: string): string, string, s
75 if not ok then 78 if not ok then
76 return nil, "Failed creating temporary cache directory "..cache_dir 79 return nil, "Failed creating temporary cache directory "..cache_dir
77 end 80 end
81 cachefile = dir.path(cache_dir, filename)
82 checkfile = cachefile .. ".check"
78 lock = fs.lock_access(cache_dir) 83 lock = fs.lock_access(cache_dir)
79 end 84 end
80 85
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua
index 41a9ba8b..2c99ff0d 100644
--- a/src/luarocks/fs/unix.lua
+++ b/src/luarocks/fs/unix.lua
@@ -145,13 +145,14 @@ function unix.is_actual_binary(filename)
145 if not file then 145 if not file then
146 return true 146 return true
147 end 147 end
148 local first = file:read(2) 148 local first = file:read()
149 file:close() 149 file:close()
150 if not first then 150 if not first then
151 util.warning("could not read "..filename) 151 util.warning("could not read "..filename)
152 return true 152 return true
153 end 153 end
154 return first ~= "#!" 154 -- only create wrapper for lua scripts with `#!/usr/bin/env lua` or `#!/usr/bin/lua`
155 return first:match('^#!.*[ /]lua.*') == first
155end 156end
156 157
157function unix.copy_binary(filename, dest) 158function unix.copy_binary(filename, dest)
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua
index 809b823d..b608d363 100644
--- a/src/luarocks/manif.lua
+++ b/src/luarocks/manif.lua
@@ -1,4 +1,4 @@
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 ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local pairs = _tl_compat and _tl_compat.pairs or pairs; local string = _tl_compat and _tl_compat.string or string; local type = type 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 ipairs = _tl_compat and _tl_compat.ipairs or ipairs; 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 type = type
2 2
3 3
4 4
@@ -103,6 +103,10 @@ function manif.load_manifest(repo_url, lua_version, versioned_only)
103 not versioned_only and "manifest" or nil, 103 not versioned_only and "manifest" or nil,
104 } 104 }
105 105
106 if util.get_luajit_version() then
107 table.insert(filenames, 1, "manifest-" .. lua_version .. ".json")
108 end
109
106 local protocol, repodir = dir.split_url(repo_url) 110 local protocol, repodir = dir.split_url(repo_url)
107 local pathname, from_cache 111 local pathname, from_cache
108 if protocol == "file" then 112 if protocol == "file" then
diff --git a/src/luarocks/manif.tl b/src/luarocks/manif.tl
index 6a62a73f..da9b7d4c 100644
--- a/src/luarocks/manif.tl
+++ b/src/luarocks/manif.tl
@@ -103,6 +103,10 @@ function manif.load_manifest(repo_url: string, lua_version?: string, versioned_o
103 not versioned_only and "manifest" or nil, 103 not versioned_only and "manifest" or nil,
104 } 104 }
105 105
106 if util.get_luajit_version() then
107 table.insert(filenames, 1, "manifest-" .. lua_version .. ".json")
108 end
109
106 local protocol, repodir = dir.split_url(repo_url) 110 local protocol, repodir = dir.split_url(repo_url)
107 local pathname, from_cache: string, boolean 111 local pathname, from_cache: string, boolean
108 if protocol == "file" then 112 if protocol == "file" then
diff --git a/src/luarocks/rockspecs.lua b/src/luarocks/rockspecs.lua
index 6a9a376c..7f137b87 100644
--- a/src/luarocks/rockspecs.lua
+++ b/src/luarocks/rockspecs.lua
@@ -24,6 +24,19 @@ local vendored_build_type_set = {
24 ["none"] = true, 24 ["none"] = true,
25} 25}
26 26
27local rockspec_mt_funcs = {}
28
29local rockspec_mt = {}
30rockspec_mt.__index = rockspec_mt_funcs
31
32function rockspec_mt_funcs.type()
33 util.warning("The function rockspec.type() is no longer " ..
34 "necessary and is now deprecated. Please update your " ..
35 "plugin to remove calls to this function.")
36
37 return "rockspec"
38end
39
27 40
28 41
29 42
@@ -83,6 +96,9 @@ local function configure_paths(rockspec)
83 vars.CONFDIR = path.conf_dir(name, version) 96 vars.CONFDIR = path.conf_dir(name, version)
84 vars.BINDIR = path.bin_dir(name, version) 97 vars.BINDIR = path.bin_dir(name, version)
85 vars.DOCDIR = path.doc_dir(name, version) 98 vars.DOCDIR = path.doc_dir(name, version)
99 if rockspec:format_is_at_least("3.1") then
100 vars.LUA_VERSION = cfg.lua_version
101 end
86 rockspec.variables = vars 102 rockspec.variables = vars
87end 103end
88 104
@@ -178,7 +194,8 @@ function rockspecs.from_persisted_table(filename, rockspec, globals, quick)
178 configure_paths(rockspec) 194 configure_paths(rockspec)
179 end 195 end
180 196
181 return rockspec 197
198 return setmetatable(rockspec, rockspec_mt)
182end 199end
183 200
184return rockspecs 201return rockspecs
diff --git a/src/luarocks/rockspecs.tl b/src/luarocks/rockspecs.tl
index a34c0dbf..7f31f786 100644
--- a/src/luarocks/rockspecs.tl
+++ b/src/luarocks/rockspecs.tl
@@ -24,6 +24,19 @@ local vendored_build_type_set: {string: boolean} = {
24 ["none"] = true, 24 ["none"] = true,
25} 25}
26 26
27local rockspec_mt_funcs = {}
28
29local rockspec_mt: metatable<Rockspec> = {}
30rockspec_mt.__index = rockspec_mt_funcs
31
32function rockspec_mt_funcs.type(): string
33 util.warning("The function rockspec.type() is no longer " ..
34 "necessary and is now deprecated. Please update your " ..
35 "plugin to remove calls to this function.")
36
37 return "rockspec"
38end
39
27--- Perform platform-specific overrides on a table. 40--- Perform platform-specific overrides on a table.
28-- Overrides values of table with the contents of the appropriate 41-- Overrides values of table with the contents of the appropriate
29-- subset of its "platforms" field. The "platforms" field should 42-- subset of its "platforms" field. The "platforms" field should
@@ -83,6 +96,9 @@ local function configure_paths(rockspec: Rockspec)
83 vars.CONFDIR = path.conf_dir(name, version) 96 vars.CONFDIR = path.conf_dir(name, version)
84 vars.BINDIR = path.bin_dir(name, version) 97 vars.BINDIR = path.bin_dir(name, version)
85 vars.DOCDIR = path.doc_dir(name, version) 98 vars.DOCDIR = path.doc_dir(name, version)
99 if rockspec:format_is_at_least("3.1") then
100 vars.LUA_VERSION = cfg.lua_version
101 end
86 rockspec.variables = vars 102 rockspec.variables = vars
87end 103end
88 104
@@ -178,7 +194,8 @@ function rockspecs.from_persisted_table(filename: string, rockspec: Rockspec, gl
178 configure_paths(rockspec) 194 configure_paths(rockspec)
179 end 195 end
180 196
181 return rockspec 197 -- TODO remove this on LuaRocks 4.0
198 return setmetatable(rockspec, rockspec_mt)
182end 199end
183 200
184return rockspecs 201return rockspecs
diff --git a/src/luarocks/tools/patch.lua b/src/luarocks/tools/patch.lua
index 8dc188a6..d1575cb0 100644
--- a/src/luarocks/tools/patch.lua
+++ b/src/luarocks/tools/patch.lua
@@ -129,14 +129,13 @@ local function file_lines(f)
129 end 129 end
130 end 130 end
131 end 131 end
132 local posi = math.tointeger(pos) 132 if not pos then
133 if not posi then 133 pos = #buffer
134 posi = #buffer
135 elseif chars == '\r\n' then 134 elseif chars == '\r\n' then
136 posi = posi + 1 135 pos = pos + 1
137 end 136 end
138 local line = buffer:sub(pos_beg, posi) 137 local line = buffer:sub(pos_beg, pos)
139 pos_beg = posi + 1 138 pos_beg = pos + 1
140 if #line > 0 then 139 if #line > 0 then
141 return line 140 return line
142 end 141 end
diff --git a/src/luarocks/tools/patch.tl b/src/luarocks/tools/patch.tl
index 83c16ab7..553964e3 100644
--- a/src/luarocks/tools/patch.tl
+++ b/src/luarocks/tools/patch.tl
@@ -114,7 +114,7 @@ local function file_lines(f: FILE): function(): string
114 local buffer = "" 114 local buffer = ""
115 local pos_beg = 1 115 local pos_beg = 1
116 return function(): string 116 return function(): string
117 local pos, chars: string, string 117 local pos, chars: integer, string
118 while 1 do 118 while 1 do
119 pos, chars = buffer:match('()([\r\n].)', pos_beg) 119 pos, chars = buffer:match('()([\r\n].)', pos_beg)
120 if pos or not f then 120 if pos or not f then
@@ -129,14 +129,13 @@ local function file_lines(f: FILE): function(): string
129 end 129 end
130 end 130 end
131 end 131 end
132 local posi = math.tointeger(pos) 132 if not pos then
133 if not posi then 133 pos = #buffer
134 posi = #buffer
135 elseif chars == '\r\n' then 134 elseif chars == '\r\n' then
136 posi = posi + 1 135 pos = pos + 1
137 end 136 end
138 local line = buffer:sub(pos_beg, posi) 137 local line = buffer:sub(pos_beg, pos)
139 pos_beg = posi + 1 138 pos_beg = pos + 1
140 if #line > 0 then 139 if #line > 0 then
141 return line 140 return line
142 end 141 end
diff --git a/src/luarocks/type/rockspec.lua b/src/luarocks/type/rockspec.lua
index cd4044f6..10b06690 100644
--- a/src/luarocks/type/rockspec.lua
+++ b/src/luarocks/type/rockspec.lua
@@ -11,7 +11,7 @@ local type_check = require("luarocks.type_check")
11 11
12 12
13 13
14type_rockspec.rockspec_format = "3.0" 14type_rockspec.rockspec_format = "3.1"
15 15
16 16
17 17
@@ -174,6 +174,9 @@ local rockspec_formats, versions = type_check.declare_schemas({
174 }, 174 },
175 }, 175 },
176 }, 176 },
177
178 ["3.1"] = {},
179
177}) 180})
178 181
179 182
diff --git a/src/luarocks/type/rockspec.tl b/src/luarocks/type/rockspec.tl
index 599c13ce..52ad7909 100644
--- a/src/luarocks/type/rockspec.tl
+++ b/src/luarocks/type/rockspec.tl
@@ -11,7 +11,7 @@ local type_check = require("luarocks.type_check")
11 11
12-- local type TableSchema = type_check.TableSchema 12-- local type TableSchema = type_check.TableSchema
13 13
14type_rockspec.rockspec_format = "3.0" 14type_rockspec.rockspec_format = "3.1"
15 15
16-- Syntax for type-checking tables: 16-- Syntax for type-checking tables:
17-- 17--
@@ -173,7 +173,10 @@ local rockspec_formats, versions = type_check.declare_schemas({
173 _more = true, 173 _more = true,
174 }, 174 },
175 } 175 }
176 } 176 },
177
178 ["3.1"] = {},
179
177}) 180})
178 181
179-- type_rockspec.order = {"rockspec_format", "package", "version", 182-- type_rockspec.order = {"rockspec_format", "package", "version",
diff --git a/src/luarocks/vendor/dkjson.d.tl b/src/luarocks/vendor/dkjson.d.tl
index a7c76389..4245e8aa 100644
--- a/src/luarocks/vendor/dkjson.d.tl
+++ b/src/luarocks/vendor/dkjson.d.tl
@@ -15,7 +15,7 @@ local record dkjson
15 end 15 end
16 encode: function({string:any}, ?JsonState): string 16 encode: function({string:any}, ?JsonState): string
17 17
18 decode: function(string, ?number, ?any, ?table): {string:any} 18 decode: function(string, ?number, ?any, ?table): {string:any}, integer, string
19 19
20 null: table 20 null: table
21 21