Commit | Line | Data |
bb4e9162 |
1 | package Module::Build::Platform::MacOS; |
2 | |
3 | use strict; |
4 | use Module::Build::Base; |
5 | use base qw(Module::Build::Base); |
6 | |
7 | use ExtUtils::Install; |
8 | |
9 | sub new { |
10 | my $class = shift; |
11 | my $self = $class->SUPER::new(@_); |
12 | |
13 | # $Config{sitelib} and $Config{sitearch} are, unfortunately, missing. |
14 | $self->{config}{sitelib} ||= $self->{config}{installsitelib}; |
15 | $self->{config}{sitearch} ||= $self->{config}{installsitearch}; |
16 | |
17 | # For some reason $Config{startperl} is filled with a bunch of crap. |
18 | $self->{config}{startperl} =~ s/.*Exit \{Status\}\s//; |
19 | |
20 | return $self; |
21 | } |
22 | |
23 | sub make_executable { |
24 | my $self = shift; |
25 | require MacPerl; |
26 | foreach (@_) { |
27 | MacPerl::SetFileInfo('McPL', 'TEXT', $_); |
28 | } |
29 | } |
30 | |
31 | sub dispatch { |
32 | my $self = shift; |
33 | |
34 | if( !@_ and !@ARGV ) { |
35 | require MacPerl; |
36 | |
37 | # What comes first in the action list. |
38 | my @action_list = qw(build test install); |
39 | my %actions = map {+($_, 1)} $self->known_actions; |
40 | delete @actions{@action_list}; |
41 | push @action_list, sort { $a cmp $b } keys %actions; |
42 | |
43 | my %toolserver = map {+$_ => 1} qw(test disttest diff testdb); |
44 | foreach (@action_list) { |
45 | $_ .= ' *' if $toolserver{$_}; |
46 | } |
47 | |
48 | my $cmd = MacPerl::Pick("What build command? ('*' requires ToolServer)", @action_list); |
49 | return unless defined $cmd; |
50 | $cmd =~ s/ \*$//; |
51 | $ARGV[0] = ($cmd); |
52 | |
53 | my $args = MacPerl::Ask('Any extra arguments? (ie. verbose=1)', ''); |
54 | return unless defined $args; |
55 | push @ARGV, $self->split_like_shell($args); |
56 | } |
57 | |
58 | $self->SUPER::dispatch(@_); |
59 | } |
60 | |
61 | sub ACTION_realclean { |
62 | my $self = shift; |
63 | chmod 0666, $self->{properties}{build_script}; |
64 | $self->SUPER::ACTION_realclean; |
65 | } |
66 | |
67 | # ExtUtils::Install has a hard-coded '.' directory in versions less |
68 | # than 1.30. We use a sneaky trick to turn that into ':'. |
69 | # |
70 | # Note that we do it here in a cross-platform way, so this code could |
71 | # actually go in Module::Build::Base. But we put it here to be less |
72 | # intrusive for other platforms. |
73 | |
74 | sub ACTION_install { |
75 | my $self = shift; |
76 | |
77 | return $self->SUPER::ACTION_install(@_) |
78 | if eval {ExtUtils::Install->VERSION('1.30'); 1}; |
79 | |
80 | local $^W = 0; # Avoid a 'redefine' warning |
81 | local *ExtUtils::Install::find = sub { |
82 | my ($code, @dirs) = @_; |
83 | |
84 | @dirs = map { $_ eq '.' ? File::Spec->curdir : $_ } @dirs; |
85 | |
86 | return File::Find::find($code, @dirs); |
87 | }; |
88 | |
89 | return $self->SUPER::ACTION_install(@_); |
90 | } |
91 | |
92 | 1; |
93 | __END__ |
94 | |
95 | =head1 NAME |
96 | |
97 | Module::Build::Platform::MacOS - Builder class for MacOS platforms |
98 | |
99 | =head1 DESCRIPTION |
100 | |
101 | The sole purpose of this module is to inherit from |
102 | C<Module::Build::Base> and override a few methods. Please see |
103 | L<Module::Build> for the docs. |
104 | |
105 | =head2 Overriden Methods |
106 | |
107 | =over 4 |
108 | |
109 | =item new() |
110 | |
111 | MacPerl doesn't define $Config{sitelib} or $Config{sitearch} for some |
112 | reason, but $Config{installsitelib} and $Config{installsitearch} are |
113 | there. So we copy the install variables to the other location |
114 | |
115 | =item make_executable() |
116 | |
117 | On MacOS we set the file type and creator to MacPerl so it will run |
118 | with a double-click. |
119 | |
120 | =item dispatch() |
121 | |
122 | Because there's no easy way to say "./Build test" on MacOS, if |
123 | dispatch is called with no arguments and no @ARGV a dialog box will |
124 | pop up asking what action to take and any extra arguments. |
125 | |
126 | Default action is "test". |
127 | |
128 | =item ACTION_realclean() |
129 | |
130 | Need to unlock the Build program before deleting. |
131 | |
132 | =back |
133 | |
134 | =head1 AUTHOR |
135 | |
136 | Michael G Schwern <schwern@pobox.com> |
137 | |
138 | |
139 | =head1 SEE ALSO |
140 | |
141 | perl(1), Module::Build(3), ExtUtils::MakeMaker(3) |
142 | |
143 | =cut |