-
Notifications
You must be signed in to change notification settings - Fork 2
/
buildgopackage
executable file
·226 lines (198 loc) · 5.44 KB
/
buildgopackage
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/bash
#+
# Use this script to compile a GO component in the context of a Mistify-OS build.
#-
source scripts/mistify-functions.sh
builddirdefault=$(get_build_default variantbuilddir build/base)
gopackagenamedefault=$(get_build_default gopackagename sample-subagent)
gopackagedirdefault=$(get_build_default gopackagedir `pwd`/subagents/$gopackagenamedefault)
usage () {
cat << EOF
Usage: $0 [options]
Use this script to build a GO based package in the context of a Mistify-OS
build without having to add the package to the Mistify-OS build itself.
The package is compiled using the same GO compiler used when Mistify-OS
was built. To do so the source is copied to a directory within the Mistify-OS
build tree and compiled there. The package must include a makefile which this
script uses to actually build. The makefile can then install the binaries
into the Mistify-OS root file system pointed to by the variable DESTDIR.
Mistify-OS root file system which can then be packaged into an initrd using
the buildmistify script.
NOTE: This script requires a completed build of Mistify-OS using buildmistify
and runs buildmistify to build the GO package.
Options:
==== Mistify-OS Build ====
--builddir <dir>
The Mistify-OS build in which to compile. This defaults to the most
recent build. This option is saved in the file:
$statedir/builddir
[builddir=$builddirdefault]
==== GO Package ====
--gopackagename <name>
The name to use when building the package in the buildroot environment.
This option is saved in the file:
$statedir/gopackagename
[gopackagename=$gopackagenamedefault]
--gopackagedir <dir>
Where the GO package resides. The package source is copied from here into
the build tree where other GO packages have been built. This option is
saved in the file:
$statedir/gopackagedir
[gopackagedir=$gopackagedirdefault]
==== other ====
--verbose
Verbose output from this script.
-l|--logfile <file>
Use this log file name instead of the generated log file name.
--viewlog
If the Buildroot make returns an error then view the log file.
--dryrun
Just showing what will happen with this script. Don't run the test.
--resetdefaults
Reset all options. They will return to the default values when this
script is restarted.
-h|--help
Display this usage.
==== Build Options ====
Any options following "--" on the commnand line are passed to the
buildmistify script.
NOTE: This script maintains state in:
$statedir.
NOTE: Currently this script can only be run against an existing build.
EOF
}
#+
# Handle the command line options.
#-
a=`getopt -l "\
builddir:,\
gopackagename:,\
gopackagedir:,\
logfile:,\
viewlog,\
verbose,\
dryrun,\
resetdefaults,\
alwaysok,\
help" \
-o "l:h" -- "$@"`
if [ $? -gt 0 ]; then
usage
exit 1
fi
eval set -- $a
while [ $# -ge 1 ]; do
case "$1" in
--)
shift
options=$*
break
;;
--builddir)
builddir=$2
shift
;;
--gopackagename)
gopackagename=$2
shift
;;
--gopackagedir)
gopackagedir=$2
shift
;;
--logfile)
logfile=$2
shift
;;
--viewlog)
viewlog=y
;;
--verbose)
verbose=y
;;
--dryrun)
dryrun=echo
;;
--resetdefaults)
resetdefaults=y
;;
-h|--help)
usage
exit 0
;;
# using getopt should avoid needing this catchall but just in case...
*)
error "Invalid option: $1"
usage
exit 1
;;
esac
shift
done
if [ -n "$resetdefaults" ]; then
reset_build_default gopackagename
reset_build_default gopackagedir
fi
if [ -z "$gopackagename" ]; then
gopackagename=$gopackagenamedefault
fi
if [ -z "$gopackagedir" ]; then
gopackagedir=$gopackagedirdefault
fi
if [ -z "$builddir" ]; then
if [ -f $testmistifystatedir/builddir ]; then
builddir=`cat $testmistifystatedir/builddir`
else
if [ -d "$builddirdefault" ]; then
builddir=$builddirdefault
fi
fi
fi
if [ -d "$builddir" ]; then
message "Building $gopackagename using build in $builddir"
else
die "The build directory $builddir does not exist."
fi
if [ -n "$logfile" ]; then
params+=" --logfile $logfile"
fi
if [ -n "$options" ]; then
params+=" $options"
fi
# Uncomment this if buildmistify itself should not run. Normally, this is
# not necessary because of the DRYRUN environment variable which is passed
# to the gopackage makefile.
# if [ -n "$dryrun" ]; then
# params+=" --dryrun"
# fi
if [ -n "$verbose" ]; then
params+=" --verbose"
fi
message "The buildmistify options are: $params"
#+
# Run the package build makefile.
#-
export GOPACKAGENAME=$gopackagename
verbose GOPACKAGENAME: $GOPACKAGENAME
export GOPACKAGEDIR=$gopackagedir
verbose GOPACKAGEDIR: $GOPACKAGEDIR
export DRYRUN=$dryrun
verbose DRYRUN: $DRYRUN
#+
# Force a new copy of the source every time which avoids strange dependency
# trees.
#-
./buildmistify $params gopackage-dirclean
./buildmistify $params gopackage
if [ $? == 0 ]; then
set_build_default gopackagename $gopackagename
set_build_default gopackagedir $gopackagedir
verbose Defaults saved.
else
warning The buildmistify script returned an error. Options have not been saved.
fi
if [ -n "$viewlog" ]; then
less $logfile
fi
message GO package build complete.
tip "To create a new rootfs image (initrd) run buildmistify one more time."