-
Notifications
You must be signed in to change notification settings - Fork 64
/
pack_options.go
209 lines (178 loc) · 5.9 KB
/
pack_options.go
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
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file except in compliance with the License.
package packmanager
// PackOptions contains the list of options which can be set when packaging a
// component.
type PackOptions struct {
appSourceFiles bool
args []string
env []string
initrd string
kconfig bool
kernelDbg bool
kernelLibraryIntermediateObjects bool
kernelLibraryObjects bool
kernelSourceFiles bool
kernelVersion string
labels map[string]string
name string
output string
mergeStrategy MergeStrategy
}
// NewPackOptions returns an instantiated *NewPackOptions with default
// configuration options values.
func NewPackOptions() *PackOptions {
return &PackOptions{
mergeStrategy: StrategyExit,
}
}
// PackAppSourceFiles returns whether the application source files should be
// packaged.
func (popts *PackOptions) PackAppSourceFiles() bool {
return popts.appSourceFiles
}
// Args returns the arguments to pass to the kernel.
func (popts *PackOptions) Args() []string {
return popts.args
}
// Env returns the environment variables to be passed to the kernel.
func (popts *PackOptions) Env() []string {
return popts.env
}
// Initrd returns the path of the initrd file that should be packaged.
func (popts *PackOptions) Initrd() string {
return popts.initrd
}
// PackKConfig returns whether the .config file should be packaged.
func (popts *PackOptions) PackKConfig() bool {
return popts.kconfig
}
// PackKernelDbg returns return whether to package the debug kernel.
func (popts *PackOptions) KernelDbg() bool {
return popts.kernelDbg
}
// PackKernelLibraryIntermediateObjects returns whether to package intermediate
// kernel library object files.
func (popts *PackOptions) PackKernelLibraryIntermediateObjects() bool {
return popts.kernelLibraryIntermediateObjects
}
// PackKernelLibraryObjects returns whether to package kernel library objects.
func (popts *PackOptions) PackKernelLibraryObjects() bool {
return popts.kernelLibraryObjects
}
// PackKernelSourceFiles returns the whether to package kernel source files.
func (popts *PackOptions) PackKernelSourceFiles() bool {
return popts.kernelSourceFiles
}
// KernelVersion returns the version of the kernel
func (popts *PackOptions) KernelVersion() string {
return popts.kernelVersion
}
// Name returns the name of the package.
func (popts *PackOptions) Name() string {
return popts.name
}
// Output returns the location of the package.
func (popts *PackOptions) Output() string {
return popts.output
}
// Labels returns the labels to be added to the package.
func (popts *PackOptions) Labels() map[string]string {
return popts.labels
}
// MergeStrategy ...
func (popts *PackOptions) MergeStrategy() MergeStrategy {
return popts.mergeStrategy
}
// PackOption is an option function which is used to modify PackOptions.
type PackOption func(*PackOptions)
// PackAppSourceFiles marks to include application source files
func PackAppSourceFiles(pack bool) PackOption {
return func(popts *PackOptions) {
popts.appSourceFiles = pack
}
}
// PackArgs sets the arguments to be passed to the application.
func PackArgs(args ...string) PackOption {
return func(popts *PackOptions) {
popts.args = args
}
}
// PackKConfig marks to include the kconfig `.config` file into the package.
func PackKConfig(kconfig bool) PackOption {
return func(popts *PackOptions) {
popts.kconfig = kconfig
}
}
// PackInitrd includes the provided path to an initrd file in the package.
func PackInitrd(initrd string) PackOption {
return func(popts *PackOptions) {
popts.initrd = initrd
}
}
// PackKernelDbg includes the debug kernel in the package.
func PackKernelDbg(dbg bool) PackOption {
return func(popts *PackOptions) {
popts.kernelDbg = dbg
}
}
// PackKernelLibraryIntermediateObjects marks to include intermediate library
// object files, e.g. libnolibc/errno.o
func PackKernelLibraryIntermediateObjects(pack bool) PackOption {
return func(popts *PackOptions) {
popts.kernelSourceFiles = pack
}
}
// PackKernelLibraryObjects marks to include library object files, e.g. nolibc.o
func PackKernelLibraryObjects(pack bool) PackOption {
return func(popts *PackOptions) {
popts.kernelSourceFiles = pack
}
}
// PackKernelSourceFiles marks that all source files which make up the build
// from the Unikraft build side are to be included. Including these files will
// enable a reproducible build.
func PackKernelSourceFiles(pack bool) PackOption {
return func(popts *PackOptions) {
popts.kernelSourceFiles = pack
}
}
// PackWithKernelVersion sets the version of the Unikraft core.
func PackWithKernelVersion(version string) PackOption {
return func(popts *PackOptions) {
popts.kernelVersion = version
}
}
// PackName sets the name of the package.
func PackName(name string) PackOption {
return func(popts *PackOptions) {
popts.name = name
}
}
// PackOutput sets the location of the output artifact package.
func PackOutput(output string) PackOption {
return func(popts *PackOptions) {
popts.output = output
}
}
// PackMergeStrategy sets the mechanism to use when an existing package of the
// same name exists.
func PackMergeStrategy(strategy MergeStrategy) PackOption {
return func(popts *PackOptions) {
popts.mergeStrategy = strategy
}
}
// PackWithEnv adds the environment variables to the package.
func PackWithEnvs(envs []string) PackOption {
return func(popts *PackOptions) {
popts.env = envs
}
}
// PackLabels adds the labels to the package.
func PackLabels(labels map[string]string) PackOption {
return func(popts *PackOptions) {
popts.labels = labels
}
}