| 1 | #!perl | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | # NB no warnings because of "implicit split to @_" | ||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 7 | $/ = undef; | |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | 7 | my @files = grep { -f $_ } qw(Makefile.PL Build.PL); | |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | (my @oses = @ARGV) || die("You must specify at least one OS\n"); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 7 | ▶ | eval "use Devel::AssertOS"; # to load AssertOS and CheckOS | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | 7 | my $verbose = 1; | |||||||||||||||||||||||||||||||||
| 17 | 7 | ▶ | if($oses[0] eq '-q') { # mostly to make tests shut the hell up | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 18 | 6 | $verbose = 0; | |||||||||||||||||||||||||||||||||
| 19 | 6 | shift @oses; | |||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | 7 | ▶ | if($oses[0] eq '-l') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 23 | 1 | print join(', ', Devel::CheckOS::list_platforms())."\n"; | |||||||||||||||||||||||||||||||||
| 24 | 1 | exit(0); | |||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | 6 | ▶ | if(!-e 'MANIFEST') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 29 | 4 | ▶ | open(MANIFEST, '>>MANIFEST') || die("Can't update MANIFEST\n"); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 30 | 4 | print MANIFEST "MANIFEST\n"; | |||||||||||||||||||||||||||||||||
| 31 | 4 | close(MANIFEST); | |||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||
| 33 | 6 | ▶ | if(!@files) { # neither Makefile.PL no Build.PL exists, so create Makefile.PL | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 34 | 3 | ▶ | open(MANIFEST, '>>MANIFEST') || die("Can't update MANIFEST\n"); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 35 | 3 | print MANIFEST "Makefile.PL\n"; | |||||||||||||||||||||||||||||||||
| 36 | 3 | close(MANIFEST); | |||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | 6 | ▶ | push @files, 'Makefile.PL' unless(@files); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | # NB can't just use scalar list_platforms cos that won't tell us that, | ||||||||||||||||||||||||||||||||||
| 42 | # eg, Linux::v2_6 also uses Linux | ||||||||||||||||||||||||||||||||||
| 43 | 6 | foreach my $os (@oses) { | |||||||||||||||||||||||||||||||||
| 44 | 12 | my %oldinc = %INC; | |||||||||||||||||||||||||||||||||
| 45 | 12 | ▶ | eval "use Devel::AssertOS qw($os)"; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 46 | 12 | ▶ | if( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 47 | 1225 | join(':', map { $_ => $oldinc{$_} } sort keys %oldinc) eq | |||||||||||||||||||||||||||||||||
| 48 | 1282 | join(':', map { $_ => $INC{$_} } sort keys %INC) | |||||||||||||||||||||||||||||||||
| 49 | ) { | ||||||||||||||||||||||||||||||||||
| 50 | 0 | print STDERR "Couldn't find a module for $os\n"; | |||||||||||||||||||||||||||||||||
| 51 | 0 | exit(1); | |||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||
| 54 | 6 | my @modulefiles = keys %{{ | |||||||||||||||||||||||||||||||||
| 55 | 69 | map { $_ => $INC{$_} } | |||||||||||||||||||||||||||||||||
| 56 | grep { | ||||||||||||||||||||||||||||||||||
| 57 | 6 | ▶ | /\bDevel\b/i && | ||||||||||||||||||||||||||||||||
|
Condition100%6/6
/\bDevel\b/i && /\b(Check|Assert)OS\b/i && !($_ =~ /\bAlias\b/i)
/\bDevel\b/i and /\b(Check|Assert)OS\b/i
MC/DC100%3/3
/\bDevel\b/i && /\b(Check|Assert)OS\b/i && !($_ =~ /\bAlias\b/i)
/\bDevel\b/i
/\b(Check|Assert)OS\b/i
!($_ =~ /\bAlias\b/i)
Truth table100%4/4
A and B && not(C)
A= /\bDevel\b/iB= /\b(Check|Assert)OS\b/iC= !($_ =~ /\bAlias\b/i)
| |||||||||||||||||||||||||||||||||||
| 58 | /\b(Check|Assert)OS\b/i && | ||||||||||||||||||||||||||||||||||
| 59 | $_ !~ /\bAlias\b/i | ||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||
| 61 | keys %INC | ||||||||||||||||||||||||||||||||||
| 62 | }}; | ||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | 6 | mkdir 'inc'; | |||||||||||||||||||||||||||||||||
| 65 | 6 | mkdir 'inc/Devel'; | |||||||||||||||||||||||||||||||||
| 66 | 6 | mkdir 'inc/Devel/AssertOS'; | |||||||||||||||||||||||||||||||||
| 67 | 6 | ▶ | print "Extra directories created under inc/\n" if($verbose); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | 6 | ▶ | open(MANIFEST, '>>MANIFEST') || die("Can't update MANIFEST\n"); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 70 | 7 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 71 | 6 | foreach my $modulefile (@modulefiles) { | |||||||||||||||||||||||||||||||||
| 72 | 69 | my $fullfilename = ''; | |||||||||||||||||||||||||||||||||
| 73 | 69 | SEARCHINC: foreach (@INC) { | |||||||||||||||||||||||||||||||||
| 74 | 138 | ▶ | if(-e File::Spec->catfile($_, $modulefile)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 75 | 69 | $fullfilename = File::Spec->catfile($_, $modulefile); | |||||||||||||||||||||||||||||||||
| 76 | 69 | last SEARCHINC; | |||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||
| 79 | 69 | ▶ | die("Can't find a file for $modulefile\n") unless(-e $fullfilename); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | 69 | (my $module = join('::', split(/\W+/, $modulefile))) =~ s/::pm/.pm/; | |||||||||||||||||||||||||||||||||
| 82 | 69 | my @dircomponents = ('inc', (split(/::/, $module))); | |||||||||||||||||||||||||||||||||
| 83 | 69 | my $file = pop @dircomponents; | |||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | 69 | mkdir File::Spec->catdir(@dircomponents); | |||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||
| 87 | 69 | ▶ | open(PM, $fullfilename) || | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 88 | die("Can't read $fullfilename: $!"); | ||||||||||||||||||||||||||||||||||
| 89 | 69 | (my $pm = <PM>) =~ s/package Devel::/package #\nDevel::/; | |||||||||||||||||||||||||||||||||
| 90 | 69 | close(PM); | |||||||||||||||||||||||||||||||||
| 91 | 69 | ▶ | open(PM, '>'.File::Spec->catfile(@dircomponents, $file)) || | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 92 | die("Can't write ".File::Spec->catfile(@dircomponents, $file).": $!"); | ||||||||||||||||||||||||||||||||||
| 93 | 69 | print PM $pm; | |||||||||||||||||||||||||||||||||
| 94 | 69 | ▶ | print "Copied $fullfilename to\n ".File::Spec->catfile(@dircomponents, $file)."\n" if($verbose); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 95 | 69 | close(PM); | |||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||
| 97 | 69 | print MANIFEST join('/', @dircomponents, $file)."\n"; | |||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||
| 99 | 6 | close(MANIFEST); | |||||||||||||||||||||||||||||||||
| 100 | 6 | ▶ | print "Added necessary modules\n" if($verbose); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 101 | 6 | ▶ | print "Updated MANIFEST\n" if($verbose); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||
| 103 | 6 | foreach my $file (@files) { | |||||||||||||||||||||||||||||||||
| 104 | 7 | my $contents = ''; | |||||||||||||||||||||||||||||||||
| 105 | 7 | ▶ | if(open(FILE, $file)) { $contents = <FILE>; close(FILE); } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 106 | 7 | ▶ | open(FILE, ">$file") || die("Can't write $file\n"); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 107 | print FILE 'use lib qw(inc); use Devel::AssertOS qw('. | ||||||||||||||||||||||||||||||||||
| 108 | join(' ', | ||||||||||||||||||||||||||||||||||
| 109 | 8 | sort { $a cmp $b } map { | |||||||||||||||||||||||||||||||||
| 110 | 7 | exists($Devel::CheckOS::OS_ALIASES{$_}) | |||||||||||||||||||||||||||||||||
| 111 | 14 | ▶ | ? $Devel::CheckOS::OS_ALIASES{$_} | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 112 | : $_ | ||||||||||||||||||||||||||||||||||
| 113 | } @oses | ||||||||||||||||||||||||||||||||||
| 114 | ). | ||||||||||||||||||||||||||||||||||
| 115 | ");\n\n"; | ||||||||||||||||||||||||||||||||||
| 116 | 7 | print FILE $contents; | |||||||||||||||||||||||||||||||||
| 117 | 7 | close(FILE); | |||||||||||||||||||||||||||||||||
| 118 | 7 | ▶ | print "Modified $file\n" if($verbose); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||
| 123 | use-devel-assertos - a script to package Devel::AssertOS modules | ||||||||||||||||||||||||||||||||||
| 124 | with your code. | ||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||
| 126 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||
| 128 | This script, when run in the directory in which your shiny new module | ||||||||||||||||||||||||||||||||||
| 129 | lives, will bundle whichever Devel::AssertOS modules you ask it to | ||||||||||||||||||||||||||||||||||
| 130 | in the C<inc> directory, and update your Makefile.PL (or Build.PL) | ||||||||||||||||||||||||||||||||||
| 131 | appropriately. If neither exists, it will create a Makefile.PL. | ||||||||||||||||||||||||||||||||||
| 132 | The MANIFEST file is updated if any files are created. | ||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||
| 134 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||
| 136 | use-devel-assertos NetBSD OpenBSD FreeBSD | ||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||
| 138 | But note that if you use C<Module::Install> you are encouraged to use | ||||||||||||||||||||||||||||||||||
| 139 | C<Module::Install::AssertOS> instead. | ||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||
| 141 | =head1 USAGE | ||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||
| 143 | In the example above, this will insert code to make your module | ||||||||||||||||||||||||||||||||||
| 144 | depend on one of the specified OSes, as well as update Makefile.PL / | ||||||||||||||||||||||||||||||||||
| 145 | Build.PL / MANIFEST. By default it's rather noisy, but you can | ||||||||||||||||||||||||||||||||||
| 146 | suppress that by passing -q as the first parameter. | ||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||
| 148 | =head1 SUPPORTED PLATFORMS | ||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||
| 150 | To get a list of supported platforms, do this: | ||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||
| 152 | use-devel-assertos -l | ||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||
| 154 | =head1 WARNINGS, BUGS and FEEDBACK | ||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||
| 156 | This script has not been thoroughly tested. You should check by | ||||||||||||||||||||||||||||||||||
| 157 | hand that it has done what you expected after running it. | ||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||
| 159 | If you use Module::Build::Compat to write a Makefile.PL, then you | ||||||||||||||||||||||||||||||||||
| 160 | will need to re-run this script whenever you have generated a new | ||||||||||||||||||||||||||||||||||
| 161 | Makefile.PL. | ||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||
| 163 | I welcome feedback about my code, including constructive criticism. | ||||||||||||||||||||||||||||||||||
| 164 | Bug reports should be made using L<https://github.com/DrHyde/perl-modules-Devel-CheckOS/issues>. | ||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||
| 166 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||
| 168 | L<Devel::AssertOS> | ||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||
| 170 | L<Devel::CheckOS> | ||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||
| 172 | L<Module::Install::AssertOS> | ||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||
| 174 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||
| 176 | David Cantrell E<lt>F<david@cantrell.org.uk>E<gt> | ||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||
| 178 | =head1 COPYRIGHT and LICENCE | ||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||
| 180 | Copyright 2024 David Cantrell | ||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||
| 182 | This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively. | ||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||
| 184 | =head1 CONSPIRACY | ||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||
| 186 | This software is also free-as-in-mason. | ||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||
| 188 | =cut | ||||||||||||||||||||||||||||||||||