forked from usnistgov/oar-pdr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makedist.python
executable file
·164 lines (148 loc) · 4.37 KB
/
makedist.python
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#! /bin/bash
#
# makedist.python: build the package's python-based distributions
#
# This script is designed to run without any arguments: this will build
# all of the python distributions. Restricting the build to specific
# distributions can be done by listing the names of the desired distributions
# on the command line.
#
# There is currently only one python distribution: pdr-publish
#
# SYNOPSIS
# makedist.python [OPTIONS] [DISTNAME ...]
#
# OPTIONS
# -l, --list list the names of the supported distributions and
# exit without building.
# --dist-dir=DIR The output directory to write the distribution
# products into.
# -d DIR, --source-dir=DIR the directory containing the python source code
# (default: ./python)
# -c DIR, --cache-dir=DIR directory for holding intermediate or cache-able
# products (currently not used); this can be shared
# with other similar packages to avoid redundant
# re-building.
# -v VER, --version=VER assign VER as the VERSION for this product
#
set -e
prog=`basename $0`
execdir=`dirname $0`
[ "$execdir" = "" -o "$execdir" = "." ] && execdir=$PWD
# this is needed because realpath is not on macs
function realpath {
if [ -d "$1" ]; then
(cd $1 && pwd)
elif [ -f "$1" ]; then
file=`basename $1`
parent=`dirname $1`
realdir=`(cd $parent && pwd)`
echo "$realdir/$file"
elif [[ $1 = /* ]]; then
echo $1
else
echo "$PWD/${1#./}"
fi
}
execdir=`realpath $execdir`
PACKAGE_DIR=`dirname $execdir`
SOURCE_DIR=$PACKAGE_DIR/python
VERSION=
# Update this list with the names of the individual component names
#
DISTNAMES=(pdr-publish)
# handle command line options
while [ "$1" != "" ]; do
case "$1" in
--list|-l)
echo "Available distributions: $DISTNAMES"
exit 0
;;
--dist-dir=*)
DIST_DIR=`echo $1 | sed -e 's/[^=]*=//'`
;;
--dist-dir)
shift
DIST_DIR=$1
;;
--source-dir=*|--dir=*)
SOURCE_DIR=`echo $1 | sed -e 's/[^=]*=//'`
;;
-d|--dir|--source-dir)
shift
SOURCE_DIR=$1
;;
--cache-dir=*)
CACHE_DIR=`echo $1 | sed -e 's/[^=]*=//'`
# NOTE: CACHE_DIR is ignored
;;
-c|--cache-dir)
shift
CACHE_DIR=$1
# NOTE: CACHE_DIR is ignored
;;
-v|--version)
shift
VERSION=$1
;;
--version=*)
VERSION=`echo $1 | sed -e 's/[^=]*=//'`
;;
-*)
echo "$prog: unsupported option:" $1
false
;;
pdr-publish)
# assuming just one distribution
true
;;
*)
echo "${prog}: ${1}: unrecognized distribution name"
false
;;
esac
shift
done
true ${DIST_DIR:=$PACKAGE_DIR/dist}
BUILD_DIR=$SOURCE_DIR/dist
mkdir -p $BUILD_DIR $DIST_DIR
# set the current version. This will inject the version into the code, if
# needed.
#
(cd oar-metadata; scripts/setversion.sh)
# don't reset the version unnecessarily as it may have been done by makedist
#
[ -z "$VERSION" -a -f "$PACKAGE_DIR/VERSION" ] || {
echo '+' scripts/setversion.sh $VERSION
scripts/setversion.sh $VERSION
}
[ -n "$PACKAGE_NAME" ] || PACKAGE_NAME=`cat $PACKAGE_DIR/VERSION | awk '{print $1}'`
version=$VERSION
[ -n "$version" ] || version=`cat $PACKAGE_DIR/VERSION | awk '{print $2}'`
vers4fn=`echo $version | perl -pe 's#[/ \t]+#_#g'`
echo '#########################'
echo '#'
echo "# Building ${DISTNAMES[0]}"...
echo '#'
echo '#########################'
# build the components
installdir=$BUILD_DIR/pdr
set -x
mkdir -p $installdir
scripts/install.sh --install-dir=$installdir
# ENTER COMMANDS for creating the dependency file(s)
#
# A dependency file should be called DISTNAME-${version}_dep.json
mkdir -p $DIST_DIR
if [ -n "$PYTHONPATH" ]; then
export PYTHONPATH=$installdir/lib/python:$PYTHONPATH
else
export PYTHONPATH=$installdir/lib/python
fi
$execdir/record_python_deps.py ${DISTNAMES[0]} $version \
> $DIST_DIR/${DISTNAMES[0]}-${vers4fn}_dep.json
# Bundle the distribution
(cd $BUILD_DIR && zip -qr $DIST_DIR/${DISTNAMES[0]}-${vers4fn}.zip pdr)
set +x
echo Created distribution in dist directory:
echo ${DISTNAMES[0]}-${vers4fn}.zip