Skip to content

Commit 201352b

Browse files
committed
sync-nv-rpms: Fix copyright year and extract awk into standalone file
Fix the copyright header year (2025 -> 2026) and extract the inline awk script into hack/sync-nv-rpms-update-workspace.awk with comments to help maintainers understand the WORKSPACE update logic. Assisted-By: Claude <noreply@anthropic.com> Signed-off-by: Lee Yarwood <lyarwood@redhat.com>
1 parent b83632f commit 201352b

2 files changed

Lines changed: 165 additions & 86 deletions

File tree

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#
2+
# This file is part of the KubeVirt project
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
# Copyright 2026 Red Hat, Inc.
17+
#
18+
# sync-nv-rpms-update-workspace.awk
19+
#
20+
# Called by hack/sync-nv-rpms.sh to update the WORKSPACE file in a single
21+
# pass. It performs two operations:
22+
#
23+
# 1. Remove existing el10nv rpm() blocks for the sub-packages we manage.
24+
# 2. Insert new el10nv rpm() blocks immediately after the last el10 entry
25+
# for each sub-package.
26+
#
27+
# Required variables (passed via -v):
28+
#
29+
# insert_map_file - Path to a file mapping bazel names to insertion
30+
# content files. Each line has the format:
31+
# <last_el10_name>|<path_to_insertion_file>
32+
# When we finish printing the rpm() block whose name
33+
# matches <last_el10_name>, we append the contents of
34+
# the corresponding insertion file.
35+
#
36+
# subpkg_list_file - Path to a file listing the sub-package prefixes we
37+
# manage (one per line, e.g. "libvirt-libs"). Any
38+
# existing rpm() block whose name starts with one of
39+
# these prefixes and contains ".el10nv." is considered
40+
# stale and is removed.
41+
#
42+
43+
# ---------------------------------------------------------------------------
44+
# Initialisation: load the insertion map and sub-package list into memory.
45+
# ---------------------------------------------------------------------------
46+
BEGIN {
47+
# Build insert_after[name] = filepath from the map file.
48+
while ((getline line < insert_map_file) > 0) {
49+
idx = index(line, "|")
50+
if (idx > 0) {
51+
iname = substr(line, 1, idx - 1)
52+
ifile = substr(line, idx + 1)
53+
insert_after[iname] = ifile
54+
}
55+
}
56+
close(insert_map_file)
57+
58+
# Load sub-package prefixes into the sp[] array.
59+
n_sp = 0
60+
while ((getline line < subpkg_list_file) > 0) {
61+
sp[++n_sp] = line
62+
}
63+
close(subpkg_list_file)
64+
65+
in_block = 0
66+
out_n = 0
67+
}
68+
69+
# ---------------------------------------------------------------------------
70+
# Helper: buffer a line for output.
71+
# ---------------------------------------------------------------------------
72+
function buf(line) { out[++out_n] = line }
73+
74+
# ---------------------------------------------------------------------------
75+
# Helper: read all lines from fpath and buffer them.
76+
# ---------------------------------------------------------------------------
77+
function insert_from_file(fpath, l) {
78+
while ((getline l < fpath) > 0) buf(l)
79+
close(fpath)
80+
}
81+
82+
# ---------------------------------------------------------------------------
83+
# Detect the start of an rpm() block and begin accumulating its lines.
84+
# We need to collect the entire block before deciding whether to keep,
85+
# remove, or augment it.
86+
# ---------------------------------------------------------------------------
87+
/^rpm\(/ {
88+
in_block = 1
89+
delete blk
90+
blk_n = 0
91+
blk[++blk_n] = $0
92+
next
93+
}
94+
95+
# ---------------------------------------------------------------------------
96+
# Accumulate lines inside an rpm() block until we hit the closing ")".
97+
# Once the block is complete we:
98+
# - Extract the "name" field.
99+
# - Decide whether this block should be removed (skip=1) because it is an
100+
# el10nv entry for a sub-package we manage.
101+
# - If kept, buffer the block and optionally append new entries after it.
102+
# ---------------------------------------------------------------------------
103+
in_block {
104+
blk[++blk_n] = $0
105+
if ($0 == ")") {
106+
in_block = 0
107+
108+
# Extract the name = "..." value from the block.
109+
name = ""
110+
for (i = 1; i <= blk_n; i++) {
111+
if (blk[i] ~ /name = "/) {
112+
name = blk[i]
113+
sub(/.*name = "/, "", name)
114+
sub(/".*/, "", name)
115+
break
116+
}
117+
}
118+
119+
# Check whether this el10nv block belongs to a managed sub-package.
120+
skip = 0
121+
if (name ~ /\.el10nv\./) {
122+
for (i = 1; i <= n_sp; i++) {
123+
pat = "^" sp[i] "-[0-9]"
124+
if (name ~ pat) {
125+
skip = 1
126+
break
127+
}
128+
}
129+
}
130+
131+
if (skip) {
132+
# Drop the stale el10nv block and any trailing blank line that
133+
# preceded it in the output buffer.
134+
if (out_n > 0 && out[out_n] == "") out_n--
135+
} else {
136+
# Keep this block.
137+
for (i = 1; i <= blk_n; i++) buf(blk[i])
138+
139+
# If this is the anchor block (last el10 entry for a
140+
# sub-package), insert the new el10nv entries after it.
141+
if (name in insert_after) {
142+
insert_from_file(insert_after[name])
143+
}
144+
}
145+
}
146+
next
147+
}
148+
149+
# ---------------------------------------------------------------------------
150+
# Lines outside any rpm() block are passed through unchanged.
151+
# ---------------------------------------------------------------------------
152+
{ buf($0) }
153+
154+
# ---------------------------------------------------------------------------
155+
# Flush the output buffer.
156+
# ---------------------------------------------------------------------------
157+
END {
158+
for (i = 1; i <= out_n; i++) print out[i]
159+
}

hack/sync-nv-rpms.sh

Lines changed: 6 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
#
17-
# Copyright 2025 Red Hat, Inc.
17+
# Copyright 2026 Red Hat, Inc.
1818
#
1919
# Syncs NV-variant RPMs (el10nv) for libvirt and qemu-kvm from the
2020
# CentOS Stream 10 internal koji build system into WORKSPACE and
@@ -294,92 +294,12 @@ done
294294
subpkg_list_file="${TMPDIR}/subpkg_list.txt"
295295
printf '%s\n' "${all_subpkg_names[@]}" >"${subpkg_list_file}"
296296

297-
# Single awk pass:
298-
# - Remove existing el10nv rpm() blocks for our sub-packages
299-
# - Insert new el10nv rpm() blocks after the last el10 entry for each sub-package
297+
# Single awk pass to remove stale el10nv blocks and insert new ones.
298+
# See hack/sync-nv-rpms-update-workspace.awk for details.
300299
awk -v insert_map_file="${insert_map_file}" \
301-
-v subpkg_list_file="${subpkg_list_file}" '
302-
BEGIN {
303-
while ((getline line < insert_map_file) > 0) {
304-
idx = index(line, "|")
305-
if (idx > 0) {
306-
iname = substr(line, 1, idx - 1)
307-
ifile = substr(line, idx + 1)
308-
insert_after[iname] = ifile
309-
}
310-
}
311-
close(insert_map_file)
312-
313-
n_sp = 0
314-
while ((getline line < subpkg_list_file) > 0) {
315-
sp[++n_sp] = line
316-
}
317-
close(subpkg_list_file)
318-
319-
in_block = 0
320-
out_n = 0
321-
}
322-
323-
function buf(line) { out[++out_n] = line }
324-
325-
function insert_from_file(fpath, l) {
326-
while ((getline l < fpath) > 0) buf(l)
327-
close(fpath)
328-
}
329-
330-
/^rpm\(/ {
331-
in_block = 1
332-
delete blk
333-
blk_n = 0
334-
blk[++blk_n] = $0
335-
next
336-
}
337-
338-
in_block {
339-
blk[++blk_n] = $0
340-
if ($0 == ")") {
341-
in_block = 0
342-
343-
name = ""
344-
for (i = 1; i <= blk_n; i++) {
345-
if (blk[i] ~ /name = "/) {
346-
name = blk[i]
347-
sub(/.*name = "/, "", name)
348-
sub(/".*/, "", name)
349-
break
350-
}
351-
}
352-
353-
skip = 0
354-
if (name ~ /\.el10nv\./) {
355-
for (i = 1; i <= n_sp; i++) {
356-
pat = "^" sp[i] "-[0-9]"
357-
if (name ~ pat) {
358-
skip = 1
359-
break
360-
}
361-
}
362-
}
363-
364-
if (skip) {
365-
if (out_n > 0 && out[out_n] == "") out_n--
366-
} else {
367-
for (i = 1; i <= blk_n; i++) buf(blk[i])
368-
369-
if (name in insert_after) {
370-
insert_from_file(insert_after[name])
371-
}
372-
}
373-
}
374-
next
375-
}
376-
377-
{ buf($0) }
378-
379-
END {
380-
for (i = 1; i <= out_n; i++) print out[i]
381-
}
382-
' "${WORKSPACE_FILE}" >"${TMPDIR}/WORKSPACE.new"
300+
-v subpkg_list_file="${subpkg_list_file}" \
301+
-f "${SCRIPT_DIR}/sync-nv-rpms-update-workspace.awk" \
302+
"${WORKSPACE_FILE}" >"${TMPDIR}/WORKSPACE.new"
383303

384304
workspace_entries=$(grep -c 'name = ".*el10nv' "${TMPDIR}/WORKSPACE.new" || true)
385305
mv "${TMPDIR}/WORKSPACE.new" "${WORKSPACE_FILE}"

0 commit comments

Comments
 (0)