~mvo/jockey/mvo

« back to all changes in this revision

Viewing changes to debian/debhelper/dh_modaliases

  • Committer: Martin Pitt
  • Date: 2010-11-25 18:03:25 UTC
  • Revision ID: martin.pitt@canonical.com-20101125180325-u4tuuxa83lmcyx2h
* Add support for putting modalias definitions in driver package's
  debian/control, so that we can replace the /usr/share/jockey/modaliases/*
  lists with lookups in the package database (see blueprint
  hardware-desktop-n-package-field-modaliases). With this we can drop the
  foo-modaliases packages, and shipping third-party driver packages will
  just work in Jockey without any further integration.
  - Add debian/debhelper/dh_jockey: Debhelper program to produce a
    ${modaliases} substvar from scanning .ko files or
    debian/packagename.modaliases.
  - Add debian/debhelper/test_dh_jockey: Automatic test script for
    dh_jockey.
  - Add debian/debhelper/modaliases.pm: dh_auto sequencer for dh_modaliases.
  - debian/control: Add dh-modaliases package.
  - debian/dh-modaliases.install: Install dh_modaliases and modaliases.pm.
  - debian/rules: Create manpage from dh_modaliases POD.
  - jockey/oslib.py: Add apt implementation for package_header_modaliases().
  - tests/oslib.py: Add test case for our package_header_modaliases()
    implementation. This only really tests anything if there is at least one
    package with a "Modaliases:" field in the local apt repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
 
 
3
=head1 NAME
 
4
 
 
5
dh_modaliases - scan kmod modaliases and provide a substvar for them
 
6
 
 
7
=cut
 
8
 
 
9
use strict;
 
10
use File::Find;
 
11
use Debian::Debhelper::Dh_Lib;
 
12
 
 
13
=head1 SYNOPSIS
 
14
 
 
15
B<dh_modaliases> [S<I<debhelper options>>]
 
16
 
 
17
=head1 DESCRIPTION
 
18
 
 
19
B<dh_modaliases> is useful for packages that ship third-party kernel modules,
 
20
either in binary form, or as sources (with e. g. DKMS). It extracts the
 
21
modules' modaliases from either the compile .ko files themselves (for packages
 
22
which ship them in compiled form, using B<modinfo>), or from a package file
 
23
B<debian/>I<package>B<.modaliases> (see below).
 
24
 
 
25
I creates a package substitution variable C<${modaliases}> which you should add
 
26
to C<debian/control> as
 
27
 
 
28
=over 4
 
29
 
 
30
XB-Modaliases: ${modaliases}
 
31
 
 
32
=back
 
33
 
 
34
This enables software which is looking for missing driver packages (such as
 
35
Jockey or the operating system installer) to identify which package(s) will
 
36
provide a driver for a piece of hardware, identified by its modalias.
 
37
 
 
38
=head1 PACKAGE MODALIAS FILES
 
39
 
 
40
If a package ships source code (using DKMS, module-assistant, etc.) instead of
 
41
compiled binary kernel modules, then B<dh_modaliases> can't figure out the
 
42
modaliases by scanning the *.ko files, and you have to provide the modalias
 
43
list manually as a package file B<debian/>I<package>B<.modaliases>.
 
44
 
 
45
The format matches the /lib/modules/`uname -r`/modules.alias file from the
 
46
Linux kernel. Examples:
 
47
 
 
48
=over 4
 
49
 
 
50
alias ssb:v1234id5678 snd_super_booster 
 
51
alias pci:v000010DEd0000004Esv*sd*bc03sc*i* nvidia_current
 
52
 
 
53
=back
 
54
 
 
55
You can generate such a list if you locally build and install this module, and
 
56
then run
 
57
 
 
58
=over 4
 
59
 
 
60
modinfo mymodname | perl -nae 'print "alias $1 mymodname\n" if /^alias:\s+(.*)$/'
 
61
 
 
62
=back
 
63
 
 
64
(replacing "mymodname" with the actual module name).
 
65
 
 
66
=head1 OPTIONS
 
67
 
 
68
The standard debhelper options are supported.
 
69
 
 
70
=cut
 
71
 
 
72
init();
 
73
 
 
74
my $aliases;
 
75
 
 
76
sub modalises_from_ko {
 
77
    my $name = $_;
 
78
    return unless /\.ko$/;
 
79
    return if -l $_ or -d $_; # Skip directories and symlinks
 
80
 
 
81
    # See if we were asked to exclude this file.
 
82
    foreach my $f (@{$dh{EXCLUDE}}) {
 
83
            return if ($File::Find::name =~ m/\Q$f\E/);
 
84
    }
 
85
 
 
86
    my ($modname) = ($name =~ /^(.*)\.ko$/);
 
87
    $modname =~ s/-/_/g; # canonical names are with underscores
 
88
    my @a;
 
89
    open M, '-|', 'modinfo', $name or die "open: $!";
 
90
    while (<M>) {
 
91
        if (/^alias:\s*(.*)$/) {
 
92
            verbose_print("$File::Find::name: module $modname has alias $1");
 
93
            push @a, $1;
 
94
        }
 
95
    }
 
96
    if ($aliases) {
 
97
        $aliases .= ', ';
 
98
    }
 
99
    $aliases .= $modname . '(' . (join ', ', @a) . ')';
 
100
}
 
101
 
 
102
sub modalises_from_pkgfile {
 
103
    my %module_alias_map = ();
 
104
    open F, $_[0];
 
105
    while (<F>) {
 
106
        next if /^#/;
 
107
 
 
108
        if (/^alias\s*([^[:space:]]+)\s*([^[:space:]]+)/) {
 
109
            verbose_print("package file $_[0]: module $2 has alias $1");
 
110
            push @{$module_alias_map{$2}}, $1;
 
111
        } else {
 
112
            warning("$_[0]: cannot translate line into modalias: $_");
 
113
        }
 
114
    }
 
115
 
 
116
    foreach my $m (sort keys %module_alias_map) {
 
117
        if ($aliases) {
 
118
            $aliases .= ', ';
 
119
        }
 
120
        $aliases .= $m . '(' . (join ', ', @{$module_alias_map{$m}}) . ')';
 
121
    }
 
122
}
 
123
 
 
124
foreach my $package (@{$dh{DOPACKAGES}}) 
 
125
{
 
126
    my $tmp = tmpdir($package);
 
127
 
 
128
    delsubstvar($package, 'modaliases');
 
129
    $aliases = '';
 
130
    my $manual_list = pkgfile($package, 'modaliases');
 
131
    if ($manual_list) {
 
132
        modalises_from_pkgfile $manual_list;
 
133
    } else {
 
134
        find(\&modalises_from_ko, tmpdir($package));
 
135
    }
 
136
    addsubstvar($package, 'modaliases', $aliases);
 
137
}
 
138
 
 
139
=head1 SEE ALSO
 
140
 
 
141
L<debhelper(1)>, L<dkms(8)>
 
142
 
 
143
This program is an extension to debhelper.
 
144
 
 
145
=head1 AUTHOR
 
146
 
 
147
Martin Pitt <martin.pitt@ubuntu.com>
 
148
 
 
149
=cut