Index: lib/Parrot/Configure/Options/Conf/Shared.pm =================================================================== --- lib/Parrot/Configure/Options/Conf/Shared.pm (.../trunk) (revision 39969) +++ lib/Parrot/Configure/Options/Conf/Shared.pm (.../branches/darwin2hints) (revision 40020) @@ -18,6 +18,8 @@ cgoto configure_trace cxx + darwin_no_fink + darwin_no_macports datadir debugging define Index: lib/Parrot/Configure/Step/List.pm =================================================================== --- lib/Parrot/Configure/Step/List.pm (.../trunk) (revision 39969) +++ lib/Parrot/Configure/Step/List.pm (.../branches/darwin2hints) (revision 40020) @@ -20,8 +20,6 @@ auto::gcc auto::glibc auto::backtrace - auto::fink - auto::macports auto::msvc auto::attributes auto::warnings Index: lib/Parrot/Configure/Step/Methods.pm =================================================================== --- lib/Parrot/Configure/Step/Methods.pm (.../trunk) (revision 39969) +++ lib/Parrot/Configure/Step/Methods.pm (.../branches/darwin2hints) (revision 40020) @@ -27,72 +27,6 @@ =head1 METHODS -=head2 C<_handle_darwin_for_fink()> - - $self->_handle_darwin_for_fink($conf, $libs, $osname, $file); - -Currently used in configuration step classes auto::gmp, auto::readline and -auto::gdbm. - -Modifies settings for C, C and C in the -Parrot::Configure object's data structure. - -=cut - -sub _handle_darwin_for_fink { - my ($self, $conf, $osname, $file) = @_; - if ( $osname =~ /darwin/ ) { - my $fink_lib_dir = $conf->data->get('fink_lib_dir'); - my $fink_include_dir = $conf->data->get('fink_include_dir'); - if ( (defined $fink_lib_dir) && (defined $fink_include_dir) ) { - if ( -f "$fink_include_dir/$file" ) { - my %intended = ( - linkflags => "-L$fink_lib_dir", - ldflags => "-L$fink_lib_dir", - ccflags => "-I$fink_include_dir", - ); - _add_flags_not_yet_seen($conf, \%intended); - } - } - } - return 1; -} - -=head2 C<_handle_darwin_for_macports()> - - $self->_handle_darwin_for_macports($conf, $libs, $osname, $file); - -Currently used in configuration step classes auto::gmp, auto::readline and -auto::opengl. - -Modifies settings for C, C and C in the -Parrot::Configure object's data structure. - -Potentially expandable to cover all BSD-ports systems -- but as yet there has -been no demand. - -=cut - -sub _handle_darwin_for_macports { - my ($self, $conf, $osname, $file) = @_; - if ( $osname =~ /darwin/ ) { -# my $ports_root = $conf->data->get( 'ports_base_dir' ); - my $ports_lib_dir = $conf->data->get( 'ports_lib_dir' ); - my $ports_include_dir = $conf->data->get( 'ports_include_dir' ); - if ( defined $ports_lib_dir && defined $ports_include_dir ) { - if ( -f qq{$ports_include_dir/$file} ) { - my %intended = ( - linkflags => "-L$ports_lib_dir", - ldflags => "-L$ports_lib_dir", - ccflags => "-I$ports_include_dir", - ); - _add_flags_not_yet_seen($conf, \%intended); - } - } - } - return 1; -} - =head2 C<_select_lib()> $self->_select_lib( { @@ -201,18 +135,6 @@ return $libs; } -sub _add_flags_not_yet_seen { - my ($conf, $intended) = @_; - foreach my $flag (keys %{ $intended }) { - my $flagstr = $conf->data->get($flag); - my @elements = split /\s+/, $flagstr; - my %seen = map {$_, 1} @elements; - $conf->data->add( ' ', $flag => $intended->{$flag} ) - unless $seen{$intended->{$flag}}; - } -} - - =head1 SEE ALSO Parrot::Configure::Step. Index: lib/Parrot/Test.pm =================================================================== --- lib/Parrot/Test.pm (.../trunk) (revision 39969) +++ lib/Parrot/Test.pm (.../branches/darwin2hints) (revision 40020) @@ -963,8 +963,8 @@ "$PConfig{link} " . "$PConfig{ld_out}$exe_f " . "$obj_f $cfg " - . "$PConfig{libparrot_linkflags} " - . "$PConfig{linkflags} $PConfig{ld_debug} " + . "$PConfig{libparrot_linkflags} " + . "$PConfig{linkflags} $PConfig{ld_debug} " . "$iculibs $PConfig{libs}"; my $exit_code = run_command( $cmd, Index: MANIFEST =================================================================== --- MANIFEST (.../trunk) (revision 39969) +++ MANIFEST (.../branches/darwin2hints) (revision 40020) @@ -1,7 +1,7 @@ # ex: set ro: # $Id$ # -# generated by tools/dev/mk_manifest_and_skip.pl Thu Jul 9 23:58:32 2009 UT +# generated by tools/dev/mk_manifest_and_skip.pl Sat Jul 11 16:40:06 2009 UT # # See below for documentation on the format of this file. # @@ -228,7 +228,6 @@ config/auto/env.pm [] config/auto/env/test_setenv_c.in [] config/auto/env/test_unsetenv_c.in [] -config/auto/fink.pm [] config/auto/format.pm [] config/auto/funcptr.pm [] config/auto/funcptr/test_c.in [] @@ -257,7 +256,6 @@ config/auto/jit/test_exec_cygwin_c.in [] config/auto/jit/test_exec_linux_c.in [] config/auto/jit/test_exec_openbsd_c.in [] -config/auto/macports.pm [] config/auto/memalign.pm [] config/auto/memalign/test2_c.in [] config/auto/memalign/test_c.in [] @@ -1947,7 +1945,6 @@ t/steps/auto/crypto-01.t [test] t/steps/auto/ctags-01.t [test] t/steps/auto/env-01.t [test] -t/steps/auto/fink-01.t [test] t/steps/auto/format-01.t [test] t/steps/auto/funcptr-01.t [test] t/steps/auto/gc-01.t [test] @@ -1961,8 +1958,6 @@ t/steps/auto/inline-01.t [test] t/steps/auto/isreg-01.t [test] t/steps/auto/jit-01.t [test] -t/steps/auto/macports-01.t [test] -t/steps/auto/macports-02.t [test] t/steps/auto/memalign-01.t [test] t/steps/auto/msvc-01.t [test] t/steps/auto/neg_0-01.t [test] Index: Configure.pl =================================================================== --- Configure.pl (.../trunk) (revision 39969) +++ Configure.pl (.../branches/darwin2hints) (revision 40020) @@ -196,8 +196,27 @@ =back +=item C<--configure_trace> + +Store the results of each configuration step in a Storable F<.sto> file on +disk, for later analysis by F methods. + +=item Operating system-specific configuration options + +=over 4 + +=item C<--darwin_no_fink> + +On Darwin, do not probe for Fink libraries. + +=item C<--darwin_no_macports> + +On Darwin, do not probe for Macports libraries. + =back +=back + =head2 Compile Options =over 4 Index: t/configure/049-options_test_prepare.t =================================================================== --- t/configure/049-options_test_prepare.t (.../trunk) (revision 39969) +++ t/configure/049-options_test_prepare.t (.../branches/darwin2hints) (revision 40020) @@ -94,11 +94,6 @@ like($stderr, qr/No tests exist for configure step $not_expected/, "Warning about step class lacking test captured"); } -# foreach my $type ( qw| init inter auto gen | ) { -# my $t = $type . q(_sometest-01.t); -# ok($tests_seen{$t}, "Found needed test"); -# } - ok( chdir $cwd, "Able to change back to starting directory"); } Index: t/steps/init/hints/darwin-01.t =================================================================== --- t/steps/init/hints/darwin-01.t (.../trunk) (revision 39969) +++ t/steps/init/hints/darwin-01.t (.../branches/darwin2hints) (revision 40020) @@ -5,10 +5,387 @@ use strict; use warnings; -use Test::More; # tests => 26; +use Cwd; +use File::Temp qw( tempdir ); +use Test::More; plan( skip_all => 'only needs testing on Darwin' ) unless $^O =~ /darwin/i; -plan( tests => 1 ); +plan( tests => 40 ); +#use Test::More qw(no_plan); # tests => 40; +use lib qw( lib t/configure/testlib ); +use_ok('config::init::defaults'); +use_ok('config::init::hints'); +use_ok('config::init::hints::darwin'); +use Parrot::Configure; +use Parrot::Configure::Options qw( process_options ); +use Parrot::Configure::Test qw( + test_step_thru_runstep + test_step_constructor_and_description +); +use IO::CaptureOutput qw | capture |; + +my $cwd = cwd(); +my ($args, $step_list_ref) = process_options( + { + argv => [], + mode => q{configure}, + } +); + +my $conf = Parrot::Configure->new; + +test_step_thru_runstep( $conf, q{init::defaults}, $args ); + +##### Tests of some internal subroutines ##### + +##### _precheck() ##### + +my $problematic_flag = 'ccflags'; +my $stored = $conf->data->get($problematic_flag); + +{ + my ($stdout, $stderr); + capture( + sub { init::hints::darwin::_precheck( + $problematic_flag, $stored, 0 + ) }, + \$stdout, + \$stderr, + ); + ok( ! $stdout, "_precheck(): Non-verbose mode produced no output" ); +} + +{ + my ($stdout, $stderr); + capture( + sub { init::hints::darwin::_precheck( + $problematic_flag, $stored, 1 + ) }, + \$stdout, + \$stderr, + ); + ok( $stdout, "_precheck(): Verbose mode produced output" ); + like($stdout, qr/Checking\s+$problematic_flag/, + "_precheck(): Got expected verbose output" ); + like($stdout, qr/Pre-check:\s+$stored/, + "_precheck(): Got expected verbose output" ); +} + +{ + my ($stdout, $stderr); + capture( + sub { init::hints::darwin::_precheck( + $problematic_flag, q{}, 1 + ) }, + \$stdout, + \$stderr, + ); + ok( $stdout, "_precheck(): Verbose mode produced output" ); + like($stdout, qr/Checking\s+$problematic_flag/, + "_precheck(): Got expected verbose output" ); + like($stdout, qr/Pre-check:\s+\(nil\)/, + "_precheck(): Got expected verbose output" ); +} + +##### _strip_arch_flags_engine ##### + +{ + my %defaults = ( + architectures => [ qw( i386 ppc64 ppc x86_64 ) ], + ); + my $flagsref = {}; + my $stored = q{-someflag -arch i386 -someotherflag -arch ppc}; + my $flag = q{ccflags}; + $flagsref = init::hints::darwin::_strip_arch_flags_engine( + $defaults{architectures}, $stored, $flagsref, $flag + ); + like( + $flagsref->{$flag}, + qr{-someflag -someotherflag}, + "_strip_arch_flags_engine(): '-arch' flags and extra whitespace removed", + ); + + +} + +##### _postcheck ##### + +{ + my $flag = 'ccflags'; + my $flagsref = { 'ccflags' => 'my ccflag' }; + my ($stdout, $stderr); + + capture( + sub { init::hints::darwin::_postcheck( + $flagsref, $flag, 0 + ) }, + \$stdout, + \$stderr, + ); + ok( ! $stdout, "_postcheck(): Non-verbose mode produced no output" ); + + capture( + sub { init::hints::darwin::_postcheck( + $flagsref, $flag, 1 + ) }, + \$stdout, + \$stderr, + ); + ok( $stdout, "_postcheck(): Verbose mode produced output" ); + like($stdout, qr/Post-check:\s+$flagsref->{$flag}/, + "_postcheck(): Got expected verbose output" ); + + $flagsref = { 'ccflags' => undef }; + capture( + sub { init::hints::darwin::_postcheck( + $flagsref, $flag, 1 + ) }, + \$stdout, + \$stderr, + ); + ok( $stdout, "_postcheck(): Verbose mode produced output" ); + like($stdout, qr/Post-check:\s+\(nil\)/, + "_postcheck(): Got expected verbose output" ); +} + +##### _strip_arch_flags ##### + +{ + my %defaults = ( + problem_flags => [ qw( ccflags ldflags ) ], + architectures => [ qw( i386 ppc64 ppc x86_64 ) ], + ); + my $flagsref = {}; + my $flag = q{ccflags}; + my $stored = q{-someflag -arch i386 -someotherflag -arch ppc}; + my $oldflag = $conf->data->get( $flag ); + $conf->data->set( $flag => $stored ); + + $flagsref = init::hints::darwin::_strip_arch_flags($conf, 0); + like($flagsref->{$flag}, + qr/-someflag -someotherflag/, + "_strip_arch_flags(): '-arch' flags and extra whitespace removed", + ); + + my ($stdout, $stderr); + capture( + sub { + $flagsref = init::hints::darwin::_strip_arch_flags($conf, 1); + }, + \$stdout, + \$stderr, + ); + like($flagsref->{$flag}, + qr/-someflag -someotherflag/, + "_strip_arch_flags(): '-arch' flags and extra whitespace removed", + ); + like( + $stdout, + qr/Stripping -arch flags due to Apple multi-architecture build problems:/, + "_strip_arch_flags(): Got expected verbose output", + ); + + $conf->data->set( $flag => $oldflag ); +} + +##### _strip_ldl_as_needed ##### + +{ + my $oldflag = $conf->data->get( 'libs ' ); + my ( $major, $libs ); + + $major = '7.99.11'; + local $init::hints::darwin::defaults{uname} = $major; + $conf->data->set( libs => '-somelib -ldl -someotherlib' ); + $libs = init::hints::darwin::_strip_ldl_as_needed( + $conf->data->get( 'libs' ) + ); + like( $libs, qr/-somelib\s+-someotherlib/, + "_strip_ldl_as_needed(): '-ldl' stripped as expected" ); + + $major = '6.99.11'; + local $init::hints::darwin::defaults{uname} = $major; + $conf->data->set( libs => '-somelib -ldl -someotherlib' ); + $libs = init::hints::darwin::_strip_ldl_as_needed( + $conf->data->get( 'libs' ) + ); + like( $libs, qr/-somelib\s+-ldl\s+-someotherlib/, + "_strip_ldl_as_needed(): '-ldl' not stripped as expected in older darwin" ); + + $conf->data->set( libs => $oldflag ); +} + +##### _set_deployment_environment() ##### + +{ + my $predicted = '10.99'; + local $ENV{'MACOSX_DEPLOYMENT_TARGET'} = undef; + no warnings 'once'; + local $init::hints::darwin::defaults{sw_vers} = qq{$predicted.11}; + use warnings; + init::hints::darwin::_set_deployment_environment(); + is($ENV{'MACOSX_DEPLOYMENT_TARGET'}, $predicted, + "_set_deployment_environment(): MACOSX_DEPLOYMENT_TARGET set as expected"); +} + +##### _probe_for_fink() ##### + +{ + my $tdir = tempdir( CLEANUP => 1 ); + chdir $tdir or die "Unable to change to temporary directory: $!"; + + local $init::hints::darwin::defaults{fink_conf} = qq{$tdir/fink.conf}; + ok( ! defined( init::hints::darwin::_probe_for_fink( $conf ) ), + "_probe_for_fink(): returned undefined value for no config file" ); + $conf->options->set( 'verbose' => 1 ); + { + my ($stdout, $stderr); + capture( + sub { init::hints::darwin::_probe_for_fink( $conf ); }, + \$stdout, + \$stderr, + ); + like( $stdout, qr/Fink configuration file not located/, + "Got expected verbose output when Fink config not located" ); + } + $conf->options->set( 'verbose' => 0 ); + + my $fink_conf_file = q{fink.conf}; + open my $CONF, '>', $fink_conf_file + or die "Unable to open $fink_conf_file for writing: $!"; + print $CONF "Hello, world, but no Fink info\n"; + close $CONF or die "Unable to close $fink_conf_file after writing: $!"; + ok( ! defined( init::hints::darwin::_probe_for_fink( $conf ) ), + "_probe_for_fink(): returned undefined value for defective config file" ); + + $conf->options->set( 'verbose' => 1 ); + { + my ($stdout, $stderr); + capture( + sub { init::hints::darwin::_probe_for_fink( $conf ); }, + \$stdout, + \$stderr, + ); + like( $stdout, qr/Fink configuration file defective/, + "Got expected verbose output when Fink config was defective" ); + } + $conf->options->set( 'verbose' => 0 ); + + my $other = qq{$tdir/other_fink.conf}; + local $init::hints::darwin::defaults{fink_conf} = $other; + $fink_conf_file = $other; + open my $OCONF, '>', $fink_conf_file + or die "Unable to open $fink_conf_file for writing: $!"; + print $OCONF "Basepath: /tmp/foobar\n"; + close $OCONF or die "Unable to close $fink_conf_file after writing: $!"; + ok( ! defined( init::hints::darwin::_probe_for_fink( $conf ) ), + "_probe_for_fink(): returned undefined value for missing directories" ); + + $conf->options->set( 'verbose' => 1 ); + { + my ($stdout, $stderr); + capture( + sub { init::hints::darwin::_probe_for_fink( $conf ); }, + \$stdout, + \$stderr, + ); + like( $stdout, qr/Could not locate Fink directories/, + "Got expected verbose output when Fink directories were missing" ); + } + $conf->options->set( 'verbose' => 0 ); + + chdir $cwd or die "Unable to change back to starting directory: $!"; +} + +##### _probe_for_macports() ##### + +{ + my $tdir = tempdir( CLEANUP => 1 ); + chdir $tdir or die "Unable to change to temporary directory: $!"; + + local $init::hints::darwin::defaults{ports_base_dir} = qq{$tdir/foobar}; + ok( ! defined( init::hints::darwin::_probe_for_macports( $conf ) ), + "_probe_for_macports(): returned undefined value for no config file" ); + + $conf->options->set( 'verbose' => 1 ); + { + my ($stdout, $stderr); + capture( + sub { init::hints::darwin::_probe_for_macports( $conf ); }, + \$stdout, + \$stderr, + ); + like( $stdout, qr/Could not locate Macports directories/, + "Got expected verbose output when Macports directories not found" ); + } + $conf->options->set( 'verbose' => 0 ); +} + +##### _probe_for_libraries() ##### + +{ + $conf->options->set( 'darwin_no_fink' => 1 ); + $conf->options->set( 'verbose' => 0 ); + my $lib_dir = $conf->data->get('build_dir') . "/blib/lib"; + my $flagsref = {}; + $flagsref->{ldflags} .= " -L$lib_dir"; + $flagsref->{ccflags} .= " -pipe -fno-common -Wno-long-double "; + $flagsref->{linkflags} .= " -undefined dynamic_lookup"; + my %state_before = map { $_ => $flagsref->{$_} } keys %{ $flagsref }; + ok( ! defined ( init::hints::darwin::_probe_for_libraries( + $conf, $flagsref, 'fink') + ), "_probe_for_libraries() returned undef as expected" ); + is_deeply( $flagsref, { %state_before }, + "No change in flags, as expected" ); + + $conf->options->set( 'darwin_no_fink' => 0 ); +} + +##### _add_to_flags() ##### + +{ + my ( $addl_flags_ref, $flagsref, $title, $verbose ); + $addl_flags_ref = undef; + $flagsref = undef; + $title = 'Fink'; + $verbose = 0; + ok( init::hints::darwin::_add_to_flags( + $addl_flags_ref, $flagsref, $title, $verbose + ), "_add_to_flags(): returned true value when no probes found" ); + + $verbose = 1; + { + my ($stdout, $stderr); + capture( + sub { init::hints::darwin::_add_to_flags( + $addl_flags_ref, $flagsref, $title, $verbose + ); }, + \$stdout, + \$stderr, + ); + like( $stdout, qr/Probe for $title unsuccessful/, + "_add_to_flags(): got expected verbose output when probe unsuccessful" ); + } + + $addl_flags_ref = { + ldflags => "-Lfink_lib_dir", + ccflags => "-Lfink_include_dir", + linkflags => "-Lfink_lib_dir", + }; + my $lib_dir = $conf->data->get('build_dir') . "/blib/lib"; + $flagsref = undef; + $flagsref->{ldflags} = " -L$lib_dir"; + $flagsref->{ccflags} = " -pipe -fno-common -Wno-long-double "; + $flagsref->{linkflags} = undef; + $title = 'Fink'; + $verbose = 0; + my $rv = init::hints::darwin::_add_to_flags( + $addl_flags_ref, $flagsref, $title, $verbose + ); + is( $flagsref->{linkflags}, " $addl_flags_ref->{linkflags}", + "_add_to_flags(): flag added where not previously populated" ); +} + pass("Completed all tests in $0"); ################### DOCUMENTATION ################### Index: t/steps/auto/fink-01.t =================================================================== --- t/steps/auto/fink-01.t (.../trunk) (revision 39969) +++ t/steps/auto/fink-01.t (.../branches/darwin2hints) (revision 40020) @@ -1,289 +0,0 @@ -#! perl -# Copyright (C) 2007-2009, Parrot Foundation. -# $Id$ -# auto/fink-01.t - -use strict; -use warnings; -use Test::More; -use Carp; -use File::Temp; -use lib qw( lib t/configure/testlib ); - -plan( skip_all => 'fink is Darwin only' ) unless $^O =~ /darwin/i; -plan( tests => 55 ); - -use_ok('config::init::defaults'); -use_ok('config::auto::fink'); - -use Parrot::Configure; -use Parrot::Configure::Options qw( process_options ); -use Parrot::Configure::Test qw( - test_step_thru_runstep - rerun_defaults_for_testing - test_step_constructor_and_description -); -use IO::CaptureOutput qw( capture ); - -########## Darwin but no good Fink ########## - -my ($args, $step_list_ref) = process_options( { - argv => [], - mode => q{configure}, -} ); - -my $conf = Parrot::Configure->new(); - -test_step_thru_runstep($conf, q{init::defaults}, $args); - -my $pkg = q{auto::fink}; - -$conf->add_steps($pkg); - -my $serialized = $conf->pcfreeze(); - -$conf->options->set(%{$args}); -my $step = test_step_constructor_and_description($conf); - -# Success in the following test means: -# (a) OS is Darwin. -# (b) Either Fink is not installed or it is installed correctly, i.e., we can -# locate the Fink subdirectories we need for later Parrot configuration steps. -ok($step->runstep($conf), "runstep() returned true value"); - -$conf->replenish($serialized); - -########## not Darwin ########## - -($args, $step_list_ref) = process_options( { - argv => [], - mode => q{configure}, -} ); -# mock not Darwin -$conf->options->set(%{$args}); -$step = test_step_constructor_and_description($conf); -$conf->data->set_p5( 'OSNAME' => 'foobar' ); -ok($step->runstep($conf), "runstep() returned true value"); -is($step->result(), q{skipped}, "Got expected result for non-Darwin OS"); - -$conf->replenish($serialized); - -########## no Fink ########## - -($args, $step_list_ref) = process_options( { - argv => [], - mode => q{configure}, -} ); -# mock no Fink -$conf->options->set(%{$args}); -$step = test_step_constructor_and_description($conf); -$step->{fink_conf} = q{my_ridiculous_foobar}; -my $msg = q{Fink not installed}; - -{ - ok($step->runstep($conf), "runstep() returned true value"); - is($step->result(), $msg, "Got expected result for $msg"); -} - -$conf->replenish($serialized); - -########## Darwin but defective Fink ########## - -($args, $step_list_ref) = process_options( { - argv => [], - mode => q{configure}, -} ); -$conf->options->set(%{$args}); -$step = test_step_constructor_and_description($conf); -{ - # mock Fink config file with no Basepath - my $tfile = File::Temp->new(); - open my $fh, ">", $tfile - or croak "Unable to open temporary file for writing"; - print $fh "Message: Hello world\n"; - close $fh or croak "Unable to close temporary file after writing"; - $step->{fink_conf} = $tfile; - ok(! defined $step->runstep($conf), - "runstep() returned undef due to defective Fink config file"); - is($step->result(), q{failed}, - "Got expected result for defective Fink Config file"); -} - -$conf->replenish($serialized); - -########## Darwin but defective Fink ########## - -($args, $step_list_ref) = process_options( { - argv => [], - mode => q{configure}, -} ); -$conf->options->set(%{$args}); -$step = test_step_constructor_and_description($conf); -{ - # mock Fink config file with non-existent Basepath - my $tfile = File::Temp->new(); - open my $fh, ">", $tfile - or croak "Unable to open temporary file for writing"; - print $fh "Basepath: /my/phony/directory\n"; - close $fh or croak "Unable to close temporary file after writing"; - $step->{fink_conf} = $tfile; - ok(! defined $step->runstep($conf), - "runstep() returned undef due to unlocateable Fink directories"); - is($step->result(), q{failed}, - "Got expected result for unlocateable Fink directories"); -} - -$conf->replenish($serialized); - -########## not Darwin; --verbose ########## - -($args, $step_list_ref) = process_options( { - argv => [ q{--verbose} ], - mode => q{configure}, -} ); -$conf->options->set(%{$args}); -$step = test_step_constructor_and_description($conf); -{ - # mock not Darwin - my $phony_OS = q{foobar}; - $conf->data->set_p5( 'OSNAME' => $phony_OS ); - my ($rv, $stdout); - capture( - sub { $rv = $step->runstep($conf); }, - \$stdout, - ); - ok($rv, "runstep() returned true value"); - is($step->result(), q{skipped}, "Got expected result for non-Darwin OS"); - like($stdout, - qr/Operating system is $phony_OS; Fink is Darwin only/, - "Got expected verbose output when OS is not Darwin"); -} - -$conf->replenish($serialized); - -########## Darwin; --verbose; no Fink ########## - -($args, $step_list_ref) = process_options( { - argv => [ q{--verbose} ], - mode => q{configure}, -} ); -$conf->options->set(%{$args}); -$step = test_step_constructor_and_description($conf); -{ - # mock no Fink - $step->{fink_conf} = q{my_ridiculous_foobar}; - my $msg = q{Fink not installed}; - my ($rv, $stdout); - capture( - sub { $rv = $step->runstep($conf); }, - \$stdout, - ); - ok($rv, "runstep() returned true value"); - is($step->result(), $msg, - "Got expected result for $msg"); - like($stdout, - qr/Fink configuration file not located/, - "Got expected verbose output when OS is not Darwin"); -} - -$conf->replenish($serialized); - -########## Darwin; --verbose; defective Fink ########## - -($args, $step_list_ref) = process_options( { - argv => [ q{--verbose} ], - mode => q{configure}, -} ); -$conf->options->set(%{$args}); -$step = test_step_constructor_and_description($conf); -{ - # mock Fink config file with no Basepath - my $tfile = File::Temp->new(); - open my $fh, ">", $tfile - or croak "Unable to open temporary file for writing"; - print $fh "Message: Hello world\n"; - close $fh or croak "Unable to close temporary file after writing"; - $step->{fink_conf} = $tfile; - - my ($rv, $stdout); - capture( - sub { $rv = $step->runstep($conf); }, - \$stdout, - ); - ok(! defined $rv, - "runstep() returned undef due to defective Fink config file"); - is($step->result(), q{failed}, - "Got expected result for defective Fink Config file"); - like($stdout, - qr/Fink configuration file defective: no 'Basepath'/, - "Got expected verbose output when Fink config file lacked 'Basepath'"); -} - -$conf->replenish($serialized); - -########## Darwin; --verbose; defective Fink ########## - -($args, $step_list_ref) = process_options( { - argv => [ q{--verbose} ], - mode => q{configure}, -} ); -$conf->options->set(%{$args}); -$step = test_step_constructor_and_description($conf); -{ - # mock Fink config file with non-existent Basepath - my $tfile = File::Temp->new(); - open my $fh, ">", $tfile - or croak "Unable to open temporary file for writing"; - print $fh "Basepath: /my/phony/directory\n"; - close $fh or croak "Unable to close temporary file after writing"; - $step->{fink_conf} = $tfile; - - my ($rv, $stdout); - capture( - sub { $rv = $step->runstep($conf); }, - \$stdout, - ); - ok(! defined $rv, - "runstep() returned undef due to unlocateable Fink directories"); - is($step->result(), q{failed}, - "Got expected result for unlocateable Fink directories"); - like($stdout, - qr/Could not locate Fink directories/, - "Got expected verbose output for unlocateable Fink directories"); -} - -pass("Completed all tests in $0"); - -################### DOCUMENTATION ################### - -=head1 NAME - -auto/fink-01.t - test auto::fink - -=head1 SYNOPSIS - - % prove t/steps/auto/fink-01.t - -=head1 DESCRIPTION - -The files in this directory test functionality used by F. - -The tests in this file test auto::fink. Some tests will run only on Darwin. -Others simulate how auto::fink runs on operating systems other than Darwin. - -=head1 AUTHOR - -James E Keenan - -=head1 SEE ALSO - -config::auto::fink, F. - -=cut - -# Local Variables: -# mode: cperl -# cperl-indent-level: 4 -# fill-column: 100 -# End: -# vim: expandtab shiftwidth=4: Index: t/steps/auto/macports-01.t =================================================================== --- t/steps/auto/macports-01.t (.../trunk) (revision 39969) +++ t/steps/auto/macports-01.t (.../branches/darwin2hints) (revision 40020) @@ -1,226 +0,0 @@ -#! perl -# Copyright (C) 2007-2009, Parrot Foundation. -# $Id$ -# auto/macports-01.t - -use strict; -use warnings; -use Test::More; -use Carp; -use Cwd; -use File::Spec; -use File::Temp qw( tempdir ); -use lib qw( lib t/configure/testlib ); - -plan( skip_all => 'Macports is Darwin only' ) unless $^O =~ /darwin/; -plan( tests => 52 ); - -use_ok('config::init::defaults'); -use_ok('config::auto::macports'); -use Parrot::Configure; -use Parrot::Configure::Options qw( process_options ); -use Parrot::Configure::Test qw( - test_step_thru_runstep - test_step_constructor_and_description -); -use IO::CaptureOutput qw( capture ); - -########## not Darwin ########## - -my ($args, $step_list_ref) = process_options( { - argv => [], - mode => q{configure}, -} ); - -my $conf = Parrot::Configure->new(); - -test_step_thru_runstep($conf, q{init::defaults}, $args); - -my $pkg = q{auto::macports}; - -$conf->add_steps($pkg); - -my $serialized = $conf->pcfreeze(); - -$conf->options->set(%{$args}); -my $step = test_step_constructor_and_description($conf); - -# mock not Darwin -$conf->data->set_p5( 'OSNAME' => 'foobar' ); -ok($step->runstep($conf), "runstep() returned true value"); -is($step->result(), q{skipped}, "Got expected result for non-Darwin OS"); - -$conf->replenish($serialized); - -########## Darwin but no Macports ########## - -($args, $step_list_ref) = process_options( { - argv => [], - mode => q{configure}, -} ); -$conf->options->set(%{$args}); -$step = test_step_constructor_and_description($conf); - -# mock no Macports-default directories -$step->{ports_root} = File::Spec->catdir( qw( / my ridiculous foobar ) ); -ok($step->runstep($conf), "runstep() returned true value"); -is($step->result(), 'no', "Got expected result"); - -$conf->replenish($serialized); - -########## Darwin with Macports ########## - -($args, $step_list_ref) = process_options( { - argv => [], - mode => q{configure}, -} ); -$conf->options->set(%{$args}); -$step = test_step_constructor_and_description($conf); -my $cwd = cwd(); - -my $tdir = tempdir( CLEANUP => 1 ); -$step->{ports_root} = $tdir; -ok(chdir $tdir, "Able to change to temporary directory"); -ok( (mkdir 'lib'), "Able to make lib directory"); -ok( (mkdir 'include'), "Able to make include directory"); - -ok($step->runstep($conf), "runstep() returned true value"); -is($step->result(), q{yes}, "Got expected result"); - -is($conf->data->get('ports_base_dir'), $tdir, - "ports base directory set as expected"); -is($conf->data->get('ports_lib_dir'), qq{$tdir/lib}, - "ports 'lib' directory set as expected"); -is($conf->data->get('ports_include_dir'), qq{$tdir/include}, - "ports 'include' directory set as expected"); - -ok(chdir $cwd, "Able to change back to original directory after testing"); - -$conf->replenish($serialized); - -########## not Darwin; --verbose ########## - -($args, $step_list_ref) = process_options( { - argv => [ q{--verbose} ], - mode => q{configure}, -} ); -$conf->options->set(%{$args}); -$step = test_step_constructor_and_description($conf); -# mock not Darwin -my $osname = 'foobar'; -$conf->data->set_p5( 'OSNAME' => $osname ); -{ - my ($stdout, $stderr); - my $ret = capture sub { $step->runstep($conf) }, \$stdout, \$stderr; - ok($ret, "runstep() returned true value"); - is($step->result(), q{skipped}, "Got expected result for non-Darwin OS"); - like( - $stdout, - qr/^Operating system is $osname; Macports is Darwin only/, - "Got expected verbose output" - ); -} - -$conf->replenish($serialized); - -########## Darwin; --verbose; no Macports ########## - -($args, $step_list_ref) = process_options( { - argv => [ q{--verbose} ], - mode => q{configure}, -} ); -$conf->options->set(%{$args}); -$step = test_step_constructor_and_description($conf); -# mock no Macports-default directories -$step->{ports_root} = File::Spec->catdir( qw( / my ridiculous foobar ) ); -SKIP: { - skip 'Macports is Darwin only', 3 unless $^O =~ /darwin/; - my ($stdout, $stderr); - my $ret = capture sub { $step->runstep($conf) }, \$stdout, \$stderr; - ok($ret, "runstep() returned true value"); - is($step->result(), 'no', "Got expected result"); - like( - $stdout, - qr/^Could not locate Macports directories/, - "Got expected verbose output" - ); -} -$step->{ports_root} = undef; # prepare for next test - -$conf->replenish($serialized); - -########## Darwin; defective Macports ########## - -($args, $step_list_ref) = process_options( { - argv => [ ], - mode => q{configure}, -} ); -$conf->options->set(%{$args}); -$step = test_step_constructor_and_description($conf); -# mock no Macports root directory -SKIP: { - skip 'Macports is Darwin only', 2 unless $^O =~ /darwin/; - $step->{ports_root} = undef; - ok($step->runstep($conf), "runstep() returned true value"); - is($step->result(), 'no', "Got expected result"); -} - -$conf->replenish($serialized); - -########## Darwin; --verbose; defective Macports ########## - -($args, $step_list_ref) = process_options( { - argv => [ q{--verbose} ], - mode => q{configure}, -} ); -$conf->options->set(%{$args}); -$step = test_step_constructor_and_description($conf); -# mock no Macports root directory -$step->{ports_root} = undef; - -my ($stdout, $stderr); -my $ret = capture sub { $step->runstep($conf) }, \$stdout, \$stderr; -ok($ret, "runstep() returned true value"); -is($step->result(), 'no', "Got expected result"); -like( - $stdout, - qr/^Could not locate Macports root directory/, - "Got expected verbose output" -); - -pass("Completed all tests in $0"); - -################### DOCUMENTATION ################### - -=head1 NAME - -auto/macports-01.t - test auto::macports - -=head1 SYNOPSIS - - % prove t/steps/auto/macports-01.t - -=head1 DESCRIPTION - -The files in this directory test functionality used by F. - -The tests in this file test auto::macports. Some tests run only on Darwin. -Others simulate what happens on operating systems other than Darwin. - -=head1 AUTHOR - -James E Keenan - -=head1 SEE ALSO - -config::auto::macports, F. - -=cut - -# Local Variables: -# mode: cperl -# cperl-indent-level: 4 -# fill-column: 100 -# End: -# vim: expandtab shiftwidth=4: - Index: t/steps/auto/macports-02.t =================================================================== --- t/steps/auto/macports-02.t (.../trunk) (revision 39969) +++ t/steps/auto/macports-02.t (.../branches/darwin2hints) (revision 40020) @@ -1,77 +0,0 @@ -#! perl -# Copyright (C) 2007, Parrot Foundation. -# $Id$ -# auto/macports-02.t - -use strict; -use warnings; -use Test::More; -plan( skip_all => 'Macports is Darwin only' ) unless $^O =~ /darwin/; -plan( tests => 12 ); -use Carp; -use lib qw( lib t/configure/testlib ); -use_ok('config::init::defaults'); -$ENV{TEST_MACPORTS} = 'foobar'; -use_ok('config::auto::macports'); - -use Parrot::Configure; -use Parrot::Configure::Options qw( process_options ); -use Parrot::Configure::Test qw( - test_step_thru_runstep - test_step_constructor_and_description -); - -my ($args, $step_list_ref) = process_options( { - argv => [], - mode => q{configure}, -} ); - -my $conf = Parrot::Configure->new(); - -test_step_thru_runstep($conf, q{init::defaults}, $args); - -my $pkg = q{auto::macports}; - -$conf->add_steps($pkg); -$conf->options->set(%{$args}); -my $step = test_step_constructor_and_description($conf); - -# mock no Macports-default directories -ok($step->runstep($conf), "runstep() returned true value"); -is($step->result(), 'no', "Got expected result"); - -pass("Completed all tests in $0"); - -################### DOCUMENTATION ################### - -=head1 NAME - -auto/macports-02.t - test auto::macports - -=head1 SYNOPSIS - - % prove t/steps/auto/macports-02.t - -=head1 DESCRIPTION - -The files in this directory test functionality used by F. - -The tests in this file test auto::macports. - -=head1 AUTHOR - -James E Keenan - -=head1 SEE ALSO - -config::auto::macports, F. - -=cut - -# Local Variables: -# mode: cperl -# cperl-indent-level: 4 -# fill-column: 100 -# End: -# vim: expandtab shiftwidth=4: - Index: t/steps/auto/gmp-01.t =================================================================== --- t/steps/auto/gmp-01.t (.../trunk) (revision 39969) +++ t/steps/auto/gmp-01.t (.../branches/darwin2hints) (revision 40020) @@ -5,7 +5,7 @@ use strict; use warnings; -use Test::More tests => 61; +use Test::More tests => 31; use Carp; use Cwd; use File::Spec; @@ -102,64 +102,9 @@ '-lgmp', "_select_lib() returned expected value"); -########### _handle_darwin_for_fink() ########### - my ($flagsbefore, $flagsafter); -$osname = 'foobar'; -$flagsbefore = $conf->data->get( 'linkflags' ); -ok($step->_handle_darwin_for_fink($conf, $osname, 'gmp.h'), - "handle_darwin_for_fink() returned true value"); -$flagsafter = $conf->data->get( 'linkflags' ); -is($flagsbefore, $flagsafter, "No change in linkflags, as expected"); - my $cwd = cwd(); -{ - my $tdir = tempdir( CLEANUP => 1 ); - ok(chdir $tdir, "Able to change to temporary directory"); - ok( (mkdir 'lib'), "Able to make lib directory"); - ok( (mkdir 'include'), "Able to make include directory"); - my $libdir = File::Spec->catdir( $tdir, 'lib' ); - my $includedir = File::Spec->catdir( $tdir, 'include' ); - $conf->data->set('fink_lib_dir' => $libdir); - $conf->data->set('fink_include_dir' => $includedir); - $osname = 'darwin'; - $flagsbefore = $conf->data->get( 'linkflags' ); - ok($step->_handle_darwin_for_fink($conf, $osname, 'gmp.h'), - "handle_darwin_for_fink() returned true value"); - $flagsafter = $conf->data->get( 'linkflags' ); - is($flagsbefore, $flagsafter, "No change in linkflags, as expected"); - ok(chdir $cwd, "Able to change back to original directory after testing"); -} - -{ - my $tdir2 = tempdir( CLEANUP => 1 ); - ok(chdir $tdir2, "Able to change to temporary directory"); - ok( (mkdir 'lib'), "Able to make lib directory"); - ok( (mkdir 'include'), "Able to make include directory"); - my $libdir = File::Spec->catdir( $tdir2, 'lib' ); - my $includedir = File::Spec->catdir( $tdir2, 'include' ); - $conf->data->set('fink_lib_dir' => $libdir); - $conf->data->set('fink_include_dir' => $includedir); - my $foo = File::Spec->catfile( $includedir, 'gmp.h' ); - open my $FH, ">", $foo or croak "Could not open for writing"; - print $FH "Hello world\n"; - close $FH or croak "Could not close after writing"; - - $osname = 'darwin'; - $flagsbefore = $conf->data->get( 'linkflags' ); - ok($step->_handle_darwin_for_fink($conf, $osname, 'gmp.h'), - "handle_darwin_for_fink() returned true value"); - $flagsafter = $conf->data->get( 'linkflags' ); - isnt($flagsbefore, $flagsafter, "Change in linkflags, as expected"); - like($conf->data->get( 'linkflags' ), qr/-L\Q$libdir\E/, - "'linkflags' modified as expected"); - - ok(chdir $cwd, "Able to change back to original directory after testing"); -} - -$conf->replenish($serialized); - ########### _evaluate_cc_run() ########### ($args, $step_list_ref) = process_options( { @@ -210,66 +155,6 @@ $step->set_result(undef); } -########### _handle_darwin_for_fink() ########### - -($args, $step_list_ref) = process_options( { - argv => [ ], - mode => q{configure}, -} ); -$conf->options->set( %{$args} ); -$step = test_step_constructor_and_description($conf); -# Mock values for OS -$osname = 'darwin'; -$conf->data->set( 'linkflags' => 'foobar' ); -$flagsbefore = $conf->data->get( 'linkflags' ); -$conf->data->set( fink_lib_dir => undef ); -$conf->data->set( fink_include_dir => undef ); -ok($step->_handle_darwin_for_fink($conf, $osname, 'gmp.h'), - "handle_darwin_for_fink() returned true value"); -$flagsafter = $conf->data->get( 'linkflags' ); -is($flagsbefore, $flagsafter, "No change in linkflags, as expected"); - -$cwd = cwd(); -{ - my $tdir = tempdir( CLEANUP => 1 ); - ok(chdir $tdir, "Able to change to temporary directory"); - ok( (mkdir 'lib'), "Able to make lib directory"); -# ok( (mkdir 'include'), "Able to make include directory"); - my $libdir = File::Spec->catdir( $tdir, 'lib' ); - my $includedir = File::Spec->catdir( $tdir, 'include' ); - $conf->data->set('fink_lib_dir' => $libdir); - $conf->data->set('fink_include_dir' => $includedir); - $osname = 'darwin'; - $conf->data->set( 'linkflags' => 'foobar' ); - $flagsbefore = $conf->data->get( 'linkflags' ); - ok($step->_handle_darwin_for_fink($conf, $osname, 'gmp.h'), - "handle_darwin_for_fink() returned true value"); - $flagsafter = $conf->data->get( 'linkflags' ); - is($flagsbefore, $flagsafter, "No change in linkflags, as expected"); - - ok(chdir $cwd, "Able to change back to original directory after testing"); -} - -{ - my $tdir1 = tempdir( CLEANUP => 1 ); - ok(chdir $tdir1, "Able to change to temporary directory"); -# ok( (mkdir 'lib'), "Able to make lib directory"); - ok( (mkdir 'include'), "Able to make include directory"); - my $libdir = File::Spec->catdir( $tdir1, 'lib' ); - my $includedir = File::Spec->catdir( $tdir1, 'include' ); - $conf->data->set('fink_lib_dir' => $libdir); - $conf->data->set('fink_include_dir' => $includedir); - $osname = 'darwin'; - $conf->data->set( 'linkflags' => 'foobar' ); - $flagsbefore = $conf->data->get( 'linkflags' ); - ok($step->_handle_darwin_for_fink($conf, $osname, 'gmp.h'), - "handle_darwin_for_fink() returned true value"); - $flagsafter = $conf->data->get( 'linkflags' ); - is($flagsbefore, $flagsafter, "No change in linkflags, as expected"); - - ok(chdir $cwd, "Able to change back to original directory after testing"); -} - pass("Completed all tests in $0"); ################### DOCUMENTATION ################### Index: t/steps/auto/readline-01.t =================================================================== --- t/steps/auto/readline-01.t (.../trunk) (revision 39969) +++ t/steps/auto/readline-01.t (.../branches/darwin2hints) (revision 40020) @@ -5,7 +5,7 @@ use strict; use warnings; -use Test::More tests => 69; +use Test::More tests => 14; use Carp; use Cwd; use File::Spec; @@ -92,221 +92,6 @@ like($@, qr/_select_lib\(\) takes hashref/, "Bad argument to _select_lib correctly detected"); -########## _handle_darwin_for_fink() ########## - -my ($flagsbefore, $flagsafter); - -$osname = 'foobar'; -$flagsbefore = $conf->data->get( 'linkflags' ); -ok($step->_handle_darwin_for_fink($conf, $osname, 'readline/readline.h'), - "handle_darwin_for_fink() returned true value"); -$flagsafter = $conf->data->get( 'linkflags' ); -is($flagsbefore, $flagsafter, "No change in linkflags, as expected"); - -my $cwd = cwd(); -{ - my $tdir1 = tempdir( CLEANUP => 1 ); - ok(chdir $tdir1, "Able to change to temporary directory"); - ok( (mkdir 'lib'), "Able to make lib directory"); - ok( (mkdir 'include'), "Able to make include directory"); - my $libdir = File::Spec->catdir( $tdir1, 'lib' ); - my $includedir = File::Spec->catdir( $tdir1, 'include' ); - $conf->data->set('fink_lib_dir' => $libdir); - $conf->data->set('fink_include_dir' => $includedir); - $osname = 'darwin'; - $flagsbefore = $conf->data->get( 'linkflags' ); - ok($step->_handle_darwin_for_fink($conf, $osname, 'readline/readline.h'), - "handle_darwin_for_fink() returned true value"); - $flagsafter = $conf->data->get( 'linkflags' ); - is($flagsbefore, $flagsafter, - "No change in linkflags, as expected, where Fink lib and include directories exist but readline/readline.h does not"); - - ok(chdir $cwd, "Able to change back to original directory after testing"); -} - -{ - my $tdir2 = tempdir( CLEANUP => 1 ); - ok(chdir $tdir2, "Able to change to temporary directory"); - ok( (mkdir 'lib'), "Able to make lib directory"); - ok( (mkdir 'include'), "Able to make include directory"); - ok( (mkdir 'include/readline'), "Able to make include/readline directory"); - my $libdir = File::Spec->catdir( $tdir2, 'lib' ); - my $includedir = File::Spec->catdir( $tdir2, 'include' ); - $conf->data->set('fink_lib_dir' => $libdir); - $conf->data->set('fink_include_dir' => $includedir); - my $foo = File::Spec->catfile( $includedir, 'readline', 'readline.h' ); - open my $FH, ">", $foo or croak "Could not open for writing"; - print $FH "Hello world\n"; - close $FH or croak "Could not close after writing"; - - $osname = 'darwin'; - $flagsbefore = $conf->data->get( 'linkflags' ); - ok($step->_handle_darwin_for_fink($conf, $osname, 'readline/readline.h'), - "handle_darwin_for_fink() returned true value"); - $flagsafter = $conf->data->get( 'linkflags' ); - isnt($flagsbefore, $flagsafter, "Change in linkflags, as expected"); - like($conf->data->get( 'linkflags' ), qr/-L\Q$libdir\E/, - "'linkflags' modified as expected, in case where Fink lib and include dirs exist and readline/readline.h exists"); - $conf->data->set( linkflags => $flagsbefore ); #reset for next test - - ok(chdir $cwd, "Able to change back to original directory after testing"); -} - -{ - my $tdir3 = tempdir( CLEANUP => 1 ); - ok(chdir $tdir3, "Able to change to temporary directory"); - ok( (mkdir 'lib'), "Able to make lib directory"); - ok( (mkdir 'include'), "Able to make include directory"); - ok( (mkdir 'include/readline'), "Able to make include/readline directory"); - my $libdir = File::Spec->catdir( $tdir3, 'lib' ); - my $includedir = File::Spec->catdir( $tdir3, 'include' ); - $conf->data->set('fink_lib_dir' => $libdir); - $conf->data->set('fink_include_dir' => undef); - - $osname = 'darwin'; - $flagsbefore = $conf->data->get( 'linkflags' ); - ok($step->_handle_darwin_for_fink($conf, $osname, 'readline/readline.h'), - "handle_darwin_for_fink() returned true value"); - $flagsafter = $conf->data->get( 'linkflags' ); - is($flagsbefore, $flagsafter, - "No change in linkflags, as expected, where Fink include directory does not exist"); - - ok(chdir $cwd, "Able to change back to original directory after testing"); -} - -{ - my $tdir4 = tempdir( CLEANUP => 1 ); - ok(chdir $tdir4, "Able to change to temporary directory"); - ok( (mkdir 'lib'), "Able to make lib directory"); - ok( (mkdir 'include'), "Able to make include directory"); - ok( (mkdir 'include/readline'), "Able to make include/readline directory"); - my $libdir = File::Spec->catdir( $tdir4, 'lib' ); - my $includedir = File::Spec->catdir( $tdir4, 'include' ); - $conf->data->set('fink_lib_dir' => undef ); - $conf->data->set('fink_include_dir' => $includedir ); - - $osname = 'darwin'; - $flagsbefore = $conf->data->get( 'linkflags' ); - ok($step->_handle_darwin_for_fink($conf, $osname, 'readline/readline.h'), - "handle_darwin_for_fink() returned true value"); - $flagsafter = $conf->data->get( 'linkflags' ); - is($flagsbefore, $flagsafter, - "No change in linkflags, as expected, where Fink lib directory does not exist"); - - ok(chdir $cwd, "Able to change back to original directory after testing"); -} - -########## _handle_darwin_for_macports() ########## - -$osname = 'foobar'; -$flagsbefore = $conf->data->get( 'linkflags' ); -ok($step->_handle_darwin_for_macports($conf, $osname, 'readline/readline.h'), - "handle_darwin_for_macports() returned true value"); -$flagsafter = $conf->data->get( 'linkflags' ); -is($flagsbefore, $flagsafter, "No change in linkflags, as expected"); -# Get ready for the next test -$conf->data->set( linkflags => $flagsbefore ); - -$cwd = cwd(); -{ - my $xtdir1 = File::Spec->canonpath( tempdir( CLEANUP => 1 ) ); - ok(chdir $xtdir1, "Able to change to temporary directory"); - ok( (mkdir 'lib'), "Able to make lib directory"); - ok( (mkdir 'include'), "Able to make include directory"); - my $libdir = File::Spec->catdir( $xtdir1, 'lib' ); - my $includedir = File::Spec->catdir( $xtdir1, 'include' ); - $conf->data->set( ports_base_dir => $xtdir1 ); - $conf->data->set( ports_lib_dir => $libdir ); - $conf->data->set( ports_include_dir => $includedir ); - ok( (mkdir 'include/readline'), "Able to make include/readline directory"); - $osname = 'darwin'; - $flagsbefore = $conf->data->get( 'linkflags' ); - ok($step->_handle_darwin_for_macports($conf, $osname, 'readline/readline.h'), - "handle_darwin_for_macports() returned true value"); - $flagsafter = $conf->data->get( 'linkflags' ); - is($flagsbefore, $flagsafter, - "No change in linkflags, as expected, where macports lib and include directories exist but readline/readline.h does not"); - - chdir $cwd or croak "Unable to change back to original directory"; -} - -$cwd = cwd(); -{ - my $xtdir2 = File::Spec->canonpath( tempdir( CLEANUP => 1 ) ); - ok(chdir $xtdir2, "Able to change to temporary directory"); - ok( (mkdir 'lib'), "Able to make lib directory"); - ok( (mkdir 'include'), "Able to make include directory"); - my $libdir = File::Spec->catdir( $xtdir2, 'lib' ); - my $includedir = File::Spec->catdir( $xtdir2, 'include' ); - $conf->data->set( ports_base_dir => $xtdir2 ); - $conf->data->set( ports_lib_dir => $libdir ); - $conf->data->set( ports_include_dir => $includedir ); - ok( (mkdir 'include/readline'), "Able to make include/readline directory"); - my $foo = File::Spec->catfile( $includedir, 'readline', 'readline.h' ); - open my $FH, ">", $foo or croak "Could not open for writing"; - print $FH "Hello world\n"; - close $FH or croak "Could not close after writing"; - - $osname = 'darwin'; - $flagsbefore = $conf->data->get( 'linkflags' ); - ok($step->_handle_darwin_for_macports($conf, $osname, 'readline/readline.h'), - "handle_darwin_for_macports() returned true value"); - $flagsafter = $conf->data->get( 'linkflags' ); - isnt($flagsbefore, $flagsafter, "Change in linkflags, as expected"); - like($conf->data->get( 'linkflags' ), qr/-L\Q$libdir\E/, - "'linkflags' modified as expected, in case where macports lib and include dirs exist and readline/readline.h exists"); - $conf->data->set( linkflags => $flagsbefore ); - - chdir $cwd or croak "Unable to change back to original directory"; -} - - -$cwd = cwd(); -{ - my $xtdir3 = File::Spec->canonpath( tempdir( CLEANUP => 1 ) ); - ok(chdir $xtdir3, "Able to change to temporary directory"); - ok( (mkdir 'lib'), "Able to make lib directory"); - ok( (mkdir 'include'), "Able to make include directory"); - my $libdir = File::Spec->catdir( $xtdir3, 'lib' ); - my $includedir = File::Spec->catdir( $xtdir3, 'include' ); - $conf->data->set( ports_base_dir => $xtdir3 ); - $conf->data->set( ports_lib_dir => $libdir ); - $conf->data->set( ports_include_dir => undef ); - - $osname = 'darwin'; - $flagsbefore = $conf->data->get( 'linkflags' ); - ok($step->_handle_darwin_for_macports($conf, $osname, 'readline/readline.h'), - "handle_darwin_for_macports() returned true value"); - $flagsafter = $conf->data->get( 'linkflags' ); - is($flagsbefore, $flagsafter, - "No change in linkflags, as expected, where Macports include directory does not exist"); - - chdir $cwd or croak "Unable to change back to original directory"; -} - -$cwd = cwd(); -{ - my $xtdir4 = File::Spec->canonpath( tempdir( CLEANUP => 1 ) ); - ok(chdir $xtdir4, "Able to change to temporary directory"); - ok( (mkdir 'lib'), "Able to make lib directory"); - ok( (mkdir 'include'), "Able to make include directory"); - my $libdir = File::Spec->catdir( $xtdir4, 'lib' ); - my $includedir = File::Spec->catdir( $xtdir4, 'include' ); - $conf->data->set( ports_base_dir => $xtdir4 ); - $conf->data->set( ports_lib_dir => undef ); - $conf->data->set( ports_include_dir => $includedir ); - - $osname = 'darwin'; - $flagsbefore = $conf->data->get( 'linkflags' ); - ok($step->_handle_darwin_for_macports($conf, $osname, 'readline/readline.h'), - "handle_darwin_for_macports() returned true value"); - $flagsafter = $conf->data->get( 'linkflags' ); - is($flagsbefore, $flagsafter, - "No change in linkflags, as expected, where Macports lib directory does not exist"); - - chdir $cwd or croak "Unable to change back to original directory"; -} - pass("Completed all tests in $0"); ################### DOCUMENTATION ################### Index: t/steps/auto/gdbm-01.t =================================================================== --- t/steps/auto/gdbm-01.t (.../trunk) (revision 39969) +++ t/steps/auto/gdbm-01.t (.../branches/darwin2hints) (revision 40020) @@ -5,7 +5,7 @@ use strict; use warnings; -use Test::More tests => 47; +use Test::More tests => 40; use Carp; use Cwd; use File::Spec; @@ -56,7 +56,7 @@ $conf->replenish($serialized); -########## --without-gdbm; _handle_darwin_for_fink() ########## +########## --without-gdbm ########## ($args, $step_list_ref) = process_options( { argv => [ q{--without-gdbm} ], @@ -69,11 +69,6 @@ my $osname; my ($flagsbefore, $flagsafter); $osname = 'foobar'; -$flagsbefore = $conf->data->get( 'linkflags' ); -ok($step->_handle_darwin_for_fink($conf, $osname, 'gdbm.h'), - "handle_darwin_for_fink() returned true value"); -$flagsafter = $conf->data->get( 'linkflags' ); -is($flagsbefore, $flagsafter, "No change in linkflags, as expected"); my $cwd = cwd(); { my $tdir = tempdir( CLEANUP => 1 ); @@ -84,12 +79,6 @@ my $includedir = File::Spec->catdir( $tdir, 'include' ); $conf->data->set('fink_lib_dir' => $libdir); $conf->data->set('fink_include_dir' => $includedir); - $osname = 'darwin'; - $flagsbefore = $conf->data->get( 'linkflags' ); - ok($step->_handle_darwin_for_fink($conf, $osname, 'gdbm.h'), - "handle_darwin_for_fink() returned true value"); - $flagsafter = $conf->data->get( 'linkflags' ); - is($flagsbefore, $flagsafter, "No change in linkflags, as expected"); ok(chdir $cwd, "Able to change back to original directory after testing"); } @@ -107,15 +96,6 @@ print $FH "Hello world\n"; close $FH or croak "Could not close after writing"; - $osname = 'darwin'; - $flagsbefore = $conf->data->get( 'linkflags' ); - ok($step->_handle_darwin_for_fink($conf, $osname, 'gdbm.h'), - "handle_darwin_for_fink() returned true value"); - $flagsafter = $conf->data->get( 'linkflags' ); - isnt($flagsbefore, $flagsafter, "Change in linkflags, as expected"); - like($conf->data->get( 'linkflags' ), qr/-L\Q$libdir\E/, - "'linkflags' modified as expected"); - ok(chdir $cwd, "Able to change back to original directory after testing"); } Index: config/init/hints/darwin.pm =================================================================== --- config/init/hints/darwin.pm (.../trunk) (revision 39969) +++ config/init/hints/darwin.pm (.../branches/darwin2hints) (revision 40020) @@ -1,4 +1,4 @@ -# Copyright (C) 2005, Parrot Foundation. +# Copyright (C) 2005-2009, Parrot Foundation. # $Id$ package init::hints::darwin; @@ -6,11 +6,18 @@ use strict; use warnings; +use lib qw( lib ); +use File::Spec (); +use base qw(Parrot::Configure::Step); +use Parrot::BuildUtil; + our %defaults = ( uname => `uname -r`, sw_vers => `sw_vers -productVersion`, problem_flags => [ qw( ccflags ldflags ) ], architectures => [ qw( i386 ppc64 ppc x86_64 ) ], + fink_conf => q{/sw/etc/fink.conf}, + ports_base_dir => q{/opt/local}, ); sub runstep { @@ -40,7 +47,15 @@ my $lib_dir = $conf->data->get('build_dir') . "/blib/lib"; $flagsref->{ldflags} .= " -L$lib_dir"; $flagsref->{ccflags} .= " -pipe -fno-common -Wno-long-double "; + $flagsref->{linkflags} .= " -undefined dynamic_lookup"; + _probe_for_libraries($conf, $flagsref, 'fink'); + _probe_for_libraries($conf, $flagsref, 'macports'); + + for my $flag ( keys %$flagsref ) { + $flagsref->{$flag} =~ s/^\s+//; + } + $conf->data->set( darwin => 1, osx_version => $ENV{'MACOSX_DEPLOYMENT_TARGET'}, @@ -51,7 +66,7 @@ share_ext => '.dylib', load_ext => '.bundle', link => 'c++', - linkflags => '-undefined dynamic_lookup', + linkflags => $flagsref->{linkflags}, ld => 'c++', ld_share_flags => '-dynamiclib -undefined dynamic_lookup', ld_load_flags => '-undefined dynamic_lookup -bundle', @@ -86,7 +101,7 @@ sub _strip_arch_flags_engine { my ($arches, $stored, $flagsref, $flag) = @_; - for my $arch ( @{ $defaults{architectures} } ) { + for my $arch ( @{ $arches } ) { $stored =~ s/-arch\s+$arch//g; $stored =~ s/\s+/ /g; $flagsref->{$flag} = $stored; @@ -144,8 +159,139 @@ } } +sub _probe_for_fink { + my $conf = shift; + my $verbose = $conf->options->get( 'verbose' ); + # Per fink(8), this is location for Fink configuration file, presumably + # regardless of where Fink itself is installed. + my $fink_conf = $defaults{fink_conf}; + unless (-f $fink_conf) { + print "Fink configuration file not located\n" if $verbose; + return; + } + my $fink_conf_str = Parrot::BuildUtil::slurp_file($fink_conf); + my @lines = split /\n/, $fink_conf_str; + my $fink_base_dir; + while (defined (my $l = shift @lines) ) { + chomp $l; + next unless $l =~ /^Basepath:\s(.*)/; + $fink_base_dir = $1; + last; + } + unless (defined $fink_base_dir) { + print "Fink configuration file defective: no 'Basepath'\n" + if $verbose; + return; + } + my $fink_lib_dir = qq{$fink_base_dir/lib}; + my $fink_include_dir = qq{$fink_base_dir/include}; + my @unlocateables; + foreach my $dir ($fink_base_dir, $fink_lib_dir, $fink_include_dir) { + push @unlocateables, $dir unless (-d $dir); + } + if (@unlocateables) { + print "Could not locate Fink directories: @unlocateables\n" + if $verbose; + return; + } + else { + my %addl_flags = ( + linkflags => "-L$fink_lib_dir", + ldflags => "-L$fink_lib_dir", + ccflags => "-I$fink_include_dir", + ); + return \%addl_flags; + } +} + +sub _probe_for_macports { + my $conf = shift; + my $verbose = $conf->options->get( 'verbose' ); + my $ports_base_dir = $defaults{ports_base_dir}; + my $ports_lib_dir = qq{$ports_base_dir/lib}; + my $ports_include_dir = qq{$ports_base_dir/include}; + my @unlocateables; + foreach my $dir ($ports_base_dir, $ports_lib_dir, $ports_include_dir) { + push @unlocateables, $dir unless (-d $dir); + } + if (@unlocateables) { + print "Could not locate Macports directories: @unlocateables\n" + if $verbose; + return; + } + else { + my %addl_flags = ( + linkflags => "-L$ports_lib_dir", + ldflags => "-L$ports_lib_dir", + ccflags => "-I$ports_include_dir", + ); + return \%addl_flags; + } +} + +sub _probe_for_libraries { + my ($conf, $flagsref, $library) = @_; + my $no_library_option = "darwin_no_$library"; + my $title = ucfirst(lc($library)); + my $verbose = $conf->options->get( 'verbose' ); + unless ($conf->options->get( $no_library_option ) ) { + my $addl_flags_ref; + if ($library eq 'fink') { + $addl_flags_ref = _probe_for_fink($conf); + } + if ($library eq 'macports') { + $addl_flags_ref = _probe_for_macports($conf); + } + my $rv = _add_to_flags( $addl_flags_ref, $flagsref, $title, $verbose ); + return $rv; + } + return; +} + +sub _add_to_flags { + my ( $addl_flags_ref, $flagsref, $title, $verbose ) = @_; + if ( defined $addl_flags_ref ) { + foreach my $addl ( keys %{ $addl_flags_ref } ) { + my %seen; + if ( defined $flagsref->{$addl} ) { + my @elements = split /\s+/, $flagsref->{$addl}; + %seen = map {$_, 1} @elements; + } + $flagsref->{$addl} .= " $addl_flags_ref->{$addl}" + unless $seen{ $addl_flags_ref->{$addl} }; + } + print "Probe for $title successful\n" if $verbose; + } + else { + print "Probe for $title unsuccessful\n" if $verbose; + } + return 1; +} + 1; +################### DOCUMENTATION ################### + +=head1 NAME + +init::hints::Darwin - hints for the Darwin compiler + +=head1 DESCRIPTION + +The functionality in this package is run automatically during configuration +step F when run on Darwin. + +Among other things, this step probes for Fink and Macports libraries -- +functionality previously provided by configuration steps F and +F, which have now been eliminated. + +Should you not want to search for either of these packages, you may specify +the command-line options C and/or C. + +The functionality is tested in F. + +=cut + # Local Variables: # mode: cperl # cperl-indent-level: 4 Index: config/auto/fink.pm =================================================================== --- config/auto/fink.pm (.../trunk) (revision 39969) +++ config/auto/fink.pm (.../branches/darwin2hints) (revision 40020) @@ -1,107 +0,0 @@ -# Copyright (C) 2005-2007, Parrot Foundation. -# $Id$ - -=head1 NAME - -config/auto/fink.pm - Determine Fink location on Darwin - -=head1 DESCRIPTION - -If the operating system is Darwin, this class determines whether and where -Fink is installed. - -=cut - -package auto::fink; - -use strict; -use warnings; - -use base qw(Parrot::Configure::Step); - -use Parrot::Configure::Utils ':auto'; -use Parrot::BuildUtil; - - -sub _init { - my $self = shift; - my %data; - $data{description} = q{Determine Fink location on Darwin}; - $data{result} = q{}; - # Per fink(8), this is location for Fink configuration file, presumably - # regardless of where Fink itself is installed. - $data{fink_conf} = q{/sw/etc/fink.conf}; - return \%data; -} - -sub runstep { - my ( $self, $conf ) = ( shift, shift ); - my $osname = $conf->data->get_p5( 'OSNAME' ); - my $verbose = $conf->options->get( 'verbose' ); - unless ($osname =~ /darwin/) { - print "Operating system is $osname; Fink is Darwin only\n" - if $verbose; - $self->set_result('skipped'); - return 1; - } - # Per fink(8), this is location for Fink configuration file, presumably - # regardless of where Fink itself is installed. - my $fink_conf = $self->{fink_conf}; - unless (-f $fink_conf) { - print "Fink configuration file not located\n" - if $verbose; - $self->set_result('Fink not installed'); - return 1; - } - my $fink_conf_str = Parrot::BuildUtil::slurp_file($fink_conf); - my @lines = split /\n/, $fink_conf_str; - my $fink_base_dir; - while (defined (my $l = shift @lines) ) { - chomp $l; - next unless $l =~ /^Basepath:\s(.*)/; - $fink_base_dir = $1; - last; - } - unless (defined $fink_base_dir) { - print "Fink configuration file defective: no 'Basepath'\n" - if $verbose; - $self->set_result('failed'); - return; - } - my $fink_lib_dir = qq{$fink_base_dir/lib}; - my $fink_include_dir = qq{$fink_base_dir/include}; - my @unlocateables; - foreach my $dir ($fink_base_dir, $fink_lib_dir, $fink_include_dir) { - push @unlocateables, $dir unless (-d $dir); - } - if (@unlocateables) { - print "Could not locate Fink directories: @unlocateables\n" - if $verbose; - $self->set_result('failed'); - return; - } - else { - $conf->data->set( - fink_base_dir => $fink_base_dir, - fink_lib_dir => $fink_lib_dir, - fink_include_dir => $fink_include_dir, - ); - $self->set_result('Fink located'); - return 1; - } -} - -1; - -=head1 AUTHOR - -James E Keenan - -=cut - -# Local Variables: -# mode: cperl -# cperl-indent-level: 4 -# fill-column: 100 -# End: -# vim: expandtab shiftwidth=4: Index: config/auto/macports.pm =================================================================== --- config/auto/macports.pm (.../trunk) (revision 39969) +++ config/auto/macports.pm (.../branches/darwin2hints) (revision 40020) @@ -1,104 +0,0 @@ -# Copyright (C) 2005-2007, Parrot Foundation. -# $Id$ - -=head1 NAME - -config/auto/macports.pm - Determine Macports location on Darwin - -=head1 DESCRIPTION - -If the operating system is Darwin, this class determines whether or not -Macports is installed in the default location. - -B No provision is yet made for Macports installation in non-default -locations. - -B This step is currently Darwin/Macports-specific because it -consolidates code previously found in multiple configuration step classes. -With some modification it may be suitable for application to BSD F -programs in general, but as there was no BSD-specific code in the -configuration step classes, that modification has not yet been made. - -=cut - -package auto::macports; - -use strict; -use warnings; - -use File::Spec; -use base qw(Parrot::Configure::Step); - -use Parrot::Configure::Utils ':auto'; -use Parrot::BuildUtil; - -sub _init { - my $self = shift; - my %data; - $data{description} = q{Determine Macports location on Darwin}; - $data{result} = q{}; - my $optlocal = File::Spec->catdir( '/', 'opt', 'local' ); - $data{ports_root} = (defined $ENV{TEST_MACPORTS}) - ? $ENV{TEST_MACPORTS} - : (-d $optlocal) - ? $optlocal - : undef; - return \%data; -} - -sub runstep { - my ( $self, $conf ) = ( shift, shift ); - my $osname = $conf->data->get_p5( 'OSNAME' ); - my $verbose = $conf->options->get( 'verbose' ); - unless ($osname =~ /darwin/) { - print "Operating system is $osname; Macports is Darwin only\n" - if $verbose; - $self->set_result('skipped'); - return 1; - } - if (! defined $self->{ports_root}) { - print "Could not locate Macports root directory\n" - if $verbose; - $self->set_result('no'); - return 1; - } - - my $ports_base_dir = $self->{ports_root}; - my $ports_lib_dir = qq{$ports_base_dir/lib}; - my $ports_include_dir = qq{$ports_base_dir/include}; - my @unlocateables; - foreach my $dir ($ports_base_dir, $ports_lib_dir, $ports_include_dir) { - push @unlocateables, $dir unless (-d $dir); - } - if (@unlocateables) { - print "Could not locate Macports directories: @unlocateables\n" - if $verbose; - $self->set_result('no'); - return 1; - } - else { - $conf->data->set( - ports_base_dir => $ports_base_dir, - ports_lib_dir => $ports_lib_dir, - ports_include_dir => $ports_include_dir, - ); - $self->set_result('yes'); - return 1; - } -} - -1; - -=head1 AUTHOR - -James E Keenan, consolidating code written by Alberto SimÃes, Leopold Toetsch -and others. - -=cut - -# Local Variables: -# mode: cperl -# cperl-indent-level: 4 -# fill-column: 100 -# End: -# vim: expandtab shiftwidth=4: Index: config/auto/gettext.pm =================================================================== --- config/auto/gettext.pm (.../trunk) (revision 39969) +++ config/auto/gettext.pm (.../branches/darwin2hints) (revision 40020) @@ -61,11 +61,6 @@ default => defined $conf->data->get('glibc') ? '' : '-lintl', } ); - # On OS X check the presence of the gettext header in the standard - # Fink and MacPorts locations. - $self->_handle_darwin_for_fink($conf, $osname, 'libintl.h'); - $self->_handle_darwin_for_macports($conf, $osname, 'libintl.h'); - $conf->cc_gen('config/auto/gettext/gettext_c.in'); eval { $conf->cc_build( q{}, $extra_libs ); }; my $has_gettext = 0; Index: config/auto/opengl.pm =================================================================== --- config/auto/opengl.pm (.../trunk) (revision 39969) +++ config/auto/opengl.pm (.../branches/darwin2hints) (revision 40020) @@ -179,12 +179,6 @@ default => '-lglut -lGLU -lGL', } ); - # On OS X check the presence of the OpenGL headers in the standard - # Fink/macports locations. - # Mindlessly morphed from readline ... may need to be fixed - $self->_handle_darwin_for_fink ($conf, $osname, 'GL/glut.h'); - $self->_handle_darwin_for_macports($conf, $osname, 'GL/glut.h'); - $conf->cc_gen('config/auto/opengl/opengl_c.in'); my $has_glut = 0; eval { $conf->cc_build( q{}, $extra_libs ) }; Index: config/auto/gmp.pm =================================================================== --- config/auto/gmp.pm (.../trunk) (revision 39969) +++ config/auto/gmp.pm (.../branches/darwin2hints) (revision 40020) @@ -66,11 +66,6 @@ default => '-lgmp', } ); - # On OS X check the presence of the gmp header in the standard - # Fink location. - $self->_handle_darwin_for_fink($conf, $osname, 'gmp.h'); - $self->_handle_darwin_for_macports($conf, $osname, 'gmp.h'); - $conf->cc_gen('config/auto/gmp/gmp_c.in'); eval { $conf->cc_build( q{}, $extra_libs); }; my $has_gmp = 0; Index: config/auto/gdbm.pm =================================================================== --- config/auto/gdbm.pm (.../trunk) (revision 39969) +++ config/auto/gdbm.pm (.../branches/darwin2hints) (revision 40020) @@ -61,10 +61,6 @@ default => '-lgdbm', } ); - # On OS X check the presence of the gdbm header in the standard - # Fink location. - $self->_handle_darwin_for_fink($conf, $osname, 'gdbm.h'); - $conf->cc_gen('config/auto/gdbm/gdbm_c.in'); eval { $conf->cc_build( q{}, $extra_libs ); }; my $has_gdbm = 0; Index: config/auto/readline.pm =================================================================== --- config/auto/readline.pm (.../trunk) (revision 39969) +++ config/auto/readline.pm (.../branches/darwin2hints) (revision 40020) @@ -49,11 +49,6 @@ default => '-lreadline', } ); - # On OS X check the presence of the readline header in the standard - # Fink/macports locations. - $self->_handle_darwin_for_fink($conf, $osname, 'readline/readline.h'); - $self->_handle_darwin_for_macports($conf, $osname, q{readline/readline.h}); - $conf->cc_gen('config/auto/readline/readline_c.in'); my $has_readline = 0; eval { $conf->cc_build( q{}, $extra_libs ) }; Index: config/auto/pcre.pm =================================================================== --- config/auto/pcre.pm (.../trunk) (revision 39969) +++ config/auto/pcre.pm (.../branches/darwin2hints) (revision 40020) @@ -56,11 +56,6 @@ default => '-lpcre', } ); - # On OS X check the presence of the pcre headers in the standard - # Fink/macports locations. - $self->_handle_darwin_for_fink ($conf, $osname, 'pcre.h'); - $self->_handle_darwin_for_macports($conf, $osname, 'pcre.h'); - $conf->cc_gen('config/auto/pcre/pcre_c.in'); eval { $conf->cc_build( q{}, $extra_libs ) }; my $has_pcre = 0;