mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 02:29:55 +02:00
feat(config): shared app.properties for app-wide constants
Add a single source of truth (root app.properties) for public app-wide constants, injected at build time on both platforms instead of hardcoding. - Apple: generate-appconfig.sh -> Generated/AppConfig.swift (wired into `make apple-app-config`), consumed as AppConfig.privacyPolicyURL. - KMP: generateAppConfig task -> AppConfig.kt (mirrors DiagnosticsBuildConfig), consumed as AppConfig.PRIVACY_POLICY_URL. Replaces the stale hardcoded privacy-policy URL on both sides with https://vnidrop.sudosy.fr/privacy/. Also fix the Apple release core build: disable release LTO in build-core.sh (Cargo forbids lto in a build-override) to avoid the proc-macro "mis-aligned LINKEDIT string pool" corruption, so release archives are compact instead of shipping the debug core. Update the app icon. Tests: shell test for the generator (escaping, missing/duplicate key), plus XCTest and jvmTest asserting the generated value matches app.properties.
This commit is contained in:
@@ -44,6 +44,13 @@ export MACOSX_DEPLOYMENT_TARGET="${MACOSX_DEPLOYMENT_TARGET:-15.0}"
|
||||
# This never touches the Rust crate — it only changes how the build is invoked.
|
||||
export CARGO_PROFILE_DEV_STRIP=none
|
||||
|
||||
# The workspace `[profile.release] lto = "thin"` corrupts host proc-macro / build
|
||||
# script dylibs when cross-compiling ("mis-aligned LINKEDIT string pool"). Cargo
|
||||
# forbids overriding `lto` per build-override, so disable thin LTO for the whole
|
||||
# release build here — the crate is still fully optimized (opt-level 3, debuginfo
|
||||
# stripped), which is what shrinks the static lib. This never edits the Cargo crate.
|
||||
export CARGO_PROFILE_RELEASE_LTO=false
|
||||
|
||||
IOS_TARGET="aarch64-apple-ios"
|
||||
SIM_ARM_TARGET="aarch64-apple-ios-sim"
|
||||
SIM_X64_TARGET="x86_64-apple-ios"
|
||||
|
||||
44
apple/scripts/generate-appconfig.sh
Executable file
44
apple/scripts/generate-appconfig.sh
Executable file
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Generates apple/VniDrop/Generated/AppConfig.swift from the shared app.properties
|
||||
# so app-wide constants (privacy policy URL, …) have a single source of truth
|
||||
# across Apple and KMP. Regenerate instead of editing the output.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
repo_root="$(cd "$script_dir/../.." && pwd)"
|
||||
config_file="${VNIDROP_APP_PROPERTIES:-$repo_root/app.properties}"
|
||||
output_dir="${VNIDROP_APPLE_GENERATED_DIR:-$repo_root/apple/VniDrop/Generated}"
|
||||
|
||||
read_property() {
|
||||
local key=$1
|
||||
local value
|
||||
value="$(sed -n "s/^${key}=//p" "$config_file")"
|
||||
[[ -n "$value" ]] || { printf 'Missing %s in %s\n' "$key" "$config_file" >&2; exit 1; }
|
||||
[[ $(printf '%s\n' "$value" | wc -l | tr -d ' ') == 1 ]] ||
|
||||
{ printf 'Duplicate %s in %s\n' "$key" "$config_file" >&2; exit 1; }
|
||||
printf '%s' "$value"
|
||||
}
|
||||
|
||||
# Escape for a Swift string literal.
|
||||
swift_escape() {
|
||||
printf '%s' "$1" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g'
|
||||
}
|
||||
|
||||
privacy_url="$(read_property PRIVACY_POLICY_URL)"
|
||||
|
||||
mkdir -p "$output_dir"
|
||||
tmp="$(mktemp "$output_dir/.AppConfig.swift.XXXXXX")"
|
||||
cat > "$tmp" <<EOF
|
||||
// Generated by apple/scripts/generate-appconfig.sh from app.properties.
|
||||
// Regenerate this file instead of editing it.
|
||||
|
||||
import Foundation
|
||||
|
||||
/// App-wide constants injected at build time from the shared \`app.properties\`.
|
||||
enum AppConfig {
|
||||
static let privacyPolicyURL = URL(string: "$(swift_escape "$privacy_url")")!
|
||||
}
|
||||
EOF
|
||||
mv "$tmp" "$output_dir/AppConfig.swift"
|
||||
59
apple/scripts/tests/test-generate-appconfig.sh
Executable file
59
apple/scripts/tests/test-generate-appconfig.sh
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Tests apple/scripts/generate-appconfig.sh: the shared app.properties is read
|
||||
# correctly, values are emitted as valid escaped Swift, and a missing key fails.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
generator="$script_dir/../generate-appconfig.sh"
|
||||
repo_root="$(cd "$script_dir/../../.." && pwd)"
|
||||
scratch="$(mktemp -d)"
|
||||
trap 'rm -rf "$scratch"' EXIT
|
||||
|
||||
# Run the generator against a fixture app.properties, emitting into a temp dir.
|
||||
generate() {
|
||||
VNIDROP_APP_PROPERTIES="$scratch/app.properties" \
|
||||
VNIDROP_APPLE_GENERATED_DIR="$scratch/out" \
|
||||
"$generator"
|
||||
}
|
||||
|
||||
expect_failure() {
|
||||
if "$@" >/dev/null 2>&1; then
|
||||
printf 'Expected command to fail: %s\n' "$*" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
assert_contains() {
|
||||
local file=$1 needle=$2
|
||||
grep -qF "$needle" "$file" ||
|
||||
{ printf 'Expected %s to contain: %s\n' "$file" "$needle" >&2; exit 1; }
|
||||
}
|
||||
|
||||
out="$scratch/out/AppConfig.swift"
|
||||
|
||||
# 1. Nominal value is emitted verbatim as a Swift URL literal.
|
||||
printf 'PRIVACY_POLICY_URL=%s\n' 'https://example.test/privacy/' > "$scratch/app.properties"
|
||||
generate
|
||||
assert_contains "$out" 'URL(string: "https://example.test/privacy/")!'
|
||||
assert_contains "$out" 'enum AppConfig'
|
||||
|
||||
# 2. Characters special to a Swift string literal are escaped.
|
||||
printf 'PRIVACY_POLICY_URL=%s\n' 'https://a.test/"q"\z' > "$scratch/app.properties"
|
||||
generate
|
||||
assert_contains "$out" 'URL(string: "https://a.test/\"q\"\\z")!'
|
||||
|
||||
# 3. A missing key fails instead of emitting an empty value.
|
||||
printf 'OTHER_KEY=value\n' > "$scratch/app.properties"
|
||||
expect_failure generate
|
||||
|
||||
# 4. A duplicated key fails.
|
||||
printf 'PRIVACY_POLICY_URL=a\nPRIVACY_POLICY_URL=b\n' > "$scratch/app.properties"
|
||||
expect_failure generate
|
||||
|
||||
# 5. The real committed app.properties produces an https URL.
|
||||
VNIDROP_APPLE_GENERATED_DIR="$scratch/real" "$generator"
|
||||
assert_contains "$scratch/real/AppConfig.swift" 'URL(string: "https://'
|
||||
|
||||
printf 'generate-appconfig tests passed.\n'
|
||||
Reference in New Issue
Block a user