diff options
-rw-r--r-- | src/luarocks/deps.lua | 9 | ||||
-rw-r--r-- | src/luarocks/fetch.lua | 5 | ||||
-rw-r--r-- | src/luarocks/fetch/git.lua | 57 | ||||
-rw-r--r-- | src/luarocks/tools/tar.lua | 6 | ||||
-rw-r--r-- | src/luarocks/type_check.lua | 2 | ||||
-rwxr-xr-x | test/testing.sh | 4 |
6 files changed, 69 insertions, 14 deletions
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 0e3265b5..f6c86d1c 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua | |||
@@ -159,6 +159,15 @@ function deps.compare_versions(a, b) | |||
159 | return deps.parse_version(a) > deps.parse_version(b) | 159 | return deps.parse_version(a) > deps.parse_version(b) |
160 | end | 160 | end |
161 | 161 | ||
162 | --- Check if rockspec format version satisfies version requirement. | ||
163 | -- @param rockspec table: The rockspec table. | ||
164 | -- @param version string: required version. | ||
165 | -- @return boolean: true if rockspec format matches version or is newer, false otherwise. | ||
166 | function deps.format_is_at_least(rockspec, version) | ||
167 | local rockspec_format = rockspec.rockspec_format or "1.0" | ||
168 | return deps.parse_version(rockspec_format) >= deps.parse_version(version) | ||
169 | end | ||
170 | |||
162 | --- Consumes a constraint from a string, converting it to table format. | 171 | --- Consumes a constraint from a string, converting it to table format. |
163 | -- For example, a string ">= 1.0, > 2.0" is converted to a table in the | 172 | -- For example, a string ">= 1.0, > 2.0" is converted to a table in the |
164 | -- format {op = ">=", version={1,0}} and the rest, "> 2.0", is returned | 173 | -- format {op = ">=", version={1,0}} and the rest, "> 2.0", is returned |
diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index e92aeddf..5ae05826 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua | |||
@@ -247,7 +247,10 @@ function fetch.load_local_rockspec(filename, quick) | |||
247 | local base = fetch.url_to_base_dir(filebase) | 247 | local base = fetch.url_to_base_dir(filebase) |
248 | rockspec.source.dir = rockspec.source.dir | 248 | rockspec.source.dir = rockspec.source.dir |
249 | or rockspec.source.module | 249 | or rockspec.source.module |
250 | or ((filebase:match("%.lua$") or filebase:match("%.c$")) and ".") | 250 | or ( (filebase:match("%.lua$") or filebase:match("%.c$")) |
251 | and (deps.format_is_at_least(rockspec, "3.0") | ||
252 | and (fetch.is_basic_protocol(protocol) and "." or base) | ||
253 | or ".") ) | ||
251 | or base | 254 | or base |
252 | if rockspec.dependencies then | 255 | if rockspec.dependencies then |
253 | for i = 1, #rockspec.dependencies do | 256 | for i = 1, #rockspec.dependencies do |
diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua index a635f190..aa735b3f 100644 --- a/src/luarocks/fetch/git.lua +++ b/src/luarocks/fetch/git.lua | |||
@@ -7,20 +7,48 @@ local unpack = unpack or table.unpack | |||
7 | 7 | ||
8 | local fs = require("luarocks.fs") | 8 | local fs = require("luarocks.fs") |
9 | local dir = require("luarocks.dir") | 9 | local dir = require("luarocks.dir") |
10 | local deps = require("luarocks.deps") | ||
10 | local util = require("luarocks.util") | 11 | local util = require("luarocks.util") |
11 | 12 | ||
13 | local cached_git_version | ||
14 | |||
15 | --- Get git version. | ||
16 | -- @param git_cmd string: name of git command. | ||
17 | -- @return table: git version as returned by luarocks.deps.parse_version. | ||
18 | local function git_version(git_cmd) | ||
19 | if not cached_git_version then | ||
20 | local version_line = io.popen(fs.Q(git_cmd)..' --version'):read() | ||
21 | local version_string = version_line:match('%d-%.%d+%.?%d*') | ||
22 | cached_git_version = deps.parse_version(version_string) | ||
23 | end | ||
24 | |||
25 | return cached_git_version | ||
26 | end | ||
27 | |||
28 | --- Check if git satisfies version requirement. | ||
29 | -- @param git_cmd string: name of git command. | ||
30 | -- @param version string: required version. | ||
31 | -- @return boolean: true if git matches version or is newer, false otherwise. | ||
32 | local function git_is_at_least(git_cmd, version) | ||
33 | return git_version(git_cmd) >= deps.parse_version(version) | ||
34 | end | ||
35 | |||
12 | --- Git >= 1.7.10 can clone a branch **or tag**, < 1.7.10 by branch only. We | 36 | --- Git >= 1.7.10 can clone a branch **or tag**, < 1.7.10 by branch only. We |
13 | -- need to know this in order to build the appropriate command; if we can't | 37 | -- need to know this in order to build the appropriate command; if we can't |
14 | -- clone by tag then we'll have to issue a subsequent command to check out the | 38 | -- clone by tag then we'll have to issue a subsequent command to check out the |
15 | -- given tag. | 39 | -- given tag. |
40 | -- @param git_cmd string: name of git command. | ||
16 | -- @return boolean: Whether Git can clone by tag. | 41 | -- @return boolean: Whether Git can clone by tag. |
17 | local function git_can_clone_by_tag(git_cmd) | 42 | local function git_can_clone_by_tag(git_cmd) |
18 | local version_string = io.popen(fs.Q(git_cmd)..' --version'):read() | 43 | return git_is_at_least(git_cmd, "1.7.10") |
19 | local major, minor, tiny = version_string:match('(%d-)%.(%d+)%.?(%d*)') | 44 | end |
20 | major, minor, tiny = tonumber(major), tonumber(minor), tonumber(tiny) or 0 | 45 | |
21 | local value = major > 1 or (major == 1 and (minor > 7 or (minor == 7 and tiny >= 10))) | 46 | --- Git >= 1.8.4 can fetch submodules shallowly, saving bandwidth and time for |
22 | git_can_clone_by_tag = function() return value end | 47 | -- submodules with large history. |
23 | return value | 48 | -- @param git_cmd string: name of git command. |
49 | -- @return boolean: Whether Git can fetch submodules shallowly. | ||
50 | local function git_supports_shallow_submodules(git_cmd) | ||
51 | return git_is_at_least(git_cmd, "1.8.4") | ||
24 | end | 52 | end |
25 | 53 | ||
26 | --- Download sources for building a rock, using git. | 54 | --- Download sources for building a rock, using git. |
@@ -77,12 +105,25 @@ function git.get_sources(rockspec, extract, dest_dir, depth) | |||
77 | ok, err = fs.change_dir(module) | 105 | ok, err = fs.change_dir(module) |
78 | if not ok then return nil, err end | 106 | if not ok then return nil, err end |
79 | if tag_or_branch and not git_can_clone_by_tag() then | 107 | if tag_or_branch and not git_can_clone_by_tag() then |
80 | local checkout_command = {fs.Q(git_cmd), "checkout", tag_or_branch} | 108 | if not fs.execute(fs.Q(git_cmd), "checkout", tag_or_branch) then |
81 | if not fs.execute(unpack(checkout_command)) then | ||
82 | return nil, 'Failed to check out the "' .. tag_or_branch ..'" tag or branch.' | 109 | return nil, 'Failed to check out the "' .. tag_or_branch ..'" tag or branch.' |
83 | end | 110 | end |
84 | end | 111 | end |
85 | 112 | ||
113 | -- Fetching git submodules is supported only when rockspec format is >= 3.0. | ||
114 | if deps.format_is_at_least(rockspec, "3.0") then | ||
115 | command = {fs.Q(git_cmd), "submodule", "update", "--init", "--recursive"} | ||
116 | |||
117 | if git_supports_shallow_submodules(git_cmd) then | ||
118 | -- Fetch only the last commit of each submodule. | ||
119 | table.insert(command, 5, "--depth=1") | ||
120 | end | ||
121 | |||
122 | if not fs.execute(unpack(command)) then | ||
123 | return nil, 'Failed to fetch submodules.' | ||
124 | end | ||
125 | end | ||
126 | |||
86 | fs.delete(dir.path(store_dir, module, ".git")) | 127 | fs.delete(dir.path(store_dir, module, ".git")) |
87 | fs.delete(dir.path(store_dir, module, ".gitignore")) | 128 | fs.delete(dir.path(store_dir, module, ".gitignore")) |
88 | fs.pop_dir() | 129 | fs.pop_dir() |
diff --git a/src/luarocks/tools/tar.lua b/src/luarocks/tools/tar.lua index b2bd930a..cedcceee 100644 --- a/src/luarocks/tools/tar.lua +++ b/src/luarocks/tools/tar.lua | |||
@@ -57,10 +57,11 @@ end | |||
57 | local function read_header_block(block) | 57 | local function read_header_block(block) |
58 | local header = {} | 58 | local header = {} |
59 | header.name = nullterm(block:sub(1,100)) | 59 | header.name = nullterm(block:sub(1,100)) |
60 | header.mode = nullterm(block:sub(101,108)) | 60 | header.mode = nullterm(block:sub(101,108)):gsub(" ", "") |
61 | header.uid = octal_to_number(nullterm(block:sub(109,116))) | 61 | header.uid = octal_to_number(nullterm(block:sub(109,116))) |
62 | header.gid = octal_to_number(nullterm(block:sub(117,124))) | 62 | header.gid = octal_to_number(nullterm(block:sub(117,124))) |
63 | header.size = octal_to_number(nullterm(block:sub(125,136))) | 63 | header.size = octal_to_number(nullterm(block:sub(125,136))) |
64 | print("{"..block:sub(125,136).."}", "{"..nullterm(block:sub(125,136)).."}", "{"..octal_to_number(nullterm(block:sub(125,136))).."}", header.size) | ||
64 | header.mtime = octal_to_number(nullterm(block:sub(137,148))) | 65 | header.mtime = octal_to_number(nullterm(block:sub(137,148))) |
65 | header.chksum = octal_to_number(nullterm(block:sub(149,156))) | 66 | header.chksum = octal_to_number(nullterm(block:sub(149,156))) |
66 | header.typeflag = get_typeflag(block:sub(157,157)) | 67 | header.typeflag = get_typeflag(block:sub(157,157)) |
@@ -94,13 +95,14 @@ function tar.untar(filename, destdir) | |||
94 | local long_name, long_link_name | 95 | local long_name, long_link_name |
95 | while true do | 96 | while true do |
96 | local block | 97 | local block |
97 | repeat | 98 | repeat |
98 | block = tar_handle:read(blocksize) | 99 | block = tar_handle:read(blocksize) |
99 | until (not block) or checksum_header(block) > 256 | 100 | until (not block) or checksum_header(block) > 256 |
100 | if not block then break end | 101 | if not block then break end |
101 | local header, err = read_header_block(block) | 102 | local header, err = read_header_block(block) |
102 | if not header then | 103 | if not header then |
103 | util.printerr(err) | 104 | util.printerr(err) |
105 | return nil, err | ||
104 | end | 106 | end |
105 | 107 | ||
106 | local file_data = tar_handle:read(math.ceil(header.size / blocksize) * blocksize):sub(1,header.size) | 108 | local file_data = tar_handle:read(math.ceil(header.size / blocksize) * blocksize):sub(1,header.size) |
diff --git a/src/luarocks/type_check.lua b/src/luarocks/type_check.lua index 65b4fc15..83091a29 100644 --- a/src/luarocks/type_check.lua +++ b/src/luarocks/type_check.lua | |||
@@ -8,7 +8,7 @@ package.loaded["luarocks.type_check"] = type_check | |||
8 | local cfg = require("luarocks.cfg") | 8 | local cfg = require("luarocks.cfg") |
9 | local deps = require("luarocks.deps") | 9 | local deps = require("luarocks.deps") |
10 | 10 | ||
11 | type_check.rockspec_format = "1.1" | 11 | type_check.rockspec_format = "3.0" |
12 | 12 | ||
13 | local string_1 = { _type = "string" } | 13 | local string_1 = { _type = "string" } |
14 | local number_1 = { _type = "number" } | 14 | local number_1 = { _type = "number" } |
diff --git a/test/testing.sh b/test/testing.sh index 26bdde5f..7292c75d 100755 --- a/test/testing.sh +++ b/test/testing.sh | |||
@@ -161,7 +161,7 @@ then | |||
161 | chmod og-wx ~/.ssh/authorized_keys | 161 | chmod og-wx ~/.ssh/authorized_keys |
162 | ssh-keyscan localhost >> ~/.ssh/known_hosts | 162 | ssh-keyscan localhost >> ~/.ssh/known_hosts |
163 | else | 163 | else |
164 | luadir="/Programs/Lua/Current" | 164 | luadir="/Programs/Lua/$luaversion" |
165 | if [ ! -e "$luadir" ] | 165 | if [ ! -e "$luadir" ] |
166 | then | 166 | then |
167 | luadir="/usr/local" | 167 | luadir="/usr/local" |
@@ -242,7 +242,7 @@ mkdir -p "$testing_server" | |||
242 | get "$luarocks_repo/stdlib-41.0.0-1.src.rock" | 242 | get "$luarocks_repo/stdlib-41.0.0-1.src.rock" |
243 | get "$luarocks_repo/luarepl-0.4-1.src.rock" | 243 | get "$luarocks_repo/luarepl-0.4-1.src.rock" |
244 | get "$luarocks_repo/validate-args-1.5.4-1.rockspec" | 244 | get "$luarocks_repo/validate-args-1.5.4-1.rockspec" |
245 | get "$luarocks_repo/luasec-0.5-2.rockspec" | 245 | get "https://raw.githubusercontent.com/brunoos/luasec/master/luasec-0.6alpha-2.rockspec" |
246 | get "$luarocks_repo/luabitop-1.0.2-1.rockspec" | 246 | get "$luarocks_repo/luabitop-1.0.2-1.rockspec" |
247 | get "$luarocks_repo/lpty-1.0.1-1.src.rock" | 247 | get "$luarocks_repo/lpty-1.0.1-1.src.rock" |
248 | get "$luarocks_repo/cprint-${verrev_cprint}.src.rock" | 248 | get "$luarocks_repo/cprint-${verrev_cprint}.src.rock" |