@@ -33,6 +33,7 @@ shopt -s expand_aliases
33
33
gitTag=
34
34
outDir=" $PWD "
35
35
scubaGogglesGit=
' [email protected] :cisagov/ScubaGoggles.git'
36
+ zipSource=true
36
37
37
38
usage ()
38
39
{
@@ -45,9 +46,10 @@ usage()
45
46
printf ' defaults to %s\n' " $scubaGogglesGit "
46
47
printf ' -t <git-tag-or-branch>: checkout tag or branch for build\n'
47
48
printf ' defaults to top of main branch\n'
49
+ printf ' -x: omit the ZIP source distribution file\n'
48
50
}
49
51
50
- while getopts ' :ho:r:t:' option
52
+ while getopts ' :ho:r:t:x ' option
51
53
do
52
54
case " $option " in
53
55
h)
64
66
t)
65
67
gitTag=$OPTARG
66
68
;;
69
+ x)
70
+ zipSource=false
71
+ ;;
67
72
? )
68
73
usage
69
74
exit 1
@@ -78,14 +83,52 @@ shift $((OPTIND -1))
78
83
# Used to distinguish output from this script.
79
84
buildPfx=' {build>>>}'
80
85
81
- cleanup () {
86
+ cleanup ()
87
+ {
82
88
echo " $buildPfx Performing build cleanup..."
83
89
[[ $( type -t deactivate) == function ]] && deactivate
84
90
[[ " ${DIRSTACK[0]} " == " $scubaGoggles " ]] && popd
85
91
rm -r f " $scubaEnv "
86
92
rm -r f " $scubaGoggles "
87
93
}
88
94
95
+ generateSourceZip ()
96
+ {
97
+ # Generates a ZIP file version of the source code distribution, which is
98
+ # in gzipped tar format (.tar.gz). There are 2 parameters to this function:
99
+ #
100
+ # generateSourceZip <gz-tar-file> <out-var-name>
101
+ #
102
+ # where <gz-tar-file> is an existing source distribution (the file must
103
+ # end with ".tar.gz" (not ".tgz")), and <out-var-name> is the name of the
104
+ # variable where the output file name will be written. The ZIP source
105
+ # code file will be created in the same location as the given tar file.
106
+ #
107
+ # Python's PEP 517 has restricted the source distributions built by
108
+ # backends to be gzipped tar files only.
109
+ #
110
+ # This work is done in a temporary directory, which is removed provided
111
+ # that no errors occur during the creation of the ZIP file.
112
+
113
+ local gztarFile
114
+ local sourceTemp
115
+ local -n outFile=$2
116
+
117
+ gztarFile=$1
118
+ sourceTemp=$( mktemp -d -t scubagoggles_src.XXXXXXXXXX)
119
+ outFile=$( realpath " ${gztarFile/ tar.gz/ zip} " )
120
+
121
+ tar xfz " $gztarFile " -C " $sourceTemp "
122
+
123
+ pushd " $sourceTemp "
124
+
125
+ zip -qr " $outFile " .
126
+
127
+ popd
128
+
129
+ rm -rf " $sourceTemp "
130
+ }
131
+
89
132
pushd () { builtin pushd " $@ " > /dev/null; }
90
133
91
134
popd () { builtin popd > /dev/null; }
@@ -140,7 +183,16 @@ python -m build
140
183
wheelFile= $( realpath dist/scubagoggles-* .whl)
141
184
tarFile= $( realpath dist/scubagoggles-* .tar.gz)
142
185
143
- for file in " $wheelFile " " $tarFile "
186
+ packageFiles= (" $wheelFile " " $tarFile " )
187
+
188
+ if [ " $zipSource " == true ]
189
+ then
190
+ echo " $buildPfx Generating Source ZIP File..."
191
+ generateSourceZip " $tarFile " zipFile
192
+ packageFiles+=(" $zipFile " )
193
+ fi
194
+
195
+ for file in " ${packageFiles[@]} "
144
196
do
145
197
echo " $buildPfx Copying $file to $outDir "
146
198
cp " $file " " $outDir /$( basename " $file " ) "
0 commit comments