diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2023-12-12 20:40:14 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-12 20:40:14 -0300 |
| commit | d81020338c99ff4116431ee496a7db516eb91f00 (patch) | |
| tree | 0717c9a5e762ed84b4949222f9730b0fbf347dc1 | |
| parent | 780d5e7828fef17b79a421ce4a6e131514e6a288 (diff) | |
| download | luarocks-d81020338c99ff4116431ee496a7db516eb91f00.tar.gz luarocks-d81020338c99ff4116431ee496a7db516eb91f00.tar.bz2 luarocks-d81020338c99ff4116431ee496a7db516eb91f00.zip | |
improve rockspec.source.dir detection by moving it later (#1555)
| -rw-r--r-- | src/luarocks/build.lua | 10 | ||||
| -rw-r--r-- | src/luarocks/cmd/new_version.lua | 16 | ||||
| -rw-r--r-- | src/luarocks/cmd/unpack.lua | 7 | ||||
| -rw-r--r-- | src/luarocks/fetch.lua | 88 | ||||
| -rw-r--r-- | src/luarocks/rockspecs.lua | 10 |
5 files changed, 88 insertions, 43 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 0b82174b..42ae4591 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua | |||
| @@ -159,8 +159,14 @@ local function fetch_and_change_to_source_dir(rockspec, opts) | |||
| 159 | if not ok then | 159 | if not ok then |
| 160 | return nil, err | 160 | return nil, err |
| 161 | end | 161 | end |
| 162 | elseif rockspec.source.file then | 162 | else |
| 163 | local ok, err = fs.unpack_archive(rockspec.source.file) | 163 | if rockspec.source.file then |
| 164 | local ok, err = fs.unpack_archive(rockspec.source.file) | ||
| 165 | if not ok then | ||
| 166 | return nil, err | ||
| 167 | end | ||
| 168 | end | ||
| 169 | local ok, err = fetch.find_rockspec_source_dir(rockspec, ".") | ||
| 164 | if not ok then | 170 | if not ok then |
| 165 | return nil, err | 171 | return nil, err |
| 166 | end | 172 | end |
diff --git a/src/luarocks/cmd/new_version.lua b/src/luarocks/cmd/new_version.lua index 49479910..ccba9335 100644 --- a/src/luarocks/cmd/new_version.lua +++ b/src/luarocks/cmd/new_version.lua | |||
| @@ -78,16 +78,16 @@ local function check_url_and_update_md5(out_rs, invalid_is_error) | |||
| 78 | util.warning("invalid URL - "..temp_dir) | 78 | util.warning("invalid URL - "..temp_dir) |
| 79 | return true, false | 79 | return true, false |
| 80 | end | 80 | end |
| 81 | do | ||
| 82 | local inferred_dir, found_dir = fetch.find_base_dir(file, temp_dir, out_rs.source.url, out_rs.source.dir) | ||
| 83 | if not inferred_dir then | ||
| 84 | return nil, found_dir | ||
| 85 | end | ||
| 81 | 86 | ||
| 82 | local inferred_dir, found_dir = fetch.find_base_dir(file, temp_dir, out_rs.source.url, out_rs.source.dir) | 87 | if found_dir and found_dir ~= inferred_dir then |
| 83 | if not inferred_dir then | 88 | out_rs.source.dir = found_dir |
| 84 | return nil, found_dir | 89 | end |
| 85 | end | ||
| 86 | |||
| 87 | if found_dir and found_dir ~= inferred_dir then | ||
| 88 | out_rs.source.dir = found_dir | ||
| 89 | end | 90 | end |
| 90 | |||
| 91 | if file then | 91 | if file then |
| 92 | if out_rs.source.md5 then | 92 | if out_rs.source.md5 then |
| 93 | util.printout("File successfully downloaded. Updating MD5 checksum...") | 93 | util.printout("File successfully downloaded. Updating MD5 checksum...") |
diff --git a/src/luarocks/cmd/unpack.lua b/src/luarocks/cmd/unpack.lua index 94da2c9f..a0ade4f3 100644 --- a/src/luarocks/cmd/unpack.lua +++ b/src/luarocks/cmd/unpack.lua | |||
| @@ -81,9 +81,9 @@ local function unpack_rock(rock_file, dir_name, kind) | |||
| 81 | if kind == "src" then | 81 | if kind == "src" then |
| 82 | if rockspec.source.file then | 82 | if rockspec.source.file then |
| 83 | local ok, err = fs.unpack_archive(rockspec.source.file) | 83 | local ok, err = fs.unpack_archive(rockspec.source.file) |
| 84 | if not ok then | 84 | if not ok then return nil, err end |
| 85 | return nil, err | 85 | ok, err = fetch.find_rockspec_source_dir(rockspec, ".") |
| 86 | end | 86 | if not ok then return nil, err end |
| 87 | ok, err = fs.change_dir(rockspec.source.dir) | 87 | ok, err = fs.change_dir(rockspec.source.dir) |
| 88 | if not ok then return nil, err end | 88 | if not ok then return nil, err end |
| 89 | ok, err = build.apply_patches(rockspec) | 89 | ok, err = build.apply_patches(rockspec) |
| @@ -133,6 +133,7 @@ local function run_unpacker(file, force) | |||
| 133 | return nil, err | 133 | return nil, err |
| 134 | end | 134 | end |
| 135 | if kind == "src" or kind == "rockspec" then | 135 | if kind == "src" or kind == "rockspec" then |
| 136 | fetch.find_rockspec_source_dir(rockspec, ".") | ||
| 136 | if rockspec.source.dir ~= "." then | 137 | if rockspec.source.dir ~= "." then |
| 137 | local ok = fs.copy(rockspec.local_abs_filename, rockspec.source.dir, "read") | 138 | local ok = fs.copy(rockspec.local_abs_filename, rockspec.source.dir, "read") |
| 138 | if not ok then | 139 | if not ok then |
diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 90e7c79e..723af8b5 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua | |||
| @@ -234,6 +234,21 @@ function fetch.find_base_dir(file, temp_dir, src_url, src_dir) | |||
| 234 | local ok, err = fs.change_dir(temp_dir) | 234 | local ok, err = fs.change_dir(temp_dir) |
| 235 | if not ok then return nil, err end | 235 | if not ok then return nil, err end |
| 236 | fs.unpack_archive(file) | 236 | fs.unpack_archive(file) |
| 237 | |||
| 238 | if not src_dir then | ||
| 239 | local rockspec = { | ||
| 240 | source = { | ||
| 241 | file = file, | ||
| 242 | dir = src_dir, | ||
| 243 | url = src_url, | ||
| 244 | } | ||
| 245 | } | ||
| 246 | ok, err = fetch.find_rockspec_source_dir(rockspec, ".") | ||
| 247 | if ok then | ||
| 248 | src_dir = rockspec.source.dir | ||
| 249 | end | ||
| 250 | end | ||
| 251 | |||
| 237 | local inferred_dir = src_dir or dir.deduce_base_dir(src_url) | 252 | local inferred_dir = src_dir or dir.deduce_base_dir(src_url) |
| 238 | local found_dir = nil | 253 | local found_dir = nil |
| 239 | if fs.exists(inferred_dir) then | 254 | if fs.exists(inferred_dir) then |
| @@ -459,33 +474,58 @@ function fetch.get_sources(rockspec, extract, dest_dir) | |||
| 459 | if not ok then return nil, err end | 474 | if not ok then return nil, err end |
| 460 | ok, err = fs.unpack_archive(rockspec.source.file) | 475 | ok, err = fs.unpack_archive(rockspec.source.file) |
| 461 | if not ok then return nil, err end | 476 | if not ok then return nil, err end |
| 462 | if not fs.exists(rockspec.source.dir) then | 477 | ok, err = fetch.find_rockspec_source_dir(rockspec, ".") |
| 463 | 478 | if not ok then return nil, err end | |
| 464 | -- If rockspec.source.dir can't be found, see if we only have one | 479 | fs.pop_dir() |
| 465 | -- directory in store_dir. If that's the case, assume it's what | 480 | end |
| 466 | -- we're looking for. | 481 | return source_file, store_dir |
| 467 | -- We only do this if the rockspec source.dir was not set, and only | 482 | end |
| 468 | -- with rockspecs newer than 3.0. | 483 | |
| 469 | local file_count, found_dir = 0 | 484 | function fetch.find_rockspec_source_dir(rockspec, store_dir) |
| 470 | 485 | local ok, err = fs.change_dir(store_dir) | |
| 471 | if not rockspec.source.dir_set and rockspec:format_is_at_least("3.0") then | 486 | if not ok then return nil, err end |
| 472 | for file in fs.dir() do | 487 | |
| 473 | file_count = file_count + 1 | 488 | local file_count, dir_count, found_dir = 0, 0, 0 |
| 474 | if fs.is_dir(file) then | 489 | |
| 475 | found_dir = file | 490 | if rockspec.source.dir and fs.exists(rockspec.source.dir) then |
| 476 | end | 491 | ok, err = true, nil |
| 492 | elseif rockspec.source.file and rockspec.source.dir then | ||
| 493 | ok, err = nil, "Directory "..rockspec.source.dir.." not found inside archive "..rockspec.source.file | ||
| 494 | elseif not rockspec.source.dir_set then -- and rockspec:format_is_at_least("3.0") then | ||
| 495 | |||
| 496 | local name = dir.base_name(rockspec.source.file or rockspec.source.url or "") | ||
| 497 | |||
| 498 | if name:match("%.lua$") or name:match("%.c$") then | ||
| 499 | if fs.is_file(name) then | ||
| 500 | rockspec.source.dir = "." | ||
| 501 | ok, err = true, nil | ||
| 502 | end | ||
| 503 | end | ||
| 504 | |||
| 505 | if not rockspec.source.dir then | ||
| 506 | for file in fs.dir() do | ||
| 507 | file_count = file_count + 1 | ||
| 508 | if fs.is_dir(file) then | ||
| 509 | dir_count = dir_count + 1 | ||
| 510 | found_dir = file | ||
| 477 | end | 511 | end |
| 478 | end | 512 | end |
| 479 | 513 | ||
| 480 | if file_count == 1 and found_dir then | 514 | if dir_count == 1 then |
| 481 | rockspec.source.dir = found_dir | 515 | rockspec.source.dir = found_dir |
| 516 | ok, err = true, nil | ||
| 482 | else | 517 | else |
| 483 | return nil, "Directory "..rockspec.source.dir.." not found inside archive "..rockspec.source.file, "source.dir", source_file, store_dir | 518 | ok, err = nil, "Could not determine source directory from rock contents (" .. tostring(file_count).." file(s), "..tostring(dir_count).." dir(s))" |
| 484 | end | 519 | end |
| 485 | end | 520 | end |
| 486 | fs.pop_dir() | 521 | else |
| 522 | ok, err = nil, "Could not determine source directory, please set source.dir in rockspec." | ||
| 487 | end | 523 | end |
| 488 | return source_file, store_dir | 524 | |
| 525 | fs.pop_dir() | ||
| 526 | |||
| 527 | assert(rockspec.source.dir or not ok) | ||
| 528 | return ok, err | ||
| 489 | end | 529 | end |
| 490 | 530 | ||
| 491 | --- Download sources for building a rock, calling the appropriate protocol method. | 531 | --- Download sources for building a rock, calling the appropriate protocol method. |
| @@ -511,7 +551,7 @@ function fetch.fetch_sources(rockspec, extract, dest_dir) | |||
| 511 | end | 551 | end |
| 512 | 552 | ||
| 513 | local protocol = rockspec.source.protocol | 553 | local protocol = rockspec.source.protocol |
| 514 | local ok, proto | 554 | local ok, err, proto |
| 515 | if dir.is_basic_protocol(protocol) then | 555 | if dir.is_basic_protocol(protocol) then |
| 516 | proto = fetch | 556 | proto = fetch |
| 517 | else | 557 | else |
| @@ -531,7 +571,13 @@ function fetch.fetch_sources(rockspec, extract, dest_dir) | |||
| 531 | end | 571 | end |
| 532 | end | 572 | end |
| 533 | 573 | ||
| 534 | return proto.get_sources(rockspec, extract, dest_dir) | 574 | local source_file, store_dir = proto.get_sources(rockspec, extract, dest_dir) |
| 575 | if not source_file then return nil, store_dir end | ||
| 576 | |||
| 577 | ok, err = fetch.find_rockspec_source_dir(rockspec, store_dir) | ||
| 578 | if not ok then return nil, err, "source.dir", source_file, store_dir end | ||
| 579 | |||
| 580 | return source_file, store_dir | ||
| 535 | end | 581 | end |
| 536 | 582 | ||
| 537 | return fetch | 583 | return fetch |
diff --git a/src/luarocks/rockspecs.lua b/src/luarocks/rockspecs.lua index c9e17530..454bab77 100644 --- a/src/luarocks/rockspecs.lua +++ b/src/luarocks/rockspecs.lua | |||
| @@ -140,16 +140,8 @@ function rockspecs.from_persisted_table(filename, rockspec, globals, quick) | |||
| 140 | if rockspec.source.cvs_tag then rockspec.source.tag = rockspec.source.cvs_tag end | 140 | if rockspec.source.cvs_tag then rockspec.source.tag = rockspec.source.cvs_tag end |
| 141 | 141 | ||
| 142 | rockspec.local_abs_filename = filename | 142 | rockspec.local_abs_filename = filename |
| 143 | local filebase = rockspec.source.file or rockspec.source.url | ||
| 144 | local base = dir.deduce_base_dir(filebase) | ||
| 145 | rockspec.source.dir_set = rockspec.source.dir ~= nil | 143 | rockspec.source.dir_set = rockspec.source.dir ~= nil |
| 146 | rockspec.source.dir = rockspec.source.dir | 144 | rockspec.source.dir = rockspec.source.dir or rockspec.source.module |
| 147 | or rockspec.source.module | ||
| 148 | or ( (filebase:match("%.lua$") or filebase:match("%.c$")) | ||
| 149 | and (rockspec:format_is_at_least("3.0") | ||
| 150 | and (dir.is_basic_protocol(protocol) and "." or base) | ||
| 151 | or ".") ) | ||
| 152 | or base | ||
| 153 | 145 | ||
| 154 | rockspec.rocks_provided = util.get_rocks_provided(rockspec) | 146 | rockspec.rocks_provided = util.get_rocks_provided(rockspec) |
| 155 | 147 | ||
