user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 4/8] ci/profiles: rewrite in Perl
  2023-09-09 12:01  7% [PATCH 0/8] NetBSD-related updates Eric Wong
@ 2023-09-09 12:01  4% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2023-09-09 12:01 UTC (permalink / raw)
  To: meta

Reading os-release(5) is a bit more painful, now; and still
requires using the shell.  However, sharing code between *BSDs
and being able to use v-strings for version comparisons is much
easier.

Test profiles for *BSDs are also trimmed down and more focused
on portability stuff.
---
 ci/profiles.perl | 97 +++++++++++++++++++++++++++++++++++++++++++++++
 ci/profiles.sh   | 98 ------------------------------------------------
 ci/run.sh        |  2 +-
 3 files changed, 98 insertions(+), 99 deletions(-)
 create mode 100755 ci/profiles.perl
 delete mode 100755 ci/profiles.sh

diff --git a/ci/profiles.perl b/ci/profiles.perl
new file mode 100755
index 00000000..3d67143a
--- /dev/null
+++ b/ci/profiles.perl
@@ -0,0 +1,97 @@
+# Copyright (C) all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+# Prints OS-specific package profiles to stdout (one per line) to use
+# as command-line args for ci/deps.perl.  Called automatically by ci/run.sh
+eval 'exec perl -wS $0 ${1+"$@"}' # no shebang
+if 0; # running under some shell
+use v5.12;
+our ($ID, $PRETTY_NAME, $VERSION_ID); # same vars as os-release(5)
+my ($release, $version); # from uname
+if ($^O eq 'linux') { # try using os-release(5)
+	for my $f (qw(/etc/os-release /usr/lib/os-release)) {
+		next unless -f $f;
+		my @echo = map {
+			qq{echo "\$"$_" = qq[\$$_];"; }
+		} qw(ID PRETTY_NAME VERSION_ID);
+		# rely on sh(1) to handle interpolation and such:
+		my $vars = `sh -c '. $f; @echo'`;
+		die "sh \$?=$?" if $?;
+		eval $vars;
+		die $@ if $@;
+		$VERSION_ID //= '';
+		$ID //= '';
+		if ($ID eq 'debian') {
+			if ($PRETTY_NAME =~ m!/sid\z!) {
+				$VERSION_ID = 'sid';
+			} else {
+				open my $fh, '<', $f or die "open($f): $!";
+				my $msg = do { local $/; <$fh> };
+				die <<EOM;
+ID=$ID, but no VERSION_ID
+==> $f <==
+$msg
+EOM
+			}
+		}
+		last if $ID ne '' && $VERSION_ID ne '';
+	}
+	$ID = 'linux' if $ID eq ''; # cf. os-release(5)
+} elsif ($^O =~ m!\A(?:free|net|open)bsd\z!) { # TODO: net? dragonfly?
+	$ID = $^O;
+	require POSIX;
+	(undef, undef, $release, $version) = POSIX::uname();
+	$VERSION_ID = lc $release;
+	$VERSION_ID =~ s/[^0-9a-z\.\_\-]//sg; # cf. os-release(5)
+} else { # only support POSIX-like and Free systems:
+	die "$^O unsupported";
+}
+$VERSION_ID //= 0; # numeric? could be 'sid', actually...
+my %MIN_VER = (freebsd => v11, openbsd => v7.3, netbsd => v9.3);
+
+if (defined(my $min_ver = $MIN_VER{$^O})) {
+	my $vstr = eval "v$VERSION_ID";
+	die <<EOM if $vstr lt $min_ver;
+ID=$ID release=$release ($version) too old to support
+EOM
+}
+my $PKG_FMT = do {
+	if ($ID eq 'freebsd') { 'pkg' }
+	# *shrug*, as long as the name doesn't conflict with FreeBSD's
+	elsif ($ID eq 'openbsd') { 'pkg_add' }
+	elsif ($ID =~ m!\A(?:debian|ubuntu)\z!) { 'deb' }
+	elsif ($ID =~ m!\A(?:centos|redhat|fedora)\z!) { 'rpm' }
+	else { die "PKG_FMT undefined for ID=$ID" }
+};
+
+# these package group names and '-' syntax are passed to ci/deps.perl
+my $TASKS = do {
+	if ($ID eq 'freebsd') { <<EOM
+all devtest IO::KQueue-
+all devtest IO::KQueue
+all devtest Inline::C-
+all devtest Inline::C
+EOM
+	} elsif ($ID eq 'debian') { <<EOM
+all devtest
+all devtest Search::Xapian-
+all devtest-
+v2essential
+essential
+essential devtest-
+EOM
+	} elsif ($ID eq 'centos') { <<EOM
+v2essential devtest
+essential devtest
+all Search::Xapian-
+EOM
+	} elsif ($ID eq 'openbsd') { <<EOM
+all devtest Inline::C-
+all devtest Inline::C
+all devtest IO::KQueue-
+all devtest IO::KQueue
+EOM
+	} else { die "TODO: support ID=$ID VERSION_ID=$VERSION_ID" }
+};
+
+$TASKS =~ s/^/$PKG_FMT /gms;
+print $TASKS;
diff --git a/ci/profiles.sh b/ci/profiles.sh
deleted file mode 100755
index 04cefa15..00000000
--- a/ci/profiles.sh
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/bin/sh
-# Copyright (C) all contributors <meta@public-inbox.org>
-# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
-
-# Prints OS-specific package profiles to stdout (one per line) to use
-# as command-line args for ci/deps.perl.  Called automatically by ci/run.sh
-
-# set by os-release(5) or similar
-ID= VERSION_ID=
-case $(uname -o 2>/dev/null || uname -s) in
-GNU/Linux)
-	for f in /etc/os-release /usr/lib/os-release
-	do
-		test -f $f || continue
-		. $f
-
-		# Debian sid (and testing) have no VERSION_ID
-		case $ID--$VERSION_ID in
-		debian--)
-			case $PRETTY_NAME in
-			*/sid) VERSION_ID=sid ;;
-			*)
-				echo >&2 "$ID, but no VERSION_ID"
-				echo >&2 "==> $f <=="
-				cat >&2 $f
-				exit 1
-				;;
-			esac
-			;;
-		esac
-
-		case $ID--$VERSION_ID in
-		*--|--*) continue ;;
-		*) break ;;
-		esac
-	done
-	;;
-FreeBSD)
-	ID=freebsd
-	VERSION_ID=$(uname -r | cut -d . -f 1)
-	test "$VERSION_ID" -lt 11 && {
-		echo >&2 "ID=$ID $(uname -r) too old to support";
-		exit 1
-	}
-	;;
-OpenBSD)
-	ID=openbsd
-	VERSION_ID=$(uname -r | cut -d . -f 1)
-	test "$VERSION_ID" -lt 7 && {
-		echo >&2 "ID=$ID $(uname -r) too old to support";
-		exit 1
-	}
-	;;
-esac
-
-case $ID in
-freebsd) PKG_FMT=pkg ;;
-debian|ubuntu) PKG_FMT=deb ;;
-centos|redhat|fedora) PKG_FMT=rpm ;;
-openbsd) PKG_FMT=pkg_add ;; # unsure about name, but it's not FreeBSD `pkg'
-*) echo >&2 "PKG_FMT undefined for ID=$ID in $0"
-esac
-
-case $ID-$VERSION_ID in
-freebsd-11|freebsd-12) sed "s/^/$PKG_FMT /" <<EOF
-all devtest-
-all devtest IO::KQueue-
-all devtest IO::KQueue
-v2essential
-essential
-essential devtest-
-EOF
-	;;
-debian-sid|debian-9|debian-10) sed "s/^/$PKG_FMT /" <<EOF
-all devtest
-all devtest Search::Xapian-
-all devtest-
-v2essential
-essential
-essential devtest-
-EOF
-	;;
-centos-7) sed "s/^/$PKG_FMT /" <<EOF
-v2essential devtest
-essential devtest
-all Search::Xapian-
-EOF
-	;;
-openbsd-7) sed "s/^/$PKG_FMT /" <<EOF
-all devtest-
-all devtest Inline::C-
-all devtest Inline::C
-v2essential
-essential
-essential devtest-
-EOF
-	;;
-esac
diff --git a/ci/run.sh b/ci/run.sh
index 1faf92c2..8f717508 100755
--- a/ci/run.sh
+++ b/ci/run.sh
@@ -13,7 +13,7 @@ fi
 NPROC=${NPROC-$({ getconf _NPROCESSORS_ONLN || getconf NPROCESSORS_ONLN ||
 	gnproc || nproc || echo 2; } 2>/dev/null)}
 
-./ci/profiles.sh | while read args
+$PERL -w ci/profiles.perl | while read args
 do
 	$DO $SUDO $PERL -w ci/deps.perl $args
 	$DO $PERL Makefile.PL

^ permalink raw reply related	[relevance 4%]

* [PATCH 0/8] NetBSD-related updates
@ 2023-09-09 12:01  7% Eric Wong
  2023-09-09 12:01  4% ` [PATCH 4/8] ci/profiles: rewrite in Perl Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2023-09-09 12:01 UTC (permalink / raw)
  To: meta

It actually packages `p5-highlight' like Debian!

Eric Wong (8):
  Makefile.PL: check `getconf NPROCESSORS_ONLN', too
  ipc: define _SC_NPROCESSORS_ONLN for NetBSD
  ci/run.sh: parameterize BUILD_JOBS TEST_JOBS and TEST_TARGET
  ci/profiles: rewrite in Perl
  update CI helper scripts for NetBSD and `pkgin'
  xap_helper: note __cleanup__ works with C++ exceptions
  xap_helper: use _OPENBSD_SOURCE on NetBSD for reallocarray
  xap_helper: clamp workers to USHRT_MAX

 Makefile.PL                  |  3 +-
 ci/deps.perl                 | 24 +++++++--
 ci/profiles.perl             | 93 ++++++++++++++++++++++++++++++++++
 ci/profiles.sh               | 98 ------------------------------------
 ci/run.sh                    | 14 +++---
 lib/PublicInbox/IPC.pm       | 16 ++++--
 lib/PublicInbox/xap_helper.h | 15 +++++-
 7 files changed, 148 insertions(+), 115 deletions(-)
 create mode 100755 ci/profiles.perl
 delete mode 100755 ci/profiles.sh

^ permalink raw reply	[relevance 7%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2023-09-09 12:01  7% [PATCH 0/8] NetBSD-related updates Eric Wong
2023-09-09 12:01  4% ` [PATCH 4/8] ci/profiles: rewrite in Perl Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).