From 85ce14f1937e7f8d99c64c7e7ce71954639a723b Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Sat, 8 Aug 2026 22:30:48 +0200 Subject: [PATCH] Consolidate getXCodeSDK/getXCodeClang into a single getXCodeTool --- hook/build.dart | 6 +++--- lib/helpers/extensions/get_xcode_sdk.dart | 20 ++++++-------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/hook/build.dart b/hook/build.dart index aa5d94e..4c89389 100644 --- a/hook/build.dart +++ b/hook/build.dart @@ -28,7 +28,7 @@ Future main(List args) => build(args, (input, output) async { final iosConfig = codeConfig.iOS; iosSdk = iosConfig.targetSdk; final minVersion = iosConfig.targetVersion; - iosSdkPath = await getXCodeSDK(sdkType: iosSdk.type); + iosSdkPath = await getXCodeTool(sdkType: iosSdk.type); final archTriple = switch (targetArch) { Architecture.arm64 => "arm64", Architecture.x64 => "x86_64", @@ -41,14 +41,14 @@ Future main(List args) => build(args, (input, output) async { : "$archTriple-apple-ios$minVersion.0"; extraEnv = { "GOOS": "ios", - "CC": await getXCodeClang(sdkType: iosSdk.type), + "CC": await getXCodeTool(sdkType: iosSdk.type, findTool: "clang"), "CGO_CFLAGS": "-isysroot $iosSdkPath -target $iosTargetTriple", "CGO_LDFLAGS": "-isysroot $iosSdkPath -target $iosTargetTriple", }; break; case OS.macOS: libFileName = "libgomuks.dylib"; - extraEnv = {"SDKROOT": await getXCodeSDK()}; + extraEnv = {"SDKROOT": await getXCodeTool()}; break; case OS.windows: libFileName = "libgomuks.dll"; diff --git a/lib/helpers/extensions/get_xcode_sdk.dart b/lib/helpers/extensions/get_xcode_sdk.dart index 4deb73a..017d762 100644 --- a/lib/helpers/extensions/get_xcode_sdk.dart +++ b/lib/helpers/extensions/get_xcode_sdk.dart @@ -1,22 +1,14 @@ import "dart:io"; -Future _runXcrun(List args, String errorContext) async { - final result = await Process.run("xcrun", args); +Future getXCodeTool({String? sdkType, String? findTool}) async { + final result = await Process.run("xcrun", [ + if (sdkType != null) ...["--sdk", sdkType], + if (findTool != null) ...["-f", findTool] else "--show-sdk-path", + ]); if (result.exitCode != 0) { - throw Exception("Failed to $errorContext\n${result.stderr}"); + throw Exception("Failed to run xcrun\n${result.stderr}"); } return result.stdout.toString().trim(); } - -Future getXCodeSDK({String? sdkType}) => _runXcrun([ - if (sdkType != null) ...["--sdk", sdkType], - "--show-sdk-path", -], "get XCode SDK"); - -Future getXCodeClang({String? sdkType}) => _runXcrun([ - if (sdkType != null) ...["--sdk", sdkType], - "-f", - "clang", -], "get XCode clang");