unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] ci/deps.perl: WIP dependency testing
@ 2019-05-08  2:50 Eric Wong
  2019-05-08  2:58 ` [WIP] " Eric Wong
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Wong @ 2019-05-08  2:50 UTC (permalink / raw)
  To: meta

manifest
---
 MANIFEST     |   1 +
 ci/deps.perl | 185 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 186 insertions(+)
 create mode 100755 ci/deps.perl

diff --git a/MANIFEST b/MANIFEST
index da9e364..d98e540 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -27,6 +27,7 @@ MANIFEST
 Makefile.PL
 README
 TODO
+ci/deps.perl
 contrib/css/216dark.css
 contrib/css/216light.css
 contrib/css/README
diff --git a/ci/deps.perl b/ci/deps.perl
new file mode 100755
index 0000000..82172ff
--- /dev/null
+++ b/ci/deps.perl
@@ -0,0 +1,185 @@
+#!/usr/bin/perl -w
+# Copyright (C) 2019 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+# Helper script for installing/uninstalling CI packages
+use strict;
+my $usage = "$0 <deb|pkg|rpm> PROFILE [PROFILE_MOD]";
+my $pkg_fmt = shift or die $usage;
+@ARGV or die $usage;
+
+# package profiles
+my $profiles = {
+	essential => [ qw(
+		git
+		perl
+		Date::Parse
+		Devel::Peek
+		Email::Simple
+		Email::MIME
+		Email::MIME::ContentType
+		Encode::MIME::Header
+		Plack
+		URI::Escape
+		) ],
+	optional => [ qw(
+		BSD::Resource
+		Crypt::CBC
+		DBD::SQLite
+		DBI
+		Filesys::Notify::Simple
+		IO::Compress::Gzip
+		Inline::C
+		Net::Server
+		Plack::Middleware::Deflater
+		Plack::Middleware::ReverseProxy
+		Search::Xapian
+		Socket6
+		highlight.pm
+		) ],
+	testonly => [ qw(
+		IPC::Run
+		Test::HTTP::Server::Simple
+		XML::Feed
+		curl
+		w3m
+		) ],
+};
+
+# package names which can't be mapped automatically:
+my $non_auto = {
+	'perl' => { pkg => 'perl5' },
+	'Date::Parse' => {
+		deb => 'libtimedate-perl',
+		pkg => 'p5-TimeDate',
+		rpm => 'perl-TimeDate',
+	},
+	'Devel::Peek' => {
+		deb => 'perl', # libperl5.XX, but the XX varies
+		pkg => 'perl5',
+	},
+	'Encode::MIME::Header' => {
+		deb => 'libencode-perl',
+		pkg => 'perl5',
+		rpm => 'perl-Encode',
+	},
+	'IO::Compress::Gzip' => {
+		deb => 'perl', # perl-modules-5.xx
+		pkg => 'perl5',
+		rpm => 'perl-PerlIO-gzip',
+	},
+	'DBD::SQLite' => { deb => 'libdbd-sqlite3-perl' },
+	'URI::Escape' => {
+		deb => 'liburi-perl',
+		pkg => 'p5-URI',
+		rpm => 'perl-URI',
+	},
+	'highlight.pm' => {
+		deb => 'libhighlight-perl',
+		pkg => [],
+		rpm => [],
+	},
+
+	# we call xapian-compact(1) in public-inbox-compact(1)
+	'xapian-tools' => {
+		deb => 'xapian-tools',
+		pkg => 'xapian-core',
+		rpm => [], # ???
+	},
+};
+
+my (@pkg_install, @pkg_remove, %all);
+for my $ary (values %$profiles) {
+	$all{$_} = \@pkg_remove for @$ary;
+}
+$profiles->{all} = [ keys %all ]; # pseudo-profile for all packages
+
+for my $profile (@ARGV) {
+	if ($profile =~ s/-\z//) {
+		# like apt-get, trailing "-" means remove
+		profile2dst($profile, \@pkg_remove);
+	} else {
+		profile2dst($profile, \@pkg_install);
+	}
+}
+
+# fill in @pkg_install and @pkg_remove:
+while (my ($pkg, $dst_pkg_list) = each %all) {
+	push @$dst_pkg_list, list(pkg2ospkg($pkg, $pkg_fmt));
+}
+
+my @apt_opts =
+	qw(-o APT::Install-Recommends=false -o APT::Install-Suggests=false);
+
+# OS-specific cleanups appreciated
+
+if ($pkg_fmt eq 'deb') {
+	run('apt-get', @apt_opts, qw(install -yqq --purge), @pkg_install,
+		# apt-get lets you suffix a package with "-" to
+		# remove it in an "install" sub-command:
+		map { "$_-" } @pkg_remove);
+	run('apt-get', @apt_opts, qw(autoremove --purge -yqq));
+} elsif ($pkg_fmt eq 'pkg') {
+	# FreeBSD, maybe other *BSDs are similar?
+	run(qw(pkg remove -y), @pkg_remove) if @pkg_remove;
+	run(qw(pkg install -y), @pkg_install) if @pkg_install;
+# TODO: yum / rpm support
+} else {
+	die "unsupported package format: $pkg_fmt\n";
+}
+exit 0;
+
+
+# map a generic package name to an OS package name
+sub pkg2ospkg {
+	my ($pkg, $fmt) = @_;
+
+	# check explicit overrides, first:
+	if (my $ospkg = $non_auto->{$pkg}->{$fmt}) {
+		return $ospkg;
+	}
+
+	# check common Perl module name patterns:
+	if ($pkg =~ /::/ || $pkg =~ /\A[A-Z]/) {
+		if ($fmt eq 'deb') {
+			$pkg =~ s/::/-/g;
+			$pkg =~ tr/A-Z/a-z/;
+			return "lib$pkg-perl";
+		} elsif ($fmt eq 'rpm') {
+			$pkg =~ s/::/-/g;
+			return "perl-$pkg"
+		} elsif ($fmt eq 'pkg') {
+			$pkg =~ s/::/-/g;
+			return "p5-$pkg"
+		} else {
+			die "unsupported package format: $fmt for $pkg\n"
+		}
+	}
+
+	# use package name as-is (e.g. 'curl' or 'w3m')
+	$pkg;
+}
+
+sub profile2dst {
+	my ($profile, $dst_pkg_list) = @_;
+	if (my $pkg_list = $profiles->{$profile}) {
+		$all{$_} = $dst_pkg_list for @$pkg_list;
+	} elsif ($all{$profile}) { # $profile is just a package name
+		$all{$profile} = $dst_pkg_list;
+	} else {
+		die "unrecognized profile or package: $profile\n";
+	}
+}
+
+sub run {
+	print join(' ', @_), "\n";
+	return if $ENV{DRY_RUN};
+	return if system(@_) == 0;
+	warn 'command failed: ', join(' ', @_), "\n";
+	exit($? >> 8);
+}
+
+# ensure result is can be pushed into an array:
+sub list {
+	my ($pkg) = @_;
+	ref($pkg) eq 'ARRAY' ? @$pkg : $pkg;
+}
-- 
EW


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-05-08  2:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-08  2:50 [PATCH] ci/deps.perl: WIP dependency testing Eric Wong
2019-05-08  2:58 ` [WIP] " Eric Wong

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).