pkg-manifest-generate.pl revision 970
98N/A#! /usr/perl5/bin/perl
98N/A#
98N/A# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
98N/A#
98N/A# Permission is hereby granted, free of charge, to any person obtaining a
98N/A# copy of this software and associated documentation files (the "Software"),
98N/A# to deal in the Software without restriction, including without limitation
98N/A# the rights to use, copy, modify, merge, publish, distribute, sublicense,
98N/A# and/or sell copies of the Software, and to permit persons to whom the
98N/A# Software is furnished to do so, subject to the following conditions:
98N/A#
98N/A# The above copyright notice and this permission notice (including the next
98N/A# paragraph) shall be included in all copies or substantial portions of the
98N/A# Software.
98N/A#
98N/A# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
98N/A# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
98N/A# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
98N/A# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
98N/A# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
98N/A# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
98N/A# DEALINGS IN THE SOFTWARE.
98N/A#
98N/A
98N/A#
98N/A# Script to generate a package manifest for use with pkg(5) from a
98N/A# temporary proto area
98N/A#
98N/A# Usage: pkg-manifest-generate.pl [<attribute>=<value>...]
355N/A#
98N/A# If <manifest input> exists, it is merged into the output.
98N/A# If <manifest input> does not exist, <license file> is included in the output
98N/A# The result is written to <manifest output>, or stdout if not specified
98N/A
156N/Ause strict;
98N/Ause warnings;
156N/A
98N/Amy %options;
98N/A
98N/Aforeach my $arg (@ARGV) {
98N/A my ($attr, $val) = split /=/, $arg, 2;
98N/A
98N/A push @{$options{$attr}}, $val;
98N/A}
98N/A
98N/Asub required_option_list {
98N/A my ($opt, $message) = @_;
98N/A
98N/A if (!exists $options{$opt}) {
98N/A die ("Must specify $opt $message\n");
98N/A }
98N/A return $options{$opt};
98N/A}
98N/A
98N/Asub required_option {
98N/A my ($opt, $message) = @_;
98N/A
98N/A my $opt_list_ref = required_option_list(@_);
98N/A
98N/A if (scalar(@{$opt_list_ref}) != 1) {
98N/A die ("Must specify only one value for $opt $message\n");
98N/A }
98N/A return $opt_list_ref->[0];
98N/A}
98N/A
98N/Amy %actions_seen = ();
156N/Amy @manifest_header;
98N/A
98N/A# Check if there is an existing manifest to merge with
98N/Aif (exists $options{'input_manifest'}) {
98N/A foreach my $mf (@{$options{'input_manifest'}}) {
98N/A next if (! -f $mf);
98N/A open my $INPUT_MF, '<', $mf or die "Cannot open input_manifest $mf: $!\n";
98N/A my $action = "";
98N/A while (my $im = <$INPUT_MF>) {
98N/A chomp($im);
98N/A if ($im =~ m{^(.*)\\$}) { # Line continues
98N/A $action .= $1 . " ";
98N/A } else {
98N/A $action .= $im;
98N/A push @manifest_header, $action;
98N/A
98N/A $action =~ s{\s+}{ }g;
98N/A if ($action =~ m{ path=(\S+)}) {
98N/A $actions_seen{$1} = $action;
98N/A } else {
98N/A $actions_seen{$action} = $action;
98N/A }
98N/A
98N/A $action = "";
98N/A }
98N/A }
98N/A close $INPUT_MF;
98N/A }
98N/A}
98N/A
98N/A# Generate a manifest header if not merging into an existing file
98N/Aif (!@manifest_header) {
98N/A
98N/A my $manifest_license_listref = required_option_list
98N/A ('manifest_license', 'when not merging with existing manifest.');
98N/A
98N/A foreach my $lf (@{$options{'manifest_license'}}) {
98N/A open my $LICENSE, '<', $lf or die "Cannot open manifest_license $lf: $!\n";
98N/A while (my $ll = <$LICENSE>) {
98N/A chomp($ll);
98N/A if ($ll !~ m{^\#}) {
98N/A $ll = '# ' . $ll;
98N/A }
98N/A push @manifest_header, $ll;
98N/A }
98N/A close $LICENSE;
355N/A }
98N/A
my $pkg_name = required_option ('pkg_name',
'when not merging with existing manifest.');
push @manifest_header, join('', 'set name=pkg.fmri value=pkg:/',
$pkg_name, '@$(PKGVERS)');
push @manifest_header, 'set name=pkg.description ' .
'value="XXX: Please provide a descriptive paragraph for the package."';
my $pkg_summary = '';
SDIR: foreach my $sdir (@{$options{'source_dir'}}) {
foreach my $bdir (glob("build-*/$sdir")) {
# First try looking in a README file for a short summary
my $rf = join('/', $bdir, 'README');
if (open my $README, '<', $rf) {
while (my $readme = <$README>) {
chomp($readme);
last if $readme =~ m{^[\-=\s]*$};
$readme =~ s{[\t\n]+}{ }g;
if ($pkg_summary =~ m{\S$}) {
$pkg_summary .= ' ';
}
$pkg_summary .= $readme;
}
close $README;
last SDIR if $pkg_summary ne '';
}
# Then try looking in man pages
my @manpage = glob("$bdir/man/*.man");
push @manpage, glob("$bdir/*.man");
foreach my $manpage (@manpage) {
if ($manpage && (-f $manpage)) {
my $desc;
open(my $MANPAGE, '<', $manpage) or warn "Cannot read $manpage\n";
while (my $l = <$MANPAGE>) {
if ($l =~ /^.SH NAME/) {
$desc = <$MANPAGE>;
last;
}
}
close($MANPAGE);
chomp($desc);
# Remove backslashes, such as \- instead of -
$desc =~ s/\\//g;
if ($sdir =~ /^xf86-(input|video)-(.*)-.*$/) {
$desc =~ s/driver$/driver for the Xorg X server/;
}
if ($desc !~ m{^\s*$}) {
$pkg_summary = $desc;
last SDIR;
}
}
}
}
}
if ($pkg_summary eq '') {
$pkg_summary =
'XXX: Please provide a short name for the package';
} else {
$pkg_summary =~ s{^\s+}{};
$pkg_summary =~ s{\s+$}{};
}
push @manifest_header, join('', 'set name=pkg.summary ',
'value="', $pkg_summary, '"');
if (exists $options{'classification'}) {
my $pkg_class = $options{'classification'};
push @manifest_header, join('', 'set name=info.classification ',
'value="org.opensolaris.category.2008:',
$pkg_class, '"');
}
}
## Contents
my @manifest_contents;
my $subdir64 = required_option('subdir_64',
'with the name used for the subdirectory containing 64-bit objects');
my $proto_area_ref = required_option_list('proto_area',
'for files to include in manifest');
foreach my $proto_area (@{$proto_area_ref}) {
my $pkgsend_cmd = join(' ', 'pkgsend', 'generate', $proto_area);
open my $PKGSEND, '-|', $pkgsend_cmd or die "Cannot run $pkgsend_cmd: $!\n";
while (my $ps = <$PKGSEND>) {
chomp($ps);
# Skip -uninstalled.pc files, since those are only used during build
next if $ps =~ m{^file\b.*\bpath=.*-uninstalled.pc\b};
# Convert 64-bit subdirectories to platform-independent form
$ps =~ s{([=/])${subdir64}\b}{$1\$(ARCH64)}g;
# Don't add duplicates of actions we've already got
my $action = $ps;
if ($ps =~ m{ path=(\S+)}) {
$action = $1;
} else {
$action =~ s{\s+}{ }g;
}
next if exists $actions_seen{$action};
$actions_seen{$action} = $ps;
# Drop file path from file actions, so we always use the path attribute
$ps =~ s{^file (\S+) (.* path=\1)}{file $2};
# Drop attributes that will be generated during package build
push @manifest_contents,
join(" ", grep (! /^(mode|group|owner|pkg.size|timestamp)=/,
split /\s+/, $ps));
}
close $PKGSEND;
}
my $pkgfmt_cmd = 'pkgfmt';
if (exists $options{'pkgfmt'}) {
$pkgfmt_cmd = join(' ', @{$options{'pkgfmt'}});
}
open my $PKGFMT, '|-', $pkgfmt_cmd or die "Cannot run $pkgfmt_cmd: $!\n";
foreach my $line (@manifest_header, @manifest_contents) {
print $PKGFMT $line, "\n";
}
close $PKGFMT;