Files
swift-nio/scripts/check-cxx-interop-compatibility.sh
Raphael 4be5ac5872 Add newline to avoid broken source files (#3570)
### Motivation:

An upcoming change in the library template adds a code snippet. Since
our cxx interop compatibility test script does not account for that
tests fail on nightly.

### Modifications:

Insert a newline character before other modifications.

### Result:

The cxx interop compatibility tests pass again on nightly.
2026-04-07 15:18:10 +00:00

50 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
##===----------------------------------------------------------------------===##
##
## This source file is part of the SwiftNIO open source project
##
## Copyright (c) 2024 Apple Inc. and the SwiftNIO project authors
## Licensed under Apache License v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
set -euo pipefail
log() { printf -- "** %s\n" "$*" >&2; }
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
fatal() { error "$@"; exit 1; }
log "Checking for Cxx interoperability compatibility..."
source_dir=$(pwd)
working_dir=$(mktemp -d "/tmp/tmp_swift_package_XXXXXXXXXX")
project_name=$(basename "$working_dir")
source_file=Sources/$project_name/$project_name.swift
library_products=$( swift package dump-package | jq -r '.products[] | select(.type.library != null) | .name')
package_name=$(swift package dump-package | jq -r '.name')
cd "$working_dir"
swift package init
{
echo "let swiftSettings: [SwiftSetting] = [.interoperabilityMode(.Cxx)]"
echo "for target in package.targets { target.swiftSettings = (target.swiftSettings ?? []) + swiftSettings }"
} >> Package.swift
echo "package.dependencies.append(.package(path: \"$source_dir\"))" >> Package.swift
echo >> "$source_file" # Line break to account for template code in the file
for product in $library_products; do
echo "package.targets.first!.dependencies.append(.product(name: \"$product\", package: \"$package_name\"))" >> Package.swift
echo "import $product" >> "$source_file"
done
swift build
log "✅ Passed the Cxx interoperability tests."