-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild
More file actions
204 lines (170 loc) · 6.74 KB
/
build
File metadata and controls
204 lines (170 loc) · 6.74 KB
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
#!/usr/bin/env python
"""
globifest/build - globifest Command Line Utility
This script allows command-line execution of the Builder.
Copyright 2018, Daniel Kristensen, Garmin Ltd, or its subsidiaries.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
import argparse
import os
import sys
from GlobifestLib import Builder, Log, ManifestParser, Util
def build_prebuild(_arg, metadata):
"""
Callback prior to iterating over packages
Preconditions guaranteed by Builder:
1. Metadata contains:
* prj_dir - Absolute path to project file
* out_dir - Absolute path to output directory
* settings - Merged (effective) settings for the project
2. Output directory exists
"""
# No need to makedirs first, metadata.out_dir will be created automatically
settings_out_file = Util.get_abs_path("settings.lst", metadata.out_dir)
Log.I("Writing settings to {}".format(settings_out_file))
with open(settings_out_file, mode="wt") as f:
metadata.settings.write_sorted(f)
def build_postprocess(_arg, metadata):
"""
Callback after processing manifests
Preconditions guaranteed by Builder:
1. The prebuild step has been run
2. Packages have been parsed
3. Metadata now also contains
* pub_includes - Include directories accessible to all packages
* pub_defines - Definitions accessible to all packages
"""
Log.I("Public entries:")
for k in ManifestParser.PUBLIC_LABELS:
out_file = Util.get_abs_path("{}.lst".format(k), metadata.out_dir)
Log.I(" {}: {}".format(k, out_file))
with open(out_file, mode="wt") as f:
for e in sorted(metadata[k]):
f.write("{}\n".format(e))
def build_target(_arg, metadata, name, tables):
"""
Callback when a target is processed
Preconditions guaranteed by Builder:
1. The postprocess step has been run
2. Package name is the base file name relative to the project file.
3. tables contains data specific to this target:
* prv_includes - Include directories accessible to files in this package
* prv_defines - Definitions accessible to files in this package
* sources - Source files for this package
* aux_files - Auxiliary files associated with this package
"""
Log.I("Target {} entries:".format(name))
for k, v in tables:
out_file = Util.get_abs_path("{}.{}.lst".format(name, k), metadata.out_dir)
Log.I(" {}: {}".format(k, out_file))
# makedirs in case the manifest is several folders down
os.makedirs(os.path.dirname(out_file), exist_ok=True)
with open(out_file, mode="wt") as f:
for e in sorted(v):
f.write("{}\n".format(e))
def parse_args():
"""Parse command-line arguments and return the results"""
parser = argparse.ArgumentParser(
description="Globifest Builder",
prefix_chars="-/",
fromfile_prefix_chars="@"
)
# Additional help options; but no need to clutter up the help text
parser.add_argument(
"-?", "/?",
help=argparse.SUPPRESS,
action="help"
)
parser.add_argument(
"-i",
help="Package file to parse",
action="store",
dest="in_fname",
type=str,
metavar="filename",
required=True
)
parser.add_argument(
"-o",
help="Where to save output",
action="store",
dest="out_dir",
type=str,
metavar="directory",
required=True
)
parser.add_argument(
"-v",
help="Logging verbosity (combine for higher levels, up to 2 times; default=0)",
action="count",
default=0,
dest="verbose"
)
parser.add_argument(
"config",
help="Configuration of each layer (ex: os=windows)",
action="append",
nargs="*"
)
# Print help if no arguments passed
arg_list = sys.argv[1:]
if not arg_list:
parser.print_help()
sys.exit(1)
return parser.parse_args(args=arg_list)
def run_cmd():
"""
Run the command line utility
@return 0 if build was successful, or error code otherwise
@returntype int
"""
ret = 0
# Parse arguments and set verbosity level
args = parse_args()
Log.Logger.set_level(args.verbose + 1)
try:
Log.D("In: {}".format(args.in_fname))
Log.D("Out: {}".format(args.out_dir))
Log.D("Config:")
for c in args.config:
Log.D(" {}".format(c))
# Set up callbacks for Builder
callbacks = Util.Container(
prebuild=build_prebuild,
target=build_target
)
Builder.build_project(
args.in_fname,
args.out_dir,
# The config argument is unnamed, but argparse still makes a 2D list out of it.
# Since it consumes all remaining arguments, they will all be in the first element.
args.config[0],
callbacks
)
except Log.GlobifestException as e:
# The logger prints these already, no need to print again
print("FAILED")
ret = e.get_type()
return ret
if __name__ == "__main__":
exit(run_cmd())