-
Notifications
You must be signed in to change notification settings - Fork 63
/
pack_options.go
170 lines (145 loc) · 4.88 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
// 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
initrd string
kconfig bool
kernelLibraryIntermediateObjects bool
kernelLibraryObjects bool
kernelSourceFiles bool
kernelVersion 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
}
// 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
}
// 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
}
// 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
}
}
// 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
}
}