[Mud-builder-commits] r255 - in trunk: lib/MUD lib/MUD/Fetch packages
jaffa at garage.maemo.org
jaffa at garage.maemo.org
Mon Jan 19 03:55:57 EET 2009
Author: jaffa
Date: 2009-01-19 03:55:56 +0200 (Mon, 19 Jan 2009)
New Revision: 255
Modified:
trunk/lib/MUD/Build.pm
trunk/lib/MUD/Fetch/Tarball.pm
trunk/lib/MUD/Package.pm
trunk/packages/vim.xml
Log:
Make MUD::Package object oriented, in preparation for a phased migration to a new package format. Refactor is not quite complete, but there should be no regressions with this intermediate stage.
Modified: trunk/lib/MUD/Build.pm
===================================================================
--- trunk/lib/MUD/Build.pm 2009-01-17 19:35:15 UTC (rev 254)
+++ trunk/lib/MUD/Build.pm 2009-01-19 01:55:56 UTC (rev 255)
@@ -49,7 +49,9 @@
=item package
-Name of the package. This is required.
+Name of the package. This is required. This can either a
+L<MUD::Package> I<reference>, or the name of a package. The use of
+reference passing is used when doing recursive, dependency builds.
=back
@@ -67,7 +69,7 @@
=item _init
-Initialise a new instance.
+Initialise a new instance. Private method.
=cut
@@ -150,11 +152,11 @@
my $buildDir = basename($self->{data}->{build} || '.');
my $origBDir = $buildDir;
$buildDir =~ s/-src\b//;
- my $version = $self->{data}->{version} || $self->{data}->{data}->{deb}->{version};
+ my $version = $self->{data}->version;
print "Version = $version, buildDir = $buildDir\n";
$version ||= $1 if $buildDir =~ s/-(\d[\w\-\.\+\:]+\w|\d\w*)*$//;
$version ||= $1 if !$version and $buildDir =~ s/(\d+)$//;
- $version = $self->{data}->{data}->{deb}->{version} || $version;
+ $version = $self->{data}->version || $version;
$version ||= 1;
print "Version = $version, buildDir = $buildDir\n";
$buildDir = $self->{package} unless $buildDir =~ /^[a-z0-9\-\+]+$/;
@@ -165,7 +167,7 @@
print "Build dir = $buildDir\n";
rename $origBDir, $buildDir if $origBDir ne $buildDir;
- $self->{data}->{version} = $version;
+ $self->{data}->version($version);
$self->{data}->{build} = File::Spec->rel2abs($buildDir, $self->{workdir});
print "Set build dir to [".$self->{data}->{build}."]\n";
system('ln', '-snf', $self->{data}->{build}, $self->{workdir}.'/.build');
@@ -274,7 +276,7 @@
if (@buildDeps) {
print "Adding calculated build-deps of [".join(', ', @buildDeps)."]\n";
my $control = $self->readDebControl();
- $control = MUD::Package->setField($control, "Build-Depends", join(', ', @buildDeps));
+ MUD::Package::setField($control, "Build-Depends", join(', ', @buildDeps));
$self->writeDebControl($control);
}
}
@@ -448,19 +450,6 @@
close(OUT) or croak "Unable to close control: $!\n";
}
-sub readValueFromFile {
- my ($file) = @_;
- my $contents = '';
-
- open(IN, $file) or croak "Unable to read file $file: $!\n";
- while(<IN>) { $contents .= $_ ; }
- close(IN);
-
- $contents =~ s/\n/\\n/g;
-
- return $contents;
-}
-
sub patchDebControl {
my $self = shift;
@@ -470,8 +459,8 @@
# -- Fix standards version and uploaders...
#
$control =~ s/^(Section:.*)devel/$1libdev/;
- $control = MUD::Package->setField($control, 'Standards-Version', '3.6.1');
- $control = MUD::Package->setField($control, 'Uploaders', 'MUD Project <mud-builder-team at garage.maemo.org>');
+ MUD::Package::setField($control, 'Standards-Version', '3.6.1');
+ MUD::Package::setField($control, 'Uploaders', 'MUD Project <mud-builder-team at garage.maemo.org>');
# -- Fix "BROKEN" libraries...
#
@@ -485,7 +474,7 @@
$control =~ s/\Q${name}\E-dev/${libdevname}/mgi;
# -- Fix section...
- #
+ # TODO Use $self->{data}->section
my $userSection = defined ($self->{data}->{data}->{deb}->{'prefix-section'})
? $self->{data}->{data}->{deb}->{'prefix-section'} : $self->{package} !~ /^lib/;
@@ -523,28 +512,20 @@
# -- Description...
#
- my $description = ref($self->{data}->{data}->{deb}->{description})
- ? readValueFromFile($self->{data}->{data}->{deb}->{description}->{file})
- : $self->{data}->{data}->{deb}->{description};
- $control = MUD::Package->setField($control, "Description", $description) if $description;
+ MUD::Package::setField($control, "Description", $self->{data}->description);
# -- Upgrade Description...
#
- my $upgradeDescription = ref($self->{data}->{data}->{deb}->{'upgrade-description'})
- ? readValueFromFile($self->{data}->{data}->{deb}->{'upgrade-description'}->{file})
- : $self->{data}->{data}->{deb}->{'upgrade-description'};
- $control = MUD::Package->setField($control, "XB-Maemo-Upgrade-Description", $upgradeDescription) if $upgradeDescription;
+ MUD::Package::setField($control, "XB-Maemo-Upgrade-Description", $self->{data}->upgradeDescription);
# -- Display Name...
#
- my $displayName = $self->{data}->{data}->{deb}->{'display-name'};
- $control = MUD::Package->setField($control, "XB-Maemo-Display-Name", $displayName) if $displayName;
+ MUD::Package::setField($control, "XB-Maemo-Display-Name", $self->{data}->displayName);
# -- Other control fields...
#
- while (my ($k, $v) = each %{ $self->{data}->{data}->{deb} }) {
- next if $k =~ /^(icon|prefix-section|library|libdev|upgrade-description|description|display-name|version)$/;
- $control = MUD::Package->setField($control, $k, $v);
+ while (my ($k, $v) = each %{ $self->{data}->controlFields }) {
+ MUD::Package::setField($control, $k, $v);
}
$self->writeDebControl($control) if $control ne $origControl;
@@ -552,7 +533,7 @@
# -- Modify changelog to contain this build...
#
# debchange doesn't do anything if the version is already there except moan
- system('debchange', '-v', $self->{data}->{version},
+ system('debchange', '-v', $self->{data}->version,
'-p', '--noquery',
'Build using mud-builder by '.($ENV{USER} || 'unknown'));
@@ -565,7 +546,7 @@
=head1 COPYRIGHT
-(c) Andrew Flegg 2007 - 2008. Released under the Artistic Licence:
+(c) Andrew Flegg 2007 - 2009. Released under the Artistic Licence:
L<http://www.opensource.org/licenses/artistic-license-2.0.php>
=head1 SEE ALSO
Modified: trunk/lib/MUD/Fetch/Tarball.pm
===================================================================
--- trunk/lib/MUD/Fetch/Tarball.pm 2009-01-17 19:35:15 UTC (rev 254)
+++ trunk/lib/MUD/Fetch/Tarball.pm 2009-01-19 01:55:56 UTC (rev 255)
@@ -41,7 +41,7 @@
@end = grep { !$s{$_} } @end;
$self->{package}->{build} = $end[0];
}
- $self->{package}->{version} = $1 if $basename =~ /-(\d[\w\-\.]+\w|\d\w*)*$/;
+ $self->{package}->version($1) if $basename =~ /-(\d[\w\-\.]+\w|\d\w*)*$/;
my @deps = split /\s*,\s*/, ($self->{package}->{data}->{fetch}->{depends} || '');
foreach my $dep (@deps) {
Modified: trunk/lib/MUD/Package.pm
===================================================================
--- trunk/lib/MUD/Package.pm 2009-01-17 19:35:15 UTC (rev 254)
+++ trunk/lib/MUD/Package.pm 2009-01-19 01:55:56 UTC (rev 255)
@@ -1,8 +1,42 @@
-#
-# MUD::Package (c) Andrew Flegg 2007
-# ~~~~~~~~~~~~ Released under the Artistic Licence
-# http://mud-builder.garage.maemo.org/
+=head1 NAME
+
+MUD::Package - Define a MUD package, and the data/definitions
+ contained within.
+
+=head1 SYNOPSIS
+
+This class abstracts L<MUD::Build> from the underlying container
+format for MUD packages. This allows for future expansion in changing
+the disk structure etc. by changing this class alone. Given a package
+name, it will find the various artifacts: XML definition, icons etc.
+
+ use MUD::Package;
+ my $pkg = MUD::Package->new();
+ $pkg->load('vim');
+ my $name = $pkg->name;
+ my $iconFile = $pkg->icon(26);
+ my $description = $pkg->description;
+ my $upgradeDesc = $pkg->upgradeDescription;
+ my $displayName = $pkg->displayName;
+ my @patchFiles = $pkg->patches;
+ my $controlFields = $pkg->controlFields;
+ my $section = $pkg->section;
+ my $version = $pkg->version;
+ my $extraFiles = $pkg->extraFiles;
+
+There are also convenience methods for dealing with Debian control
+files:
+
+ MUD::Package::setField($controlData, 'Section', 'user/network');
+ my @values = MUD::Package::parseField($controlData, 'Section');
+
+=head1 DESCRIPTION
+
+=over 12
+
+=cut
+
package MUD::Package;
use strict;
@@ -12,7 +46,7 @@
use Carp;
@ISA = qw();
-$VERSION = '0.10';
+$VERSION = '0.20';
# Based on Maemo Packaging Policy & Debian Policy
@PERMITTED_SECTIONS = qw(accessories communication games multimedia office
@@ -23,6 +57,15 @@
libdevel mail math misc net news oldlibs perl python
science shells sound tex text utils web x11);
+
+=item new( [ORIGINAL] )
+
+Create a new package instance. This can be optionally
+initialised by passing in an existing package as
+C<ORIGINAL>.
+
+=cut
+
sub new {
my $that = shift;
$that = ref($that) || $that;
@@ -32,12 +75,29 @@
return $self;
}
+
+=item _init
+
+Initialise a new instance. Private method.
+
+=cut
+
sub _init {
my $self = shift;
$self->{config} ||= new MUD::Config();
}
+
+=item load( NAME )
+
+Load information for the given package into this object.
+This will load an XML file from C<PACKAGES_DIR/name.xml>,
+run any SDK-specific XSLT and initialise any environment
+variables defined for the build.
+
+=cut
+
sub load {
my $self = shift;
my ($name) = @_;
@@ -77,11 +137,193 @@
return $self;
}
+
+=item name
+
+Return the package's name.
+
+=cut
+
+sub name {
+ my $self = shift;
+
+ return $self->{name};
+}
+
+
+=item icon( SIZE )
+
+Return a path to a file containing an icon of the specified
+size. If L<ImageMagick> is installed, it will be used to convert
+any icon found to the given size (as both width and height).
+If multiple icons are available, the one with a filename containing
+a number closest to C<SIZE> is used either directly, or as the
+resize source.
+
+The file returned will I<not> be within the build directory, and
+so cannot be directly used as a reference within C<debian/rules>.
+
+If no appropriate icon can be found, C<undef> is returned.
+
+=cut
+
+sub icon {
+ return undef; # TODO icon()
+}
+
+
+=item description
+
+Return this package's description. This can be sourced
+from a file, or directly embedded within the XML.
+
+=cut
+
+sub description {
+ my $self = shift;
+
+ my $description = $self->{data}->{deb}->{description};
+ return ref($description) ? &readFile($description->{file}) : $description;
+}
+
+
+=item upgradeDescription
+
+Return the short description of the reason this package has
+been updated. This can be sourced from a file, or directly
+embedded within the XML.
+
+=cut
+
+sub upgradeDescription {
+ my $self = shift;
+
+ my $desc = $self->{data}->{deb}->{'upgrade-description'};
+ return ref($desc) ? &readFile($desc->{file}) : $desc;
+}
+
+
+=item displayName
+
+Return the name which should be displayed as a human-readable,
+user-friendly variant in Application Manager.
+
+=cut
+
+sub displayName {
+ my $self = shift;
+
+ return $self->{data}->{deb}->{'display-name'};
+}
+
+
+=item patches
+
+Return an array of patch files which should be applied against
+the unpacked source before building. If no patches are to be
+applied, returns an empty list.
+
+ my @values = $pkg->patches;
+
+=cut
+
+sub patches {
+ return (); # TODO
+}
+
+
+=item controlFields
+
+Return a hash reference of values which contain additional
+C<debian/control> fields to set.
+
+ my $values = $pkg->controlFields;
+
+=cut
+
+sub controlFields {
+ my $self = shift;
+
+ # -- Return if already generated...
+ #
+ return $self->{controlFields} if $self->{controlFields};
+
+ # -- Generate...
+ #
+ my %data = map { $_ => $self->{data}->{deb}->{$_} }
+ grep { $_ !~ /^(icon|prefix-section|library|libdev|upgrade-description|description|display-name|version)$/ }
+ keys %{ $self->{data}->{deb} };
+ $self->{controlFields} = \%data;
+ return $self->{controlFields};
+}
+
+
+=item section
+
+Return the section which this package should be in. If no
+section is explicitly specified then, for I<non->libraries,
+C<user/> is prefixed.
+
+=cut
+
+sub section {
+ my $self = shift;
+
+ return undef; # TODO
+}
+
+
+=item version [( VERSION )]
+
+Set or return the version number which should be used for this package.
+Setting the version number can be done by sub-classes of
+L<MUD::Fetch>, if they have managed to work out the version number from
+(say) an upstream URL. However, this can I<always> be overridden by
+specifying the version in the C<deb> section of the package XML.
+
+=cut
+
+sub version {
+ my $self = shift;
+ my ($version) = @_;
+ $self->{version} = $version if $version;
+
+ return $self->{data}->{deb}->{version} || $self->{version};
+}
+
+
+=item extraFiles
+
+Return a hash reference of extra files to be installed. These
+take the form of C<TARGET =E<gt> SOURCE>, which allows multiple
+copies of the same source file to be included in the package in
+multiple locations.
+
+If no extra files are to be installed, an empty hash reference
+is returned.
+
+=cut
+
+sub extraFiles {
+ my $self = shift;
+
+ return {}; # TODO
+}
+
+
+=item parseField( FIELD, DATA )
+
+Utility method for reading a field from a Debian control file and
+returning the array of lines which makes it up.
+
+ my ($value) = MUD::Package::parseField('Version', $controlData);
+
+=cut
+
sub parseField {
- my $self = shift;
my ($field, $data) = @_;
- my @lines = $data =~ /[\r\n]+\s?$field:(\s+.*?[\r\n])(\s\s\S.*[\r\n])*/ig;
+ my @lines = $data =~ /^[\r\n]+\s?$field:(\s+.*?[\r\n])(\s\s\S.*[\r\n])*/ig;
if ($field =~ /^(Build-)?Depends$/i) {
@lines = map { s/\s*[\(\[].*?[\)\]]//; chomp; $_ }
@@ -91,9 +333,21 @@
return @lines;
}
+
+=item setField( DATA, FIELD, VALUE )
+
+Utility method for setting a field within a Debian control file.
+The value of C<DATA> is changed in place; no value is returned.
+
+ MUD::Package::setField($controlData, 'Version', $value);
+
+If C<VALUE> is undefined, no change is made to C<DATA>.
+
+=cut
+
sub setField {
- my $self = shift;
my ($data, $field, $value) = @_;
+ return $data if !defined($value);
# Capitalise field name
$field = ucfirst($field);
@@ -128,6 +382,38 @@
$data =~ s/^$paragraph: .*$/$&\n$wrapped/mg;
}
- return $data;
+ $_[0] = $data;
}
+
+
+=item readFile( FILE )
+
+Utility method for reading the contents of a file. (Any newlines
+in the file are converted into C<\n>. - DISABLED)
+
+=cut
+
+sub readFile {
+ my ($file) = @_;
+ my $contents = '';
+
+ open(IN, $file) or croak "Unable to read file $file: $!\n";
+ while(<IN>) { $contents .= $_ ; }
+ close(IN);
+
+ #$contents =~ s/\n/\\n/g;
+
+ return $contents;
+}
+
+=back
+
+=head1 COPYRIGHT
+
+(c) Andrew Flegg 2007 - 2009. Released under the Artistic Licence:
+L<http://www.opensource.org/licenses/artistic-license-2.0.php>
+
+=head1 SEE ALSO
+
+L<http://mud-builder.garage.maemo.org/>
Modified: trunk/packages/vim.xml
===================================================================
--- trunk/packages/vim.xml 2009-01-17 19:35:15 UTC (rev 254)
+++ trunk/packages/vim.xml 2009-01-19 01:55:56 UTC (rev 255)
@@ -12,7 +12,7 @@
</build>
<deb>
<version>7.2-0maemo1</version>
- <section>user/programming</section>
+ <section>user/utilities</section>
<description>Powerful console text editor
One of the most powerful text editors in existence, vim is "Vi-Improved".
.
More information about the Mud-builder-commits
mailing list