[svn:parrot] r45922 - in trunk: . config/auto config/auto/zlib config/gen/makefiles lib/Parrot/Configure/Options lib/Parrot/Configure/Options/Conf lib/Parrot/Configure/Step src/dynpmc t/dynpmc t/steps/auto
fperrad at svn.parrot.org
fperrad at svn.parrot.org
Thu Apr 22 20:15:58 UTC 2010
Author: fperrad
Date: Thu Apr 22 20:15:57 2010
New Revision: 45922
URL: https://trac.parrot.org/parrot/changeset/45922
Log:
[zlib] add a configure step for zlib, and a skeleton of GzipHandle PMC
Added:
trunk/config/auto/zlib/
trunk/config/auto/zlib.pm (contents, props changed)
trunk/config/auto/zlib/zlib_c.in (contents, props changed)
trunk/src/dynpmc/gziphandle.pmc (contents, props changed)
trunk/t/dynpmc/gziphandle.t (contents, props changed)
trunk/t/steps/auto/zlib-01.t (contents, props changed)
Modified:
trunk/MANIFEST
trunk/config/gen/makefiles/dynpmc.in
trunk/lib/Parrot/Configure/Options/Conf.pm
trunk/lib/Parrot/Configure/Options/Conf/Shared.pm
trunk/lib/Parrot/Configure/Step/List.pm
Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST Thu Apr 22 19:49:50 2010 (r45921)
+++ trunk/MANIFEST Thu Apr 22 20:15:57 2010 (r45922)
@@ -1,7 +1,7 @@
# ex: set ro:
# $Id$
#
-# generated by tools/dev/mk_manifest_and_skip.pl Thu Apr 22 19:33:40 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Thu Apr 22 20:12:33 2010 UT
#
# See below for documentation on the format of this file.
#
@@ -298,6 +298,8 @@
config/auto/va_ptr/test_c.in []
config/auto/warnings.pm []
config/auto/warnings/test_c.in []
+config/auto/zlib.pm []
+config/auto/zlib/zlib_c.in []
config/gen/config_h.pm []
config/gen/config_h/config_h.in []
config/gen/config_h/feature_h.in []
@@ -1306,6 +1308,7 @@
src/dynpmc/ext.pir []
src/dynpmc/foo.pmc []
src/dynpmc/foo2.pmc []
+src/dynpmc/gziphandle.pmc []
src/dynpmc/main.pasm []
src/dynpmc/pccmethod_test.pmc []
src/dynpmc/rational.pmc []
@@ -1681,6 +1684,7 @@
t/dynpmc/dynlexpad.t [test]
t/dynpmc/foo.t [test]
t/dynpmc/foo2.t [test]
+t/dynpmc/gziphandle.t [test]
t/dynpmc/pccmethod_test.t [test]
t/dynpmc/rational.t [test]
t/dynpmc/rotest.t [test]
@@ -2009,6 +2013,7 @@
t/steps/auto/thread-01.t [test]
t/steps/auto/va_ptr-01.t [test]
t/steps/auto/warnings-01.t [test]
+t/steps/auto/zlib-01.t [test]
t/steps/gen/config_h-01.t [test]
t/steps/gen/config_pm-01.t [test]
t/steps/gen/core_pmcs-01.t [test]
Added: trunk/config/auto/zlib.pm
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/config/auto/zlib.pm Thu Apr 22 20:15:57 2010 (r45922)
@@ -0,0 +1,90 @@
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+
+=head1 NAME
+
+config/auto/zlib.pm - Test for zlib library
+
+=head1 DESCRIPTION
+
+This library is linked to a dynamic PMC.
+
+=cut
+
+package auto::zlib;
+
+use strict;
+use warnings;
+
+use base qw(Parrot::Configure::Step);
+
+use Parrot::Configure::Utils ':auto';
+
+
+sub _init {
+ my $self = shift;
+ my %data;
+ $data{description} = q{Does your platform support zlib};
+ $data{result} = q{};
+ return \%data;
+}
+
+sub runstep {
+ my ( $self, $conf ) = @_;
+
+ my ( $verbose, $without ) = $conf->options->get(
+ qw|
+ verbose
+ without-zlib
+ |
+ );
+
+ if ($without) {
+ $conf->data->set( has_zlib => 0 );
+ $self->set_result('no');
+ return 1;
+ }
+
+ my $osname = $conf->data->get('osname');
+
+ my $extra_libs = $self->_select_lib( {
+ conf => $conf,
+ osname => $osname,
+ cc => $conf->data->get('cc'),
+ win32_nongcc => 'zlib.lib',
+ default => '-lz',
+ } );
+
+ $conf->cc_gen('config/auto/zlib/zlib_c.in');
+ eval { $conf->cc_build( q{}, $extra_libs); };
+ my $has_zlib = 0;
+ if ( !$@ ) {
+ my $test = $conf->cc_run();
+ $has_zlib = $self->_evaluate_cc_run($conf, $test, $has_zlib, $verbose);
+ }
+ $conf->data->set( has_zlib => $has_zlib );
+ $self->set_result($has_zlib ? 'yes' : 'no');
+
+ return 1;
+}
+
+sub _evaluate_cc_run {
+ my $self = shift;
+ my ($conf, $test, $has_zlib, $verbose) = @_;
+ if ( $test =~ m/^(\d\.\d\.\d)/ ) {
+ my $version = $1;
+ $has_zlib = 1;
+ print " (yes) " if $verbose;
+ $self->set_result("yes, $version");
+ }
+ return $has_zlib;
+}
+
+1;
+
+# Local Variables:
+# mode: cperl
+# cperl-indent-level: 4
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:
Added: trunk/config/auto/zlib/zlib_c.in
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/config/auto/zlib/zlib_c.in Thu Apr 22 20:15:57 2010 (r45922)
@@ -0,0 +1,26 @@
+/*
+ Copyright (C) 2010, Parrot Foundation.
+ $Id$
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <zlib.h>
+
+int
+main(int argc, char *argv[])
+{
+ if (0 == strcmp(ZLIB_VERSION, zlibVersion())) {
+ printf("%s\n", ZLIB_VERSION);
+ return EXIT_SUCCESS;
+ }
+ printf("not same version between include and library\n");
+ return EXIT_FAILURE;
+}
+
+/*
+ * Local variables:
+ * c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */
Modified: trunk/config/gen/makefiles/dynpmc.in
==============================================================================
--- trunk/config/gen/makefiles/dynpmc.in Thu Apr 22 19:49:50 2010 (r45921)
+++ trunk/config/gen/makefiles/dynpmc.in Thu Apr 22 20:15:57 2010 (r45922)
@@ -33,6 +33,7 @@
pccmethod_test$(LOAD_EXT) \
rotest$(LOAD_EXT) \
rational$(LOAD_EXT) \
+#IF(has_zlib): gziphandle$(LOAD_EXT) \
subproxy$(LOAD_EXT)
PMCS_FOO = \
@@ -43,6 +44,10 @@
foo$(O) \
foo2$(O)
+#IF(win32 and cc==gcc):LIB_ZLIB = -lz
+#ELSIF(win32):LIB_ZLIB = zlib.lib
+#ELSE:LIB_ZLIB = -lz
+
CLEANUPS = \
"*.c" \
"pmc_*.h" \
@@ -161,6 +166,19 @@
subproxy.dump: subproxy.pmc
$(PMC2CD) subproxy.pmc
+gziphandle$(LOAD_EXT): gziphandle$(O)
+ $(LD) @ld_out at gziphandle$(LOAD_EXT) gziphandle$(O) $(LINKARGS) $(LIB_ZLIB)
+#IF(win32): if exist $@.manifest mt.exe -nologo -manifest $@.manifest -outputresource:$@;2
+
+gziphandle$(O): gziphandle.c
+ $(CC) -c @cc_o_out at gziphandle$(O) $(INCLUDES) $(CFLAGS) gziphandle.c
+
+gziphandle.c: gziphandle.dump
+ $(PMC2CC) gziphandle.pmc
+
+gziphandle.dump: gziphandle.pmc
+ $(PMC2CD) gziphandle.pmc
+
test : all
cd ../.. && $(PERL) -Ilib t/harness t/dynpmc/*.t
Modified: trunk/lib/Parrot/Configure/Options/Conf.pm
==============================================================================
--- trunk/lib/Parrot/Configure/Options/Conf.pm Thu Apr 22 19:49:50 2010 (r45921)
+++ trunk/lib/Parrot/Configure/Options/Conf.pm Thu Apr 22 20:15:57 2010 (r45922)
@@ -103,6 +103,7 @@
--without-gmp Build parrot without GMP support
--without-opengl Build parrot without OpenGL support (GL/GLU/GLUT)
--without-pcre Build parrot without pcre support
+ --without-zlib Build parrot without zlib support
ICU Options:
Modified: trunk/lib/Parrot/Configure/Options/Conf/Shared.pm
==============================================================================
--- trunk/lib/Parrot/Configure/Options/Conf/Shared.pm Thu Apr 22 19:49:50 2010 (r45921)
+++ trunk/lib/Parrot/Configure/Options/Conf/Shared.pm Thu Apr 22 20:15:57 2010 (r45922)
@@ -80,6 +80,7 @@
without-opengl
without-pcre
without-threads
+ without-zlib
yacc
};
Modified: trunk/lib/Parrot/Configure/Step/List.pm
==============================================================================
--- trunk/lib/Parrot/Configure/Step/List.pm Thu Apr 22 19:49:50 2010 (r45921)
+++ trunk/lib/Parrot/Configure/Step/List.pm Thu Apr 22 20:15:57 2010 (r45922)
@@ -54,6 +54,7 @@
auto::readline
auto::pcre
auto::opengl
+ auto::zlib
auto::gettext
auto::snprintf
auto::perldoc
Added: trunk/src/dynpmc/gziphandle.pmc
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/src/dynpmc/gziphandle.pmc Thu Apr 22 20:15:57 2010 (r45922)
@@ -0,0 +1,87 @@
+/*
+Copyright (C) 2010, Parrot Foundation.
+$Id$
+
+=head1 NAME
+
+src/dynpmc/gziphandle.pmc - GzipHandle PMC
+
+=head1 DESCRIPTION
+
+The GzipHandle PMC performs I/O operations on a source or destination file.
+
+This PMC wraps the zlib.
+
+=head2 Vtable Functions
+
+=over 4
+
+=cut
+
+*/
+
+#include <zlib.h>
+#include "parrot/extend.h"
+
+/* HEADERIZER HFILE: none */
+/* HEADERIZER BEGIN: static */
+/* HEADERIZER END: static */
+
+pmclass GzipHandle extends Handle dynpmc auto_attrs {
+
+/*
+
+=item C<void init()>
+
+Initializes a newly created FileHandle object.
+
+=cut
+
+*/
+
+ VTABLE void init() {
+ }
+
+/*
+
+=back
+
+=head2 Stream-Oriented Methods
+
+=over 4
+
+*/
+
+
+/*
+
+=back
+
+=head2 Basic Methods
+
+=over 4
+
+*/
+
+ METHOD version() {
+ STRING *version = Parrot_str_new_constant(INTERP, zlibVersion());
+ RETURN(STRING *version);
+ }
+
+/*
+
+=back
+
+=cut
+
+*/
+
+}
+
+/*
+ * Local variables:
+ * c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */
+
Added: trunk/t/dynpmc/gziphandle.t
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/t/dynpmc/gziphandle.t Thu Apr 22 20:15:57 2010 (r45922)
@@ -0,0 +1,56 @@
+#! parrot
+# Copyright (C) 2010, Parrot Foundation.
+
+=head1 NAME
+
+t/dynpmc/gziphandle.t - test the GzipHandle PMC
+
+=head1 SYNOPSIS
+
+ % parrot t/dynpmc/gziphandle.t
+
+=head1 DESCRIPTION
+
+Tests the C<GzipHandle> PMC, a zlib wrapper.
+
+=cut
+
+.sub 'main' :main
+ .include 'test_more.pir'
+ .include 'iglobals.pasm'
+ .local pmc config_hash, interp
+
+ plan(2)
+ interp = getinterp
+ config_hash = interp[.IGLOBALS_CONFIG_HASH]
+ $S0 = config_hash['has_zlib']
+ unless $S0 goto no_zlib
+
+ $P0 = loadlib 'gziphandle'
+ test_version()
+ .return()
+
+ no_zlib:
+ skip(2, 'No zlib library available')
+ .return()
+.end
+
+
+.sub 'test_version'
+ $P0 = new 'GzipHandle'
+ $S0 = typeof $P0
+ is($S0, 'GzipHandle', 'GzipHandle typeof')
+ $S0 =$P0.'version'()
+ diag($S0)
+ $I0 = index $S0, '1.'
+ is($I0, 0, 'zlib version')
+.end
+
+
+# Local Variables:
+# mode: pir
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
+
+
Added: trunk/t/steps/auto/zlib-01.t
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/t/steps/auto/zlib-01.t Thu Apr 22 20:15:57 2010 (r45922)
@@ -0,0 +1,176 @@
+#! perl
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+
+use strict;
+use warnings;
+use Test::More tests => 24;
+use Carp;
+use lib qw( lib t/configure/testlib );
+use_ok('config::auto::zlib');
+use Parrot::Configure::Options qw( process_options );
+use Parrot::Configure::Step::Test;
+use Parrot::Configure::Test qw(
+ test_step_constructor_and_description
+);
+use IO::CaptureOutput qw( capture );
+
+########## --without-zlib ##########
+
+my ($args, $step_list_ref) = process_options(
+ {
+ argv => [ q{--without-zlib} ],
+ mode => q{configure},
+ }
+);
+
+my $conf = Parrot::Configure::Step::Test->new;
+$conf->include_config_results( $args );
+
+my $pkg = q{auto::zlib};
+
+$conf->add_steps($pkg);
+
+my $serialized = $conf->pcfreeze();
+
+$conf->options->set( %{$args} );
+my $step = test_step_constructor_and_description($conf);
+my $ret = $step->runstep($conf);
+ok( $ret, "runstep() returned true value" );
+is($conf->data->get('has_zlib'), 0,
+ "Got expected value for 'has_zlib'");
+is($step->result(), q{no}, "Expected result was set");
+
+$conf->replenish($serialized);
+
+########## _select_lib() ##########
+
+($args, $step_list_ref) = process_options( {
+ argv => [ ],
+ mode => q{configure},
+} );
+$conf->options->set( %{$args} );
+$step = test_step_constructor_and_description($conf);
+# Mock different OS/compiler combinations.
+my ($osname, $cc, $initial_libs);
+$initial_libs = $conf->data->get('libs');
+$osname = 'mswin32';
+$cc = 'gcc';
+is($step->_select_lib( {
+ conf => $conf,
+ osname => $osname,
+ cc => $cc,
+ win32_nongcc => 'zlib.lib',
+ default => '-lz',
+} ),
+ '-lz',
+ "_select_lib() returned expected value");
+
+$osname = 'mswin32';
+$cc = 'cc';
+is($step->_select_lib( {
+ conf => $conf,
+ osname => $osname,
+ cc => $cc,
+ win32_nongcc => 'zlib.lib',
+ default => '-lz',
+} ),
+ 'zlib.lib',
+ "_select_lib() returned expected value");
+
+$osname = 'foobar';
+$cc = 'cc';
+is($step->_select_lib( {
+ conf => $conf,
+ osname => $osname,
+ cc => $cc,
+ win32_nongcc => 'zlib.lib',
+ default => '-lz',
+} ),
+ '-lz',
+ "_select_lib() returned expected value");
+
+my $verbose = undef;
+
+$conf->replenish($serialized);
+
+########## --without-zlib; _evaluate_cc_run() ##########
+
+($args, $step_list_ref) = process_options( {
+ argv => [ q{--without-zlib} ],
+ mode => q{configure},
+} );
+$conf->options->set( %{$args} );
+$step = test_step_constructor_and_description($conf);
+my ($test, $has_zlib);
+$test = qq{1.2.3\n};
+$has_zlib = 0;
+$verbose = undef;
+$has_zlib = $step->_evaluate_cc_run($conf, $test, $has_zlib, $verbose);
+is($has_zlib, 1, "'has_zlib' set as expected");
+is($step->result(), 'yes, 1.2.3', "Expected result was set");
+# Prepare for next test
+$step->set_result(undef);
+
+$test = qq{foobar};
+$has_zlib = 0;
+$verbose = undef;
+$has_zlib = $step->_evaluate_cc_run($conf, $test, $has_zlib, $verbose);
+is($has_zlib, 0, "'has_zlib' set as expected");
+ok(! defined $step->result(), "Result is undefined, as expected");
+
+{
+ my $stdout;
+ $test = qq{1.2.3\n};
+ $has_zlib = 0;
+ $verbose = 1;
+ capture(
+ sub { $has_zlib =
+ $step->_evaluate_cc_run($conf, $test, $has_zlib, $verbose); },
+ \$stdout,
+ );
+ is($has_zlib, 1, "'has_zlib' set as expected");
+ is($step->result(), 'yes, 1.2.3', "Expected result was set");
+ like($stdout, qr/\(yes\)/, "Got expected verbose output");
+ # Prepare for next test
+ $step->set_result(undef);
+}
+
+pass("Completed all tests in $0");
+
+################### DOCUMENTATION ###################
+
+=head1 NAME
+
+auto/zlib-01.t - test auto::zlib
+
+=head1 SYNOPSIS
+
+ % prove t/steps/auto/zlib-01.t
+
+=head1 DESCRIPTION
+
+The files in this directory test functionality used by F<Configure.pl>.
+
+The tests in this file test auto::zlib.
+
+=head1 HISTORY
+
+Mostly taken from F<t/steps/auto/gdbm-01.t>.
+
+=head1 AUTHOR
+
+Francois Perrad
+
+=head1 SEE ALSO
+
+config::auto::zlib, F<Configure.pl>.
+
+=cut
+
+# Local Variables:
+# mode: cperl
+# cperl-indent-level: 4
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:
More information about the parrot-commits
mailing list