|
| 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 | +} |
0 commit comments