From 96f191fc91e66837fed2793ba7c43c45d8edac50 Mon Sep 17 00:00:00 2001 From: merakor Date: Tue, 31 Jan 2023 16:23:48 +0000 Subject: LICENSE: update license year FossilOrigin-Name: 4781e27ea205de406da1e7f912fd4fd4d9219f9718903c3ea3eba002121a8f92 --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index b732ecc..ea3666c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2020-2022 Cem Keylan +Copyright (c) 2020-2023 Cem Keylan Copyright (c) 2019-2020 Dylan Araps Permission is hereby granted, free of charge, to any person obtaining a copy -- cgit v1.2.3 From 1d8c311d19521f86a6221765b4a3992bf867813c Mon Sep 17 00:00:00 2001 From: merakor Date: Sun, 5 Feb 2023 13:39:03 +0000 Subject: use a tsort function compatible with POSIX and fix dependency calculation issues FossilOrigin-Name: faa4f309950d79caab445296a3dfb3008552067e6ec7aeedd7ddef904a577b09 --- src/cpt-lib.in | 128 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 100 insertions(+), 28 deletions(-) diff --git a/src/cpt-lib.in b/src/cpt-lib.in index 5a0d463..55a8688 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -88,32 +88,100 @@ _tsort() { # but the specification is quite vague, it doesn't specify cycles as a # reason of error, and implementations differ on how it's handled. coreutils # tsort(1) exits with an error, while openbsd tsort(1) doesn't. Both - # implementations are correct according to the specification. This leaves us - # with the following awk script, because the POSIX shell is not up for the - # job without super ugly hacks. - awk 'function fv(s) { - for (sp in e) { - split (e[sp],t) - for (j in t) if (s == t[j]) return 0 - } return 1 + # implementations are correct according to the specification. + # + # The script below was taken from + # + # The MIT License (MIT) + # Copyright (c) 2023 Kevin Robell + # + # Permission is hereby granted, free of charge, to any person obtaining a + # copy of this software and associated documentation files (the “Software”), + # to deal in the Software without restriction, including without limitation + # the rights to use, copy, modify, merge, publish, distribute, sublicense, + # and/or sell copies of the Software, and to permit persons to whom the + # Software is furnished to do so, subject to the following conditions: + # + # The above copyright notice and this permission notice shall be included in + # all copies or substantial portions of the Software. + # + # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + # DEALINGS IN THE SOFTWARE. + awk '{ + for (i = 1; i <= NF; ++i) { + # Store each node. + nodes[$i] = 1 + if (is_child) { + child = $i + # Skip nodes that point to themselves. + # This traditionally means that the node + # is disconnected from the rest of the graph. + if (parent != child) { + # Store from parent to child. + idx = ++child_count[parent] + child_graph[parent, idx] = child + # Store count from child to parent. + ++parent_count[child] + } + } else { + parent = $i + } + # Flip switch + is_child = !is_child + } } - function el(_l) {for(i in e){_l=_l" "i;}; return _l;} - function ce(t) {if (!(t in e)) e[t]="";} - function err(s) {print "Dependency cycle deteced between: " s; exit 1;} - {ce($1);$1!=$2&&e[$1]=e[$1]" "$2;} END { - do {p=el() - for (s in e) { - if (fv(s)) { - pr=s" "pr - split(e[s],t) - for(i in t){ce(t[i]);} - delete e[s] + # Print errors to the stderr + stderr = "/dev/stderr" + + # Sanity Check + if (is_child) { + print("Error: odd number of input values: expected pairs of values") > stderr + exit(1) + } + + ##### + # Topological Sort + ##### + + # Remove unconnected nodes first. + for (node in nodes) { + if (parent_count[node] == 0 && child_count[node] == 0) { + delete nodes[node] + print(node) + } + } + + # Remove the rest of the nodes starting with those without parents. + while (length(nodes) > 0) { + removed_node = 0 + for (node in nodes) { + # Delete and print nodes without any remaining parents. + if (parent_count[node] == 0) { + delete nodes[node] + removed_node = 1 + # Decrease child_count for each parent node. + for (i = child_count[node]; i > 0; --i) { + child = child_graph[node, i] + --parent_count[child] + } + print(node) } - } c=el() - } while (p != c) - if (length(p)!=0) err(p); - print pr + } + + # If we havent removed any nodes, it means that there + # are no nodes without any remaining parents so we have + # a cycle. + if (!removed_node) { + print("Error: Cycle found") > stderr + exit(1) + } + } }' } @@ -228,7 +296,7 @@ _get_digest() { # function. # URL: https://github.com/ko1nksm/getoptions (v2.5.0) # License: Creative Commons Zero v1.0 Universal -# shellcheck disable=2016,2086 +# shellcheck disable=2016,2086,2317 getoptions() { _error='' _on=1 _off='' _export='' _plus='' _mode='' _alt='' _rest='' _flags='' _nflags='' _opts='' _help='' _abbr='' _cmds='' _init=@empty IFS=' ' @@ -423,6 +491,7 @@ getoptions() { } # URL: https://github.com/ko1nksm/getoptions (v2.5.0) # License: Creative Commons Zero v1.0 Universal +# shellcheck disable=2317 getoptions_help() { _width='30,12' _plus='' _leading=' ' @@ -904,8 +973,9 @@ pkg_depends() { # Resolve all dependencies and generate an ordered list. # This does a depth-first search. The deepest dependencies are # listed first and then the parents in reverse order. - contains "$pkgs" "$1" || { - pkgs="$pkgs $1 " + # + # shellcheck disable=2015 + contains "$pkgs" "$1" && [ -z "$2" ] || { [ "$2" = raw ] && _dep_append "$1" "$1" while read -r dep type || [ "$dep" ]; do # Skip comments and empty lines. @@ -926,7 +996,7 @@ pkg_depends() { if [ "$2" = explicit ] || [ "$3" ]; then _dep_append "$dep" "$dep" else - _dep_append "$1" "$dep" + _dep_append "$dep" "$1" fi # Recurse through the dependencies of the child packages. Forward @@ -938,6 +1008,7 @@ pkg_depends() { fi done 2>/dev/null < "$(pkg_find "$1")/depends" ||: + pkgs="$pkgs $1 " } } @@ -2181,6 +2252,7 @@ pkg_gentree() ( esac done pkg_depends "$1" tree "$make_deps" + pkg_depends_commit # Unless 'f' is given, pop the package from the list so that we don't list # the package (for example if it's part of the base package list). Normally @@ -2192,7 +2264,7 @@ pkg_gentree() ( # shellcheck disable=2086 [ -z "${2##*f*}" ] || deps=$(pop "$1" from $deps) - eval set -- "$deps" + set -- $deps pkg_order "$@" if [ "$reverse" ]; then eval set -- "$redro"; else eval set -- "$order"; fi [ "$1" ] || return 0 -- cgit v1.2.3 From c67fed385fe720fa65f234ec07609c226999461e Mon Sep 17 00:00:00 2001 From: merakor Date: Sun, 5 Feb 2023 13:44:01 +0000 Subject: CHANGELOG: update FossilOrigin-Name: 5f6ff8eafaec6b4f1fda29bbe6a477d38da8db307b84fcbd365facce65b48948 --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3102485..3a4182c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,17 @@ this project _somewhat_ adheres to [Semantic Versioning]. [Semantic Versioning]: https://semver.org/spec/v2.0.0.html +[7.0.1] - 2023-02-05 +-------------------------------------------------------------------------------- + +### Fixed +- Made the `_tsort()` function compatible with POSIX +- Fixed dependency calculation issue in `pkg_depends()` where some packages + would be removed. +- Fixed `pkg_gentree()` not generating the dependency tree due to the dependency + calculation changes. + + [7.0.0] - 2023-01-31 -------------------------------------------------------------------------------- -- cgit v1.2.3 From adcfbdd0ffefd31804947f033961d102480abfd7 Mon Sep 17 00:00:00 2001 From: merakor Date: Sun, 5 Feb 2023 14:27:15 +0000 Subject: pkg_gentree(): disable shellcheck error FossilOrigin-Name: d973f64d827764766111bb0774b489f1fc613fcde6871f794deb5d2bc2e49b21 --- src/cpt-lib.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cpt-lib.in b/src/cpt-lib.in index 55a8688..8b6cd13 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -2264,6 +2264,8 @@ pkg_gentree() ( # shellcheck disable=2086 [ -z "${2##*f*}" ] || deps=$(pop "$1" from $deps) + # Word splitting is intentional. + # shellcheck disable=2086 set -- $deps pkg_order "$@" if [ "$reverse" ]; then eval set -- "$redro"; else eval set -- "$order"; fi -- cgit v1.2.3 From 0e86e90e0fca8b5a0db95c84b6ff30cacabd81f0 Mon Sep 17 00:00:00 2001 From: merakor Date: Sun, 5 Feb 2023 14:28:51 +0000 Subject: cpt: disable unnecessary shellcheck warnings FossilOrigin-Name: a2be47d8d0dac03ad4e688eb2307c2872c54afa92f5dad562ed23b5270d84d2d --- src/cpt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cpt b/src/cpt index cdaff42..7905d9c 100755 --- a/src/cpt +++ b/src/cpt @@ -2,6 +2,8 @@ bi() { # Build and install function for cpt. + # + # shellcheck disable=2317 parser_definition() { setup REST help:usage -- "usage: ${0##*/} bi [-dfSty] [--root ROOT] [pkg...]" msg -- '' 'Options:' @@ -24,6 +26,8 @@ bi() { cbi() { # Checksum, build and install. + # + # shellcheck disable=2317 parser_definition() { setup REST help:usage -- "usage: ${0##*/} cbi [-dfSsty] [--root ROOT] [pkg...]" msg -- '' 'Options:' -- cgit v1.2.3 From 46b2952a6d21628552f217d0904ae4f7b7a24de8 Mon Sep 17 00:00:00 2001 From: merakor Date: Sun, 5 Feb 2023 14:32:12 +0000 Subject: bump to version 7.0.1 FossilOrigin-Name: 8f1c72970449117818c76c3ec90846997c1d48c8805d3359d9d11f971f9b83c8 --- configure | 2 +- docs/cpt.texi | 2 +- docs/cpt.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/configure b/configure index da16f14..2105975 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #!/bin/sh -e -version=7.0.0 +version=7.0.1 die() { printf '%s: %s\n' "${0##*/}" "$*" >&2 diff --git a/docs/cpt.texi b/docs/cpt.texi index 291c6f7..e18eed6 100644 --- a/docs/cpt.texi +++ b/docs/cpt.texi @@ -41,7 +41,7 @@ the section entitled "GNU Free Documentation License." @top Carbs Packaging Tools This is a reference document containing both the user-guide and the development -manual for @strong{Carbs Packaging Tools} version 7.0.0. For development logs +manual for @strong{Carbs Packaging Tools} version 7.0.1. For development logs see @uref{https://fossil.carbslinux.org/cpt, the fossil repository}. @end ifnottex diff --git a/docs/cpt.txt b/docs/cpt.txt index e18e4d9..911e9e5 100644 --- a/docs/cpt.txt +++ b/docs/cpt.txt @@ -77,7 +77,7 @@ _________________ This is a reference document containing both the user-guide and the -development manual for *Carbs Packaging Tools* version 7.0.0. For +development manual for *Carbs Packaging Tools* version 7.0.1. For development logs see [the fossil repository]. -- cgit v1.2.3