| 11 | | |
| 12 | | my $path = File::Spec->catfile($ENV{HOME}, "/.pmsetuprc"); |
| 13 | | my $config = eval { YAML::LoadFile($path) } || {}; |
| 14 | | |
| 15 | | my $save; |
| 16 | | while (! $config->{author}) { |
| 17 | | $config->{author} = prompt("Your name: ", ''); |
| 18 | | $save++; |
| | 11 | use Config::Pit; |
| | 12 | |
| | 13 | my $config = pit_get("pmsetup", require => { |
| | 14 | author => "cho45", |
| | 15 | email => "cho45\@lowreal.net", |
| | 16 | scratch_repos => "Your svk base scratch DEPOTPATH: //scratch", |
| | 17 | # mirror_repos => "Your svk base mirror DEPOTPATH: //mirror", |
| | 18 | workdir => "$ENV{HOME}/tmp", |
| | 19 | }); |
| | 20 | $config->{author} || $config->{email} || $config->{workdir} || die("no settings"); |
| | 21 | |
| | 22 | -e $config->{workdir} || mkdir $config->{workdir}, 0777; |
| | 23 | |
| | 24 | unless ($config->{scratch_repos} =~ m{^//.}) { |
| | 25 | delete $config->{scratch_repos}; |
| 21 | | while (! $config->{email}) { |
| 22 | | $config->{email} = prompt("Your email: ", ''); |
| 23 | | $save++; |
| | 28 | #unless ($config->{mirror_repos} =~ m{^//.}) { |
| | 29 | # delete $config->{mirror_repos}; |
| | 30 | #} |
| | 31 | |
| | 32 | |
| | 33 | my $modname = shift @ARGV or die "Usage: $0 module\n"; |
| | 34 | $modname =~ s/-/::/g; |
| | 35 | |
| | 36 | write_plugin_files($modname, $config); |
| | 37 | |
| | 38 | sub write_plugin_files { |
| | 39 | my($module, $config) = @_; |
| | 40 | |
| | 41 | my $svk = $config->{scratch_repos} ? prompt("import to SVK? [yN] ", 'n') : "n"; |
| | 42 | my $coderepos = prompt("CodeRepos friendly? [Yn] ", 'y'); |
| | 43 | |
| | 44 | # $module = "Foo::Bar" |
| | 45 | # $dist = "Foo-Bar" |
| | 46 | # $path = "Foo/Bar.pm" |
| | 47 | my @pkg = split /::/, $module; |
| | 48 | my $dist = join "-", @pkg; |
| | 49 | my $path = join("/", @pkg) . ".pm"; |
| | 50 | |
| | 51 | mkdir $dist, 0777; |
| | 52 | chdir $dist; |
| | 53 | if ($svk =~ /[Yy]/ || $coderepos =~ /[Yy]/ ) { |
| | 54 | mkdir $_, 0777 for (qw/ trunk tags branches /); |
| | 55 | chdir 'trunk'; |
| | 56 | } |
| | 57 | |
| | 58 | my @template = YAML::Load(join '', <DATA>); |
| | 59 | my $vars = { module => $module, dist => $dist, path => $path, |
| | 60 | config => $config, localtime => scalar localtime }; |
| | 61 | |
| | 62 | for my $tmpl (@template) { |
| | 63 | my $file = $tmpl->{file}; |
| | 64 | $file =~ s/(\$\w+)/$1/eeg; |
| | 65 | if (defined $tmpl->{coderepos}) { |
| | 66 | if ($coderepos =~ /[Yy]/) { |
| | 67 | next unless $tmpl->{coderepos}; |
| | 68 | } else { |
| | 69 | next if $tmpl->{coderepos}; |
| | 70 | } |
| | 71 | } |
| | 72 | write_file($file, $tmpl->{template}, $vars); |
| | 73 | chmod oct($tmpl->{chmod}), $tmpl->{file} if $tmpl->{chmod}; |
| | 74 | } |
| | 75 | |
| | 76 | !system "perl Makefile.PL" or die $?; |
| | 77 | !system 'make test' or die $?; |
| | 78 | !system 'make manifest' or die $?; |
| | 79 | !system 'make distclean' or die $?; |
| | 80 | |
| | 81 | return unless $svk =~ /[Yy]/; |
| | 82 | chdir '..'; |
| | 83 | system("svk import -m '$dist import' $config->{scratch_repos}/$dist"); |
| | 84 | chdir '..'; |
| | 85 | rmtree("$dist"); |
| | 86 | system("svk co $config->{scratch_repos}/$dist/trunk $dist"); |
| 26 | | while (! $config->{scratch_repos}) { |
| 27 | | $config->{scratch_repos} = prompt("Your svk base scratch DEPOTPATH: [//scratch]", ''); |
| 28 | | unless ($config->{scratch_repos} =~ m{^//.}) { |
| 29 | | delete $config->{scratch_repos}; |
| 30 | | next; |
| 31 | | } |
| 32 | | $save++; |
| | 89 | sub write_file { |
| | 90 | my($path, $template, $vars) = @_; |
| | 91 | |
| | 92 | if (-e $path) { |
| | 93 | my $ans = prompt("$path exists. Override? [yN] ", 'n'); |
| | 94 | return if $ans !~ /[Yy]/; |
| | 95 | } |
| | 96 | |
| | 97 | my $dir = File::Basename::dirname($path); |
| | 98 | unless (-e $dir) { |
| | 99 | warn "Creating directory $dir\n"; |
| | 100 | File::Path::mkpath($dir, 1, 0777); |
| | 101 | } |
| | 102 | |
| | 103 | my $tt = Template->new; |
| | 104 | $tt->process(\$template, $vars, \my $content); |
| | 105 | |
| | 106 | warn "Creating $path\n"; |
| | 107 | open my $out, ">", $path or die "$path: $!"; |
| | 108 | print $out $content; |
| | 109 | close $out; |
| 35 | | while (! $config->{mirror_repos}) { |
| 36 | | $config->{mirror_repos} = prompt("Your svk base mirror DEPOTPATH: [//mirror]", ''); |
| 37 | | unless ($config->{mirror_repos} =~ m{^//.}) { |
| 38 | | delete $config->{mirror_repos}; |
| 39 | | next; |
| 40 | | } |
| 41 | | $save++; |
| 42 | | } |
| 43 | | |
| 44 | | while (! -e $config->{workdir}) { |
| 45 | | $config->{workdir} = prompt("Your workdir:", "$ENV{HOME}/tmp"); |
| 46 | | mkdir $config->{workdir}, 0777; |
| 47 | | $save++; |
| 48 | | } |
| 49 | | |
| 50 | | my $modname = shift @ARGV or die "Usage: $0 module\n"; |
| 51 | | $modname =~ s/-/::/g; |
| 52 | | |
| 53 | | write_plugin_files($modname, $config); |
| 54 | | |
| 55 | | END { |
| 56 | | YAML::DumpFile($path, $config) if $save; |
| 57 | | } |
| 58 | | |
| 59 | | sub write_plugin_files { |
| 60 | | my($module, $config) = @_; |
| 61 | | |
| 62 | | my $svk = prompt("import to SVK? [yN] ", 'n'); |
| 63 | | |
| 64 | | # $module = "Foo::Bar" |
| 65 | | # $dist = "Foo-Bar" |
| 66 | | # $path = "Foo/Bar.pm" |
| 67 | | my @pkg = split /::/, $module; |
| 68 | | my $dist = join "-", @pkg; |
| 69 | | my $path = join("/", @pkg) . ".pm"; |
| 70 | | |
| 71 | | mkdir $dist, 0777; |
| 72 | | chdir $dist; |
| 73 | | if ($svk =~ /[Yy]/) { |
| 74 | | mkdir $_, 0777 for (qw/ trunk tags branches /); |
| 75 | | chdir 'trunk'; |
| 76 | | } |
| 77 | | |
| 78 | | my @template = YAML::Load(join '', <DATA>); |
| 79 | | my $vars = { module => $module, dist => $dist, path => $path, |
| 80 | | config => $config, localtime => scalar localtime }; |
| 81 | | |
| 82 | | for my $tmpl (@template) { |
| 83 | | my $file = $tmpl->{file}; |
| 84 | | $file =~ s/(\$\w+)/$1/eeg; |
| 85 | | write_file($file, $tmpl->{template}, $vars); |
| 86 | | chmod oct($tmpl->{chmod}), $tmpl->{file} if $tmpl->{chmod}; |
| 87 | | } |
| 88 | | |
| 89 | | !system "perl Makefile.PL" or die $?; |
| 90 | | !system 'make test' or die $?; |
| 91 | | !system 'make manifest' or die $?; |
| 92 | | !system 'make distclean' or die $?; |
| 93 | | |
| 94 | | return unless $svk =~ /[Yy]/; |
| 95 | | chdir '..'; |
| 96 | | system("svk import -m '$dist import' $config->{scratch_repos}/$dist"); |
| 97 | | chdir '..'; |
| 98 | | rmtree("$dist"); |
| 99 | | system("svk co $config->{scratch_repos}/$dist/trunk $dist"); |
| 100 | | } |
| 101 | | |
| 102 | | sub write_file { |
| 103 | | my($path, $template, $vars) = @_; |
| 104 | | |
| 105 | | if (-e $path) { |
| 106 | | my $ans = prompt("$path exists. Override? [yN] ", 'n'); |
| 107 | | return if $ans !~ /[Yy]/; |
| 108 | | } |
| 109 | | |
| 110 | | my $dir = File::Basename::dirname($path); |
| 111 | | unless (-e $dir) { |
| 112 | | warn "Creating directory $dir\n"; |
| 113 | | File::Path::mkpath($dir, 1, 0777); |
| 114 | | } |
| 115 | | |
| 116 | | my $tt = Template->new; |
| 117 | | $tt->process(\$template, $vars, \my $content); |
| 118 | | |
| 119 | | warn "Creating $path\n"; |
| 120 | | open my $out, ">", $path or die "$path: $!"; |
| 121 | | print $out $content; |
| 122 | | close $out; |
| 123 | | } |
| 124 | | |
| | 120 | --- |
| | 121 | file: Rakefile |
| | 122 | template: | |
| | 123 | require "rubygems" |
| | 124 | require "rake" |
| | 125 | require "shipit" |
| | 126 | require "pathname" |
| | 127 | |
| | 128 | makefilepl = Pathname.new("Makefile.PL") |
| | 129 | |
| | 130 | NAME = makefilepl.read[/name '([^']+)';/, 1] |
| | 131 | #VERS = |
| | 132 | #DESCRIPTION = |
| | 133 | |
| | 134 | task :default => :test |
| | 135 | |
| | 136 | desc "make test" |
| | 137 | task :test => ["Makefile"] do |
| | 138 | sh %{make test} |
| | 139 | end |
| | 140 | |
| | 141 | desc "make clean" |
| | 142 | task :clean => ["Makefile"] do |
| | 143 | sh %{make clean} |
| | 144 | end |
| | 145 | |
| | 146 | desc "make install" |
| | 147 | task :install => ["Makefile"] do |
| | 148 | sh %{sudo make install} |
| | 149 | end |
| | 150 | |
| | 151 | desc "release" |
| | 152 | task :release => :shipit |
| | 153 | |
| | 154 | task :shipit => [:test, "MANIFEST"] |
| | 155 | Rake::ShipitTask.new do |s| |
| | 156 | ENV["LANG"] = "C" |
| | 157 | s.Step.new { |
| | 158 | # check |
| | 159 | system("svn", "up") |
| | 160 | raise "Any chages remain?\n#{`svn st`}" unless `svn st`.empty? |
| | 161 | }.and {} |
| | 162 | s.Step.new { |
| | 163 | system "shipit", "-n" |
| | 164 | print "Check dry-run result and press Any Key to continue (or cancel by Ctrl-C)." |
| | 165 | $stdin.gets |
| | 166 | }.and { |
| | 167 | system "shipit" |
| | 168 | } |
| | 169 | end |
| | 170 | |
| | 171 | file "Makefile" => ["Makefile.PL"] do |
| | 172 | sh %{perl Makefile.PL} |
| | 173 | end |
| | 174 | |
| | 175 | file "Makefile.PL" |
| | 176 | |
| | 177 | file "MANIFEST" => Dir["**/*"].delete_if {|i| i == "MANIFEST" } do |
| | 178 | rm "MANIFEST" if File.exist?("MANIFEST") |
| | 179 | sh %{perl Makefile.PL} |
| | 180 | sh %{make} |
| | 181 | sh %{make manifest} |
| | 182 | end |
| 280 | | file: tools/release.pl |
| 281 | | chmod: 0744 |
| 282 | | template: | |
| 283 | | #!/usr/bin/perl |
| 284 | | use warnings; |
| 285 | | use strict; |
| 286 | | use File::Path; |
| 287 | | use LWP::Simple; |
| 288 | | use ExtUtils::MakeMaker qw(prompt); |
| 289 | | |
| 290 | | my $version = shift @ARGV or die "Usage: release.pl version"; |
| 291 | | |
| 292 | | my @pkg = split /::/, '[% module %]'; |
| 293 | | my $dist = join "-", @pkg; |
| 294 | | my $path = join("/", @pkg) . ".pm"; |
| 295 | | |
| 296 | | my $workdir = "[% config.workdir %]"; |
| 297 | | my $checkout = "$dist-$version"; |
| 298 | | |
| 299 | | chdir $workdir; |
| 300 | | |
| 301 | | if (-e $checkout) { |
| 302 | | die "$workdir/$checkout exists. Remove it first"; |
| 303 | | } |
| 304 | | |
| 305 | | system("svk co [% config.mirror_repos %]/$dist/trunk $checkout"); |
| 306 | | sleep(2); |
| 307 | | |
| 308 | | if (-e $checkout) { |
| 309 | | chdir $checkout; |
| 310 | | |
| 311 | | rewrite_version("lib/$path", $version); |
| 312 | | |
| 313 | | system("perl Makefile.PL --skip"); |
| 314 | | system("make manifest"); |
| 315 | | |
| 316 | | check_version("Changes", $version); |
| 317 | | |
| 318 | | if (!system("make disttest")) { |
| 319 | | system("svk ci -m 'packaging $version'"); |
| 320 | | system("svk cp -m 'tag release $version' [% config.mirror_repos %]/$dist/trunk [% config.mirror_repos %]/$dist/tags/release-$version"); |
| 321 | | system("make dist"); |
| 322 | | if (prompt("upload to CPAN?: [yN]", 'n') =~ /[yY]/) { |
| 323 | | system("cpan-upload -verbose $dist-$version.tar.gz"); |
| 324 | | } else { |
| 325 | | rename "$dist-$version.tar.gz", "../$dist-$version.tar.gz"; |
| 326 | | } |
| 327 | | } else { |
| 328 | | warn "make disttest failed. Don't upload"; |
| 329 | | } |
| 330 | | |
| 331 | | chdir ".."; |
| 332 | | system("svk co --detach $checkout"); |
| 333 | | } |
| 334 | | |
| 335 | | rmtree("$workdir/$checkout"); |
| 336 | | |
| 337 | | sub rewrite_version { |
| 338 | | my($file, $version) = @_; |
| 339 | | |
| 340 | | open my $fh, $file or die "$file: $!"; |
| 341 | | my $content = join '', <$fh>; |
| 342 | | close $fh; |
| 343 | | |
| 344 | | $content =~ s/^our \$VERSION = .*?;$/our \$VERSION = '$version';/m; |
| 345 | | |
| 346 | | open my $out, ">", "lib/$path"; |
| 347 | | print $out $content; |
| 348 | | close $out; |
| 349 | | } |
| 350 | | |
| 351 | | sub check_version { |
| 352 | | my($file, $version) = @_; |
| 353 | | |
| 354 | | open my $fh, $file or die "$file: $!"; |
| 355 | | while (<$fh>) { |
| 356 | | /^\Q$version\E / and return 1; |
| 357 | | } |
| 358 | | |
| 359 | | die "$file doesn't contain log for $version"; |
| 360 | | } |
| | 332 | file: .shipit |
| | 333 | chmod: 0644 |
| | 334 | coderepos: 0 |
| | 335 | template: | |
| | 336 | steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN |
| | 337 | svk.tagpattern = release-%v |
| | 338 | --- |
| | 339 | file: .shipit |
| | 340 | chmod: 0644 |
| | 341 | coderepos: 1 |
| | 342 | template: | |
| | 343 | steps = CommitMessageWrap, FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN |
| | 344 | svk.tagpattern = release-%v |
| | 345 | commit_message.format = lang/perl/[% dist %]: %msg |