public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/swift-lang] rawhide: update-swift-version.sh: preserve source indexes and add exclusions
@ 2026-10-19 10:27 Link Dupont
0 siblings, 0 replies; only message in thread
From: Link Dupont @ 2026-10-19 10:27 UTC (permalink / raw)
To: git-commits
A new commit has been pushed.
Repo : rpms/swift-lang
Branch : rawhide
Commit : 4fdac4835aeea26ff453ec7f60920bf200c7a2dc
Author : Link Dupont <link@sub-pop.net>
Date : 2026-10-02T13:22:51-04:00
Stats : +138/-43 in 2 file(s)
URL : https://src.fedoraproject.org/rpms/swift-lang/c/4fdac4835aeea26ff453ec7f60920bf200c7a2dc?branch=rawhide
Log:
update-swift-version.sh: preserve source indexes and add exclusions
- Preserve source indexes: parse existing %global subdirN lines and reuse
their numbers when updating. New projects are appended at max(N)+1.
- Add EXCLUDED_CHECKOUTS list to skip sources that come from the system (cmake and ninja)
- Various compatibility and bug fixes
[skip changelog]
---
diff --git a/README.md b/README.md
index 1cfec91..2c9f094 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
## update-swift-version.sh
-A script to update the Swift language package to a new version by automatically downloading the official Swift configuration and updating the RPM spec file.
+A script to update the Swift language package to a new version by automatically downloading the official Swift configuration and updating the RPM spec file while preserving source numbering.
### Usage
@@ -13,15 +13,22 @@ A script to update the Swift language package to a new version by automatically
### Example
```bash
-./update-swift-version.sh 6.1.3
+./update-swift-version.sh 6.4.0
```
### What it does
1. Downloads the Swift release configuration from the official Swift repository
-2. Parses the repository versions for all Swift components
-3. Updates the `swift-lang.spec` file with new source URLs and version information
-4. Removes old forge sources and adds new ones based on the Swift release configuration
+2. Determines the correct release scheme (tries `release/<version>`, `release/<major.minor>.x`, then `release/<major.minor>`)
+3. Parses the repository versions for all Swift components
+4. Preserves existing source indexes: projects that are already in the spec keep their `SourceN` number
+5. Excludes checkouts we don't package: for example, `cmake` and `ninja` are excluded (we use system versions)
+6. Appends new projects at the next available index
+7. Updates the `%global forgeurlN`, `%global tagN` entries for changed versions
+8. Updates the Lua loop bounds to match the highest source index
+9. Updates the package version number
+
+The script is idempotent: running it multiple times on the same version produces identical results.
### Requirements
@@ -31,4 +38,7 @@ A script to update the Swift language package to a new version by automatically
### After running
-Review the changes to `swift-lang.spec` and remove any patches that are no longer needed for the new version.
+1. Review the changes to `swift-lang.spec`
+2. Update patches if needed for the new version
+3. Run `spectool -g swift-lang.spec` to download new source tarballs
+4. Run `fedpkg new-sources <tarballs>` to upload them to the lookaside cache
diff --git a/update-swift-version.sh b/update-swift-version.sh
index 5fe95d8..4419543 100755
--- a/update-swift-version.sh
+++ b/update-swift-version.sh
@@ -1,15 +1,15 @@
-#!/bin/bash
+#!/usr/bin/env bash
set -e
-SWIFT_VERSION="${1:-}"
-# Only shorten the version if it contains two dots.
-if [[ "${SWIFT_VERSION}" =~ \.\. ]]; then
- SHORT_SWIFT_VERSION="${SWIFT_VERSION%.*}"
-else
- SHORT_SWIFT_VERSION="${SWIFT_VERSION}"
+# Require bash 4+ for associative arrays
+if [ "${BASH_VERSINFO[0]}" -lt 4 ]; then
+ echo "Error: This script requires bash 4 or later (found bash ${BASH_VERSION})"
+ exit 1
fi
+SWIFT_VERSION="${1:-}"
+
if [[ -z "$SWIFT_VERSION" ]]; then
echo "Usage: $0 <swift-version>"
echo "Example: $0 6.1.3"
@@ -21,6 +21,9 @@ TAG="swift-${SWIFT_VERSION}-RELEASE"
CONFIG_URL="https://raw.githubusercontent.com/swiftlang/swift/${TAG}/utils/update_checkout/update-checkout-config.json"
TEMP_CONFIG=$(mktemp)
+# Checkouts we deliberately don't package (use system versions or not needed for Fedora)
+EXCLUDED_CHECKOUTS="cmake ninja"
+
echo "Downloading Swift $SWIFT_VERSION configuration..."
if ! curl -sSL "$CONFIG_URL" -o "$TEMP_CONFIG"; then
echo "Error: Failed to download configuration for Swift $SWIFT_VERSION"
@@ -35,54 +38,136 @@ if ! jq . "$TEMP_CONFIG" >/dev/null 2>&1; then
exit 1
fi
+echo "Determining release scheme..."
+# Try exact version scheme first (e.g., release/6.4.0), then .x variant (release/6.4.x),
+# then major.minor (release/6.4)
+RELEASE_SCHEME="release/${SWIFT_VERSION}"
+if ! jq -e --arg scheme "$RELEASE_SCHEME" '."branch-schemes"[$scheme]' "$TEMP_CONFIG" >/dev/null 2>&1; then
+ MAJOR_MINOR="${SWIFT_VERSION%.*}"
+ RELEASE_SCHEME="release/${MAJOR_MINOR}.x"
+ if ! jq -e --arg scheme "$RELEASE_SCHEME" '."branch-schemes"[$scheme]' "$TEMP_CONFIG" >/dev/null 2>&1; then
+ RELEASE_SCHEME="release/${MAJOR_MINOR}"
+ fi
+fi
+
+if ! jq -e --arg scheme "$RELEASE_SCHEME" '."branch-schemes"[$scheme]' "$TEMP_CONFIG" >/dev/null 2>&1; then
+ echo "Error: No release scheme found for Swift $SWIFT_VERSION"
+ echo "Tried: release/${SWIFT_VERSION}, release/${MAJOR_MINOR}.x, release/${MAJOR_MINOR}"
+ rm -f "$TEMP_CONFIG"
+ exit 1
+fi
+
+echo "Using release scheme: $RELEASE_SCHEME"
echo "Parsing repository versions..."
# Collect all the projects included in the desired branch scheme
-PROJECTS=$(jq -r --arg scheme "release/${SHORT_SWIFT_VERSION}" '.["branch-schemes"][$scheme]["repos"]|keys[]' "${TEMP_CONFIG}")
+PROJECTS=$(jq -r --arg scheme "$RELEASE_SCHEME" '.["branch-schemes"][$scheme]["repos"]|keys[]' "${TEMP_CONFIG}" | sort)
+
+# Build a map of project name -> existing source index by parsing the spec
+declare -A PROJECT_INDEX
+while IFS= read -r line; do
+ if [[ "$line" =~ ^%global\ subdir([0-9]+)\ +(.+)$ ]]; then
+ idx="${BASH_REMATCH[1]}"
+ name="${BASH_REMATCH[2]}"
+ PROJECT_INDEX["$name"]="$idx"
+ fi
+done < "$SPEC_FILE"
-# Associate each project with the ref used by the desired branch scheme
-declare -A PROJECT_REFS
-for PROJECT in ${PROJECTS}; do
- PROJECT_REF=$(jq -r --arg scheme "release/${SHORT_SWIFT_VERSION}" --arg project "$PROJECT" '.["branch-schemes"][$scheme]["repos"][$project]' "${TEMP_CONFIG}")
- PROJECT_REFS["${PROJECT}"]="${PROJECT_REF}"
+# Find the maximum existing index
+MAX_IDX=0
+for idx in "${PROJECT_INDEX[@]}"; do
+ if [ "$idx" -gt "$MAX_IDX" ]; then
+ MAX_IDX="$idx"
+ fi
done
-# Remove all existing sources between the lines "Begin forge sources" and "End forge sources"
-sed -i "/Begin forge sources/,/End forge sources/{//!d;}" "${SPEC_FILE}"
-
-IDX=1
-# Get each project's "ID" (Github repo org/proj URL fragment)
-for PROJECT in "${!PROJECT_REFS[@]}"; do
+# Process each project
+for PROJECT in $PROJECTS; do
if [ "${PROJECT}" == "swift" ]; then
continue
fi
- PROJECT_REF=${PROJECT_REFS[${PROJECT}]}
+ # Skip excluded checkouts
+ if echo "$EXCLUDED_CHECKOUTS" | grep -qw "$PROJECT"; then
+ echo "Excluding $PROJECT (not packaged for Fedora)"
+ # Remove from spec if it exists
+ if [ -n "${PROJECT_INDEX[$PROJECT]}" ]; then
+ idx="${PROJECT_INDEX[$PROJECT]}"
+ sed -i.bak "/^%global forgeurl${idx} /d; /^%global tag${idx} /d; /^%global subdir${idx} /d" "$SPEC_FILE"
+ fi
+ continue
+ fi
+
+ PROJECT_REF=$(jq -r --arg scheme "$RELEASE_SCHEME" --arg project "$PROJECT" '.["branch-schemes"][$scheme]["repos"][$project]' "${TEMP_CONFIG}")
PROJECT_ID=$(jq -r --arg project "${PROJECT}" '.["repos"][$project].remote.id' "${TEMP_CONFIG}")
FORGEURL="https://github.com/${PROJECT_ID}"
- PADDING=" "
- if [ "${IDX}" -lt 10 ]; then
- PADDING=" "
- fi
- if [ "${IDX}" -ge 100 ]; then
- PADDING=" "
- fi
-
+ # Normalize release branch refs to use %{version0}
if [[ "${PROJECT_REF}" =~ ^(swift/)?release/.* ]]; then
PROJECT_REF="swift-%{version0}-RELEASE"
fi
- # Add a new source to the spec file between the lines "Begin forge sources" and "End forge sources"
- sed -i -e "/End forge sources/i %global forgeurl${IDX} ${FORGEURL}\n%global tag${IDX} ${PADDING}${PROJECT_REF}\n%global subdir${IDX} ${PROJECT}\n" "${SPEC_FILE}"
- IDX=$((IDX + 1))
+ # Determine the index for this project
+ if [ -n "${PROJECT_INDEX[$PROJECT]}" ]; then
+ # Existing project: update in place
+ IDX="${PROJECT_INDEX[$PROJECT]}"
+ PADDING=" "
+ if [ "${IDX}" -lt 10 ]; then
+ PADDING=" "
+ elif [ "${IDX}" -ge 100 ]; then
+ PADDING=" "
+ fi
+
+ sed -i.bak "s|^%global forgeurl${IDX} .*|%global forgeurl${IDX} ${FORGEURL}|" "$SPEC_FILE"
+ sed -i.bak "s|^%global tag${IDX} .*|%global tag${IDX} ${PADDING}${PROJECT_REF}|" "$SPEC_FILE"
+ # subdir line stays unchanged
+ else
+ # New project: append after the highest index
+ MAX_IDX=$((MAX_IDX + 1))
+ IDX="$MAX_IDX"
+ PADDING=" "
+ if [ "${IDX}" -lt 10 ]; then
+ PADDING=" "
+ elif [ "${IDX}" -ge 100 ]; then
+ PADDING=" "
+ fi
+
+ # Use awk for portable insert-before operation
+ awk -v idx="$IDX" -v url="$FORGEURL" -v ref="$PROJECT_REF" -v padding="$PADDING" -v proj="$PROJECT" '
+ /^# End forge sources/ {
+ printf "%%global forgeurl%s %s\n", idx, url
+ printf "%%global tag%s %s%s\n", idx, padding, ref
+ printf "%%global subdir%s %s\n\n", idx, proj
+ }
+ { print }
+ ' "$SPEC_FILE" > "${SPEC_FILE}.tmp" && mv "${SPEC_FILE}.tmp" "$SPEC_FILE"
+ PROJECT_INDEX["$PROJECT"]="$IDX"
+ fi
done
-# Update the version number in the spec file.
-echo "Updating version number in the spec file."
-sed -i "s|Version: .*|Version: ${SWIFT_VERSION}|" "${SPEC_FILE}"
+# Find the new maximum index for Lua loop bounds
+NEW_MAX_IDX=0
+for idx in "${PROJECT_INDEX[@]}"; do
+ if [ "$idx" -gt "$NEW_MAX_IDX" ]; then
+ NEW_MAX_IDX="$idx"
+ fi
+done
-rm -f "$TEMP_CONFIG"
+# Update Lua loop bounds (for i = 0, N do)
+# Use a more portable regex that works with both GNU and BSD sed
+sed -i.bak "s/for i = 0, [0-9][0-9]*/for i = 0, ${NEW_MAX_IDX}/" "$SPEC_FILE"
-echo "Done! Please review the changes to ensure everything is correct."
-echo "Remember to review the patches and remove any that are no longer needed."
+# Update the version number in the spec file
+echo "Updating version number in the spec file."
+sed -i.bak "s|Version: .*|Version: ${SWIFT_VERSION}|" "${SPEC_FILE}"
+
+rm -f "$TEMP_CONFIG" "${SPEC_FILE}.bak"
+
+echo "Done! Swift version updated to ${SWIFT_VERSION}"
+echo "Maximum source index: ${NEW_MAX_IDX}"
+echo ""
+echo "Next steps:"
+echo "1. Review the changes to swift-lang.spec"
+echo "2. Update patches if needed for the new version"
+echo "3. Run 'spectool -g swift-lang.spec' to download new sources"
+echo "4. Run 'fedpkg new-sources <tarballs>' to upload them"
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-19 10:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-19 10:27 [rpms/swift-lang] rawhide: update-swift-version.sh: preserve source indexes and add exclusions Link Dupont
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox