Skip to content

Commit 629a5b7

Browse files
committed
scripts: update UNRELEASED export map on release
To reduce the confusion where to put a new exported symbol, there is a new UNRELEASED section with all the unreleased symbols. On release, update the export map to the new release version and add back the UNRELEASED section. Signed-off-by: Daniel Wagner <[email protected]>
1 parent e33f756 commit 629a5b7

1 file changed

Lines changed: 105 additions & 0 deletions

File tree

scripts/release.sh

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,111 @@ if [ "$build_doc" = true ]; then
132132
git commit -s -m "doc: Regenerate all docs for $VERSION"
133133
fi
134134

135+
# update linker maps
136+
map_files=("src/libnvme.map" "src/libnvme-mi.map")
137+
lib_ver="LIBNVME_${ver//./_}"
138+
139+
for map_file in "${map_files[@]}"; do
140+
if [ ! -f "${map_file}" ]; then
141+
continue
142+
fi
143+
144+
# Check if LIBNVME_UNRELEASED has symbols
145+
if ! awk '
146+
$0 ~ /LIBNVME_UNRELEASED[[:space:]]*\{/ { in_section = 1; next }
147+
in_section && $0 ~ /\}/ { exit }
148+
in_section && $0 !~ /^[[:space:]]*($|\/|\/\*|\*|#)/ { found = 1; exit }
149+
END { exit !found }
150+
' "${map_file}"; then
151+
continue
152+
fi
153+
154+
awk -v old="LIBNVME_UNRELEASED" -v new="${lib_ver}" '
155+
BEGIN {
156+
in_unreleased = 0
157+
in_section = 0
158+
count = 0
159+
inserted = 0
160+
header_lines = 0
161+
}
162+
163+
function print_empty_unreleased() {
164+
return old " {\n\tglobal:\n};"
165+
}
166+
167+
function print_sorted_renamed() {
168+
section = new " {\n\tglobal:"
169+
n = asort(symbols, sorted)
170+
for (i = 1; i <= n; i++) {
171+
section = section "\n\t\t" sorted[i]
172+
}
173+
section = section "\n};"
174+
return section
175+
}
176+
177+
{
178+
lines[++line_count] = $0
179+
180+
# Header detection (lines starting with #)
181+
if (line_count == 1 || (header_lines && $0 ~ /^#/)) {
182+
header_lines++
183+
}
184+
185+
if (!in_unreleased && $0 ~ old "[[:space:]]*\\{") {
186+
in_unreleased = 1
187+
in_section = 1
188+
unreleased_start = line_count
189+
next
190+
}
191+
192+
if (in_unreleased && in_section) {
193+
if ($0 ~ /\}/) {
194+
unreleased_end = line_count
195+
in_section = 0
196+
in_unreleased = 2
197+
next
198+
}
199+
200+
if ($0 ~ /^[[:space:]]*[a-zA-Z0-9_]+;/) {
201+
sub(/^[[:space:]]*/, "", $0)
202+
symbols[++count] = $0
203+
}
204+
next
205+
}
206+
}
207+
208+
END {
209+
has_symbols = (count > 0)
210+
if (has_symbols) {
211+
renamed_section = print_sorted_renamed()
212+
}
213+
new_unreleased = print_empty_unreleased()
214+
215+
# First: print preserved header
216+
for (i = 1; i <= header_lines; i++) {
217+
print lines[i]
218+
}
219+
220+
# Then: insert the new unreleased block
221+
print new_unreleased
222+
223+
for (i = header_lines + 1; i <= line_count; i++) {
224+
if (i == unreleased_start) {
225+
i = unreleased_end
226+
if (has_symbols) {
227+
print renamed_section
228+
}
229+
continue
230+
}
231+
print lines[i]
232+
}
233+
}
234+
' "${map_file}" > "${map_file}.tmp" && mv "${map_file}.tmp" "${map_file}"
235+
236+
git add "${map_file}"
237+
echo "${map_file} updated."
238+
done
239+
135240
# update meson.build
136241
sed -i -e "0,/[ \t]version: /s/\([ \t]version: \).*/\1\'$ver\',/" meson.build
137242
if [[ -n "$libnvme_VERSION" ]] && [[ -f subprojects/libnvme.wrap ]]; then

0 commit comments

Comments
 (0)