Files
terebi/Checks/ffmpeg-runtime.swift
hl-valdemar 31c4759c1d build: bundle playback and YouTube dependencies
Build pinned LGPL playback libraries and package standalone YouTube helpers inside the signed native app. Keep the CLI inside the app and relocate private library links for installation without runtime Homebrew dependencies.

Record adaptive fixture completion in its EXIT trap: cancellation can exit with status 143 before the TERM trap writes its marker, while native pause and quality preservation remain correct.
2026-10-12 01:52:51 +02:00

46 lines
2.9 KiB
Swift

import Foundation
@main
struct FFmpegRuntimeChecks {
static func require(_ condition: Bool, _ message: String) {
if !condition { fatalError("FAIL: " + message) }
}
static func main() throws {
let realApp = URL(fileURLWithPath: CommandLine.arguments[1], isDirectory: true)
let directory = FileManager.default.temporaryDirectory.appendingPathComponent("terebi.ffmpeg-check.\(UUID().uuidString)", isDirectory: true)
let app = directory.appendingPathComponent("terebi.app", isDirectory: true)
let resources = app.appendingPathComponent("Contents/Resources", isDirectory: true)
try FileManager.default.createDirectory(at: resources, withIntermediateDirectories: true)
defer { try? FileManager.default.removeItem(at: directory) }
let manifest = resources.appendingPathComponent("ffmpeg-libraries.txt")
let required = try String(contentsOf: realApp.appendingPathComponent("Contents/Resources/ffmpeg-libraries.txt"), encoding: .utf8)
.split(separator: "\n").map(String.init)
let frameworks = app.appendingPathComponent("Contents/Frameworks", isDirectory: true)
try FileManager.default.createDirectory(at: frameworks, withIntermediateDirectories: true)
require(FFmpegRuntime.error(for: app) != nil, "missing dependency metadata blocks startup")
for invalid in [
"/" + required[0], "../" + required[0], "subdirectory/" + required[0],
"libavformat.dylib", "libavformat..dylib", "libavformat.one.dylib",
"libavformat.1.dylib\r", "libavformat.1.dylib\0"
] {
var entries = required
entries[0] = invalid
try (entries.joined(separator: "\n") + "\n").write(to: manifest, atomically: true, encoding: .utf8)
require(FFmpegRuntime.error(for: app) != nil, "unsafe or unversioned metadata blocks startup")
}
try Array(repeating: required[0], count: 5).joined(separator: "\n").write(to: manifest, atomically: true, encoding: .utf8)
require(FFmpegRuntime.error(for: app) != nil, "duplicated entries cannot omit required library families")
try (required.joined(separator: "\n") + "\n").write(to: manifest, atomically: true, encoding: .utf8)
require(FFmpegRuntime.error(for: app) != nil, "missing bundled libraries block startup")
let brokenLibrary = frameworks.appendingPathComponent(required[0])
try Data("not a dynamic library".utf8).write(to: brokenLibrary)
require(FFmpegRuntime.error(for: app) != nil, "an existing but unloadable bundled library blocks startup")
try FileManager.default.removeItem(at: frameworks)
try FileManager.default.copyItem(at: realApp.appendingPathComponent("Contents/Frameworks"), to: frameworks)
require(FFmpegRuntime.error(for: app) == nil, "isolated relocated copies of bundled native libraries load successfully")
print("FFmpeg runtime checks passed")
}
}