File: distscript.pl

package info (click to toggle)
mpich 4.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 423,384 kB
  • sloc: ansic: 1,088,434; cpp: 71,364; javascript: 40,763; f90: 22,829; sh: 17,463; perl: 14,773; xml: 14,418; python: 10,265; makefile: 9,246; fortran: 8,008; java: 4,355; asm: 324; ruby: 176; lisp: 19; php: 8; sed: 4
file content (111 lines) | stat: -rwxr-xr-x 3,357 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env perl

use strict;
use warnings;

use POSIX qw(strftime);

my $builddir = shift(@ARGV);
my $version = shift(@ARGV);

# Sanity check
die "Must specify builddir, version"
    if (!defined($builddir) || !$builddir || ! -d $builddir ||
        !defined($version) || !$version);

my $today = strftime "%Y-%m-%d", localtime;

#------------------------------------------------------------------------------
# Helper function to re-write files
#------------------------------------------------------------------------------

sub subst {
    my $file = shift;

    my $orig;
    open(IN, $file) || die "Can't read $file: $!";
    $orig .= $_
        while (<IN>);
    close(IN);

    my $copy = $orig;
    $copy =~ s/#VERSION#/Libfabric v$version/g;
    $copy =~ s/#DATE#/$today/g;

    if ($copy ne $orig) {
        print "*** VERSION/DATE-ifying $file...\n";
        open(OUT, ">$file") || die "Can't write to $file: $!";
        print OUT $copy;
        close(OUT);
    }
}

###############################################################################
# Check to see that the source tree is clean / has no local changes
###############################################################################

if (-d ".git") {
    open(GIT_STATUS, "git status --porcelain|") ||
        die "Can't run git status to verify that the source tree is clean";
    my $clean = 1;

    # Allow the caller to specify a list of dirty files that can be
    # skipped in this git cleanliness check.  The nightly tarball
    # script uses this mechanism (because it needs to modify the
    # version in configure.ac).  Others may use this mechanism, too --
    # it allows them the safety of checking that the *rest* of their
    # tree is git clean (e.g., perhaps they have modified
    # libfabric.spec.in with a local release number).
    my @dirty_files;
    @dirty_files = split(/\s+/, $ENV{'LIBFABRIC_DISTSCRIPT_DIRTY_FILES'})
        if (exists($ENV{'LIBFABRIC_DISTSCRIPT_DIRTY_FILES'}));

    while (<GIT_STATUS>) {
        chomp;
        if ($_ =~ m/^([^?! ].|.[^?! ]) (.+)$/) {
            my $file = $2;
            print "*** WARNING: found modified file in source tree: $file\n";

            my $found = 0;
            foreach my $dirty_file (@dirty_files) {
                if ($file eq $dirty_file) {
                    print "*** ...but an environment variable override says that this is ok!\n";
                    $found = 1;
                    last;
                }
            }

            $clean = 0
                if (!$found);
        }
    }
    close(GIT_STATUS);
    if (!$clean) {
        print "*** WARNING: Source tree is not clean.\n";
        die "Refusing to make tarball";
    }
}

###############################################################################
# Change into the new distribution tree
###############################################################################

chdir($builddir);
subst("README");

chdir("man");
opendir(my $dh, ".") || die "Can't open man directory: $!";
my @subdirs = grep { /man\d+/ && -d "./$_" } readdir($dh);
closedir $dh;

foreach my $dir (@subdirs) {
    opendir(my $dh, $dir) || die "Can't open man/$dir directory: $!";
    my @files = grep { /\.\d$/ && -f "$dir/$_" } readdir($dh);
    closedir $dh;

    foreach my $file (@files) {
        subst("$dir/$file");
    }
}

exit(0);