Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

nightly build script

  • Loading branch information...
commit 748eeb92a05b3a57ba5bbeebcae9241df5646e29 1 parent 2b0d3bf
Robert Norris authored

Showing 1 changed file with 209 additions and 0 deletions. Show diff stats Hide diff stats

  1. +209 0 scripts/nightly-build.pl
209 scripts/nightly-build.pl
... ... @@ -0,0 +1,209 @@
  1 +#!/usr/bin/env perl
  2 +
  3 +use 5.010;
  4 +
  5 +use warnings;
  6 +use strict;
  7 +use autodie qw(:all);
  8 +
  9 +use constant SOURCE_DIR => q{/home/rob/pioneer};
  10 +use constant TEMP_DIR => q{/tmp};
  11 +use constant OUT_DIR => q{/home/rob};
  12 +use constant CHROOT_DIR => q{/home/rob/squeeze};
  13 +use constant THIRDPARTY_DIR => q{/home/rob/pioneer-thirdparty};
  14 +use constant MXE_DIR => q{/home/rob/mxe};
  15 +use constant CONFIGURE_OPTS => q{--with-ccache --enable-debug};
  16 +use constant UPLOAD_PATH_FORMAT => q{robertnorris,pioneerspacesim@frs.sf.net:/home/frs/project/p/pi/pioneerspacesim/%s};
  17 +use constant URL_FORMAT => q{http://sourceforge.net/projects/pioneerspacesim/files/nightly/%s/download};
  18 +
  19 +use constant PLATFORM => {
  20 + linux64 => {
  21 + suffix => "",
  22 + configure_opts => "",
  23 + builder => \&build_chroot,
  24 + archiver => \&archive_bz2,
  25 + },
  26 + linux32 => {
  27 + suffix => "",
  28 + configure_opts => "",
  29 + builder => \&build_chroot,
  30 + archiver => \&archive_bz2,
  31 + },
  32 + win32 => {
  33 + suffix => ".exe",
  34 + configure_opts => "--with-mxe=".MXE_DIR,
  35 + build_dir => SOURCE_DIR,
  36 + builder => \&build_local,
  37 + archiver => \&archive_7z,
  38 + },
  39 +};
  40 +
  41 +my $branch = shift @ARGV || "master";
  42 +my $build_type = shift @ARGV || "nightly";
  43 +
  44 +if (!grep { $_ eq $build_type } qw(alpha nightly)) {
  45 + say STDERR "unknown build type $build_type";
  46 + exit 1;
  47 +}
  48 +
  49 +my $ref = update_source($branch);
  50 +
  51 +my %archives;
  52 +for my $platform (keys %{PLATFORM()}) {
  53 + my $build_dir = build($platform);
  54 + my $copy_dir = copy($platform, $build_dir);
  55 + $archives{$platform} = archive($platform, $copy_dir);
  56 +}
  57 +
  58 +upload(values %archives);
  59 +
  60 +tweet(%archives);
  61 +
  62 +sub update_source {
  63 + my ($branch) = @_;
  64 +
  65 + say STDERR ">>> updating source";
  66 +
  67 + chdir SOURCE_DIR;
  68 + system "git fetch";
  69 + system "git checkout origin/$branch || git checkout $branch";
  70 +
  71 + my $ref = `git log -n1 --pretty=%h origin/$branch`;
  72 + chomp $ref;
  73 + return $ref;
  74 +}
  75 +
  76 +sub build_local {
  77 + my ($platform, $configure_opts) = @_;
  78 +
  79 + say STDERR ">>> local build: ".PLATFORM->{$platform}->{build_dir};
  80 +
  81 + chdir PLATFORM->{$platform}->{build_dir};
  82 +
  83 + {
  84 + no autodie;
  85 + system "make distclean";
  86 + }
  87 + system "./bootstrap";
  88 + system "./configure $configure_opts";
  89 + system "make clean";
  90 + system "make";
  91 +
  92 + return PLATFORM->{$platform}->{build_dir};
  93 +}
  94 +
  95 +sub build_chroot {
  96 + my ($platform, $configure_opts) = @_;
  97 +
  98 + say STDERR ">>> chroot build";
  99 +
  100 + system sprintf("sudo rsync -av --delete --exclude=pioneer/.git %s %s/%s", SOURCE_DIR, CHROOT_DIR, $platform);
  101 + system sprintf("sudo chroot %s/%s sh -c 'cd pioneer && ./configure && make distclean && ./configure %s && make'", CHROOT_DIR, $platform, $configure_opts);
  102 +
  103 + return sprintf("%s/%s/pioneer", CHROOT_DIR, $platform);
  104 +}
  105 +
  106 +sub build {
  107 + my ($platform) = @_;
  108 +
  109 + say STDERR ">>> $platform: building";
  110 +
  111 + my $configure_opts = join ' ', (CONFIGURE_OPTS, PLATFORM->{$platform}->{configure_opts}, "--with-extra-version=$ref");
  112 +
  113 + return PLATFORM->{$platform}->{builder}($platform, $configure_opts);
  114 +}
  115 +
  116 +sub filename_base {
  117 + my ($platform) = @_;
  118 +
  119 + return
  120 + $build_type eq "alpha" ? "pioneer-$branch-$platform" :
  121 + $branch eq "master" ? "pioneer-$ref-$platform" :
  122 + "pioneer-$branch-$ref-$platform";
  123 +}
  124 +
  125 +sub copy {
  126 + my ($platform, $source_dir) = @_;
  127 +
  128 + say ">>> $platform: copying";
  129 +
  130 + chdir $source_dir;
  131 +
  132 + my $copy_dir = TEMP_DIR.'/'.filename_base($platform);
  133 + system "mkdir -p $copy_dir";
  134 +
  135 + my $suffix = PLATFORM->{$platform}->{suffix};
  136 +
  137 + system "cp -v src/pioneer$suffix src/modelviewer$suffix $copy_dir";
  138 + system "cp -v src/pioneer.map src/modelviewer.map $copy_dir";
  139 + system "cp -v *.txt $copy_dir";
  140 + system "cp -rv data $copy_dir/data";
  141 +
  142 + system "find $copy_dir/data '(' -name .gitignore -o -name Makefile\\\* ')' -delete";
  143 +
  144 + return $copy_dir;
  145 +}
  146 +
  147 +sub archive {
  148 + my ($platform, $source_dir) = @_;
  149 +
  150 + say STDERR ">>> $platform: archiving";
  151 +
  152 + chdir "$source_dir/..";
  153 +
  154 + my $archive = PLATFORM->{$platform}->{archiver}($platform);
  155 +
  156 + system "rm -rf $source_dir";
  157 +
  158 + return $archive;
  159 +}
  160 +
  161 +sub archive_bz2 {
  162 + my ($platform) = @_;
  163 +
  164 + my $base = filename_base($platform);
  165 + my $out = OUT_DIR."/$base.tar";
  166 +
  167 + system "tar cvf $out $base";
  168 + system "bzip2 $out";
  169 +
  170 + my $arc = "$base.tar.bz2";
  171 + say STDERR ">>> $platform: archived to $arc";
  172 + return $arc;
  173 +}
  174 +
  175 +sub archive_7z {
  176 + my ($platform) = @_;
  177 +
  178 + my $base = filename_base($platform);
  179 + my $out = OUT_DIR."/$base.7z";
  180 +
  181 + system "7za a $out $base";
  182 +
  183 + my $arc = "$base.7z";
  184 + say STDERR ">>> $platform: archived to $arc";
  185 + return $arc;
  186 +}
  187 +
  188 +sub upload {
  189 + my @files = @_;
  190 +
  191 + chdir OUT_DIR;
  192 +
  193 + say STDERR ">>> uploading ", join(' ', @files);
  194 + system join(' ', "scp", @files, sprintf(UPLOAD_PATH_FORMAT, $build_type));
  195 +}
  196 +
  197 +sub tweet {
  198 + my %archives = @_;
  199 +
  200 + if ($build_type ne "nightly") {
  201 + say STDERR ">>> not tweeting for $build_type build";
  202 + return;
  203 + }
  204 +
  205 + say STDERR ">>> tweeting";
  206 +
  207 + my $links = join '', map { sprintf " %s ".URL_FORMAT, $_, $archives{$_} } sort keys %archives;
  208 + system "ttytter -linelength=500 -status='new dev build available!$links #pioneerspacesim'";
  209 +}

0 comments on commit 748eeb9

Please sign in to comment.
Something went wrong with that request. Please try again.