[Git][haskell-team/haskell-devscripts][master] Introduce config_to_package_id method
Ilias Tsitsimpis (@iliastsi)
gitlab at salsa.debian.org
Fri Sep 19 20:55:12 BST 2025
Ilias Tsitsimpis pushed to branch master at Debian Haskell Group / haskell-devscripts
Commits:
4fd7aecd by Ilias Tsitsimpis at 2025-09-19T22:54:44+03:00
Introduce config_to_package_id method
A package's ID, name, version, and hash, is currently determined by
parsing the name of its configuration file in several different
locations. This approach is brittle; if the naming convention for these
files changes, as it recently did with GHC adding a hash after the
version, you have to update the parsing logic in every place it's used.
To solve this, we consolidate this logic into a single function called
config_to_package_id. This new method will take the path to the
configuration file and return the package's ID. By doing this, we create
a single point of truth. Now, if the file naming convention ever changes
again, we only need to update the parsing logic inside this one method,
making our code more robust and easier to maintain.
- - - - -
5 changed files:
- debian/changelog
- dh_haskell_depends_cabal
- dh_haskell_provides_ghc
- dh_haskell_shlibdeps
- lib/Debian/Debhelper/Buildsystem/Haskell/Recipes.pm
Changes:
=====================================
debian/changelog
=====================================
@@ -1,3 +1,9 @@
+haskell-devscripts (0.16.36) unstable; urgency=medium
+
+ * Introduce config_to_package_id method
+
+ -- Ilias Tsitsimpis <iliastsi at debian.org> Fri, 19 Sep 2025 21:07:26 +0300
+
haskell-devscripts (0.16.35) experimental; urgency=medium
* dh_haskell_provides_ghc: strip "-inplace" from configs.
=====================================
dh_haskell_depends_cabal
=====================================
@@ -35,6 +35,7 @@ use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(
ghc_pkg_command
load_ghc_database
hashed_id_to_virtual_installable
+ config_to_package_id
);
use Debian::Debhelper::Dh_Lib;
@@ -149,10 +150,10 @@ sub cabal_depends {
my @prerequisites;
for my $config (@configs) {
- my $name = path($config)->basename(qr{ [.]conf $}x);
+ my $package_id = config_to_package_id($config, $ghc_pkg, $tmp_db);
my $depends
= run($ghc_pkg, '--package-db', $tmp_db, qw{--simple-output field},
- $name, 'depends');
+ '--unit-id', $package_id, 'depends');
push(@prerequisites, split($SPACE, $depends // $EMPTY));
}
=====================================
dh_haskell_provides_ghc
=====================================
@@ -36,6 +36,7 @@ use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(
ghc_pkg_command
load_ghc_database
hashed_id_to_virtual_installable
+ config_to_package_id
);
use Debian::Debhelper::Dh_Lib;
@@ -71,16 +72,8 @@ for my $installable (@{ $dh{DOPACKAGES} }) {
my @hashed_ids;
for my $config (@configs) {
-
- my $name = path($config)->basename(qr{ [.]conf $}x);
- (my $namever = $name) =~ s/-inplace$//;
- push(
- @hashed_ids,
- run(
- $ghc_pkg, '--package-db', $ENV{DEB_GHC_DATABASE},
- qw{--simple-output field},
- $namever, 'id'
- ));
+ my $package_id = config_to_package_id($config, $ghc_pkg, $ENV{DEB_GHC_DATABASE});
+ push(@hashed_ids, $package_id);
}
my $substvars_path = "debian/$installable.substvars";
=====================================
dh_haskell_shlibdeps
=====================================
@@ -35,6 +35,7 @@ use Debian::Debhelper::Buildsystem::Haskell::Recipes qw(
hc_pkgdir
ghc_pkg_command
load_ghc_database
+ config_to_package_id
);
use Debian::Debhelper::Dh_Lib;
@@ -60,23 +61,27 @@ for my $installable (@{ $dh{DOPACKAGES} }) {
my @gcc_args;
- my @hashed_ids = map { path($_)->basename(qr{ [.]conf $}x) } @configs;
- for my $hashed_id (@hashed_ids) {
+ my @package_ids;
+ for my $config (@configs) {
+ my $package_id = config_to_package_id($config, $ghc_pkg, $ENV{DEB_GHC_DATABASE});
+ push(@package_ids, $package_id);
+ }
+ for my $package_id (@package_ids) {
my $libdir_string = decode_utf8(
run(
- $ghc_pkg, '--package-db',
- $ENV{DEB_GHC_DATABASE}, qw{--simple-output field},
- $hashed_id, 'library-dirs'
+ $ghc_pkg, '--package-db', $ENV{DEB_GHC_DATABASE},
+ qw{--simple-output field},
+ '--unit-id', $package_id, 'library-dirs'
));
my @lib_dirs = split($SPACE, $libdir_string);
push(@gcc_args, (map { "-L$_" } @lib_dirs));
my $library_string = decode_utf8(
run(
- $ghc_pkg, '--package-db',
- $ENV{DEB_GHC_DATABASE}, qw{--simple-output field},
- $hashed_id, 'extra-libraries'
+ $ghc_pkg, '--package-db', $ENV{DEB_GHC_DATABASE},
+ qw{--simple-output field},
+ '--unit-id', $package_id, 'extra-libraries'
));
my @libraries = split($SPACE, $library_string);
push(@gcc_args, (map { "-l$_" } @libraries));
=====================================
lib/Debian/Debhelper/Buildsystem/Haskell/Recipes.pm
=====================================
@@ -43,6 +43,7 @@ BEGIN {
load_ghc_database
own_cabal_prerequisites
hashed_id_to_virtual_installable
+ config_to_package_id
clean_recipe
make_setup_recipe
configure_recipe
@@ -481,6 +482,24 @@ sub hashed_id_to_virtual_installable {
return $virtual;
}
+=item config_to_package_id
+
+=cut
+
+sub config_to_package_id {
+ my ($config, $ghc_pkg, $package_db) = @_;
+
+ my $name = path($config)->basename(qr { [.]conf $}x);
+
+ $name =~ m/^([^ ]*?)-(\d[\d.]*)(-\S+)?$/;
+ $name = "$1-$2";
+
+ my $package_id = run($ghc_pkg, '--package-db', $package_db,
+ qw{--simple-output field}, $name, 'id');
+
+ return $package_id;
+}
+
=item clean_recipe
=cut
View it on GitLab: https://salsa.debian.org/haskell-team/haskell-devscripts/-/commit/4fd7aecd88ea73c08ee139bc86670c0a328c3768
--
View it on GitLab: https://salsa.debian.org/haskell-team/haskell-devscripts/-/commit/4fd7aecd88ea73c08ee139bc86670c0a328c3768
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-haskell-commits/attachments/20250919/61e15e0c/attachment-0001.htm>
More information about the Pkg-haskell-commits
mailing list