From a944b5d23fa5620c15fd9a4aad4eb160f49ee2c6 Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Mon, 26 Aug 2024 15:08:06 +0200 Subject: [PATCH 1/2] [native_toolchain_c] Print compiler config --- pkgs/native_toolchain_c/test/clinker/objects_test.dart | 1 + .../native_toolchain_c/test/clinker/treeshake_helper.dart | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/pkgs/native_toolchain_c/test/clinker/objects_test.dart b/pkgs/native_toolchain_c/test/clinker/objects_test.dart index 58e8c86c7..8713e83de 100644 --- a/pkgs/native_toolchain_c/test/clinker/objects_test.dart +++ b/pkgs/native_toolchain_c/test/clinker/objects_test.dart @@ -49,6 +49,7 @@ Future main() async { envScriptArgs: envScriptArgs, ), ); + printOnFailure(linkConfig.cCompiler.toString()); await CLinker.library( name: name, assetName: '', diff --git a/pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart b/pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart index 66363b511..2b8983365 100644 --- a/pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart +++ b/pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart @@ -67,7 +67,15 @@ Future runTests(List architectures) async { buildMode: BuildMode.release, linkModePreference: LinkModePreference.dynamic, assets: [], + cCompiler: CCompilerConfig( + compiler: cc, + archiver: ar, + linker: ld, + envScript: envScript, + envScriptArgs: envScriptArgs, + ), ); + printOnFailure(config.cCompiler.toString()); await clinker.linker([testArchive.toFilePath()]).run( config: config, output: linkOutput, From 52a4fed983059fa17b34ca7234fb8ddf06604f86 Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Mon, 26 Aug 2024 15:21:59 +0200 Subject: [PATCH 2/2] Standardize getting the c compiler config from env in tests --- .../cbuilder/cbuilder_build_failure_test.dart | 6 +-- .../test/cbuilder/cbuilder_test.dart | 48 ++++--------------- .../test/cbuilder/objective_c_test.dart | 6 +-- .../test/clinker/build_testfiles.dart | 6 +-- .../test/clinker/objects_test.dart | 10 +--- .../test/clinker/treeshake_helper.dart | 9 +--- pkgs/native_toolchain_c/test/helpers.dart | 25 +++++++--- 7 files changed, 33 insertions(+), 77 deletions(-) diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_build_failure_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_build_failure_test.dart index 767b1bf0f..28fa203ed 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_build_failure_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_build_failure_test.dart @@ -37,11 +37,7 @@ void main() { targetOS: OS.current, linkModePreference: LinkModePreference.dynamic, buildMode: BuildMode.release, - cCompiler: CCompilerConfig( - compiler: cc, - envScript: envScript, - envScriptArgs: envScriptArgs, - ), + cCompiler: cCompiler, linkingEnabled: false, ); final buildOutput = BuildOutput(); diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart index 495e6091d..08f91df54 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart @@ -52,11 +52,7 @@ void main() { buildMode: buildMode, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, - cCompiler: CCompilerConfig( - compiler: cc, - envScript: envScript, - envScriptArgs: envScriptArgs, - ), + cCompiler: cCompiler, linkingEnabled: false, ); final buildOutput = BuildOutput(); @@ -132,11 +128,7 @@ void main() { targetOS: OS.current, buildMode: BuildMode.release, linkModePreference: LinkModePreference.dynamic, - cCompiler: CCompilerConfig( - compiler: cc, - envScript: envScript, - envScriptArgs: envScriptArgs, - ), + cCompiler: cCompiler, linkingEnabled: false, ); final buildOutput = BuildOutput(); @@ -226,11 +218,7 @@ void main() { buildMode: BuildMode.release, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, - cCompiler: CCompilerConfig( - compiler: cc, - envScript: envScript, - envScriptArgs: envScriptArgs, - ), + cCompiler: cCompiler, linkingEnabled: false, ); final buildOutput = BuildOutput(); @@ -284,11 +272,7 @@ void main() { targetOS: OS.current, buildMode: BuildMode.release, linkModePreference: LinkModePreference.dynamic, - cCompiler: CCompilerConfig( - compiler: cc, - envScript: envScript, - envScriptArgs: envScriptArgs, - ), + cCompiler: cCompiler, linkingEnabled: false, ); final buildOutput = BuildOutput(); @@ -330,11 +314,7 @@ void main() { targetOS: OS.current, buildMode: BuildMode.release, linkModePreference: LinkModePreference.dynamic, - cCompiler: CCompilerConfig( - compiler: cc, - envScript: envScript, - envScriptArgs: envScriptArgs, - ), + cCompiler: cCompiler, linkingEnabled: false, ); final buildOutput = BuildOutput(); @@ -390,11 +370,7 @@ void main() { targetOS: OS.current, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, - cCompiler: CCompilerConfig( - compiler: cc, - envScript: envScript, - envScriptArgs: envScriptArgs, - ), + cCompiler: cCompiler, linkingEnabled: false, ); final buildOutput = BuildOutput(); @@ -455,11 +431,7 @@ void main() { targetOS: OS.current, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, - cCompiler: CCompilerConfig( - compiler: cc, - envScript: envScript, - envScriptArgs: envScriptArgs, - ), + cCompiler: cCompiler, linkingEnabled: false, ); final buildOutput = BuildOutput(); @@ -527,11 +499,7 @@ Future testDefines({ buildMode: buildMode, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, - cCompiler: CCompilerConfig( - compiler: cc, - envScript: envScript, - envScriptArgs: envScriptArgs, - ), + cCompiler: cCompiler, linkingEnabled: false, ); final buildOutput = BuildOutput(); diff --git a/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart b/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart index 63cbb6b4d..4d08cc4a8 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart @@ -43,11 +43,7 @@ void main() { targetArchitecture: Architecture.current, targetOS: OS.current, linkModePreference: LinkModePreference.dynamic, - cCompiler: CCompilerConfig( - compiler: cc, - envScript: envScript, - envScriptArgs: envScriptArgs, - ), + cCompiler: cCompiler, linkingEnabled: false, ); final buildOutput = BuildOutput(); diff --git a/pkgs/native_toolchain_c/test/clinker/build_testfiles.dart b/pkgs/native_toolchain_c/test/clinker/build_testfiles.dart index 1e21cf3a4..763ba1e44 100644 --- a/pkgs/native_toolchain_c/test/clinker/build_testfiles.dart +++ b/pkgs/native_toolchain_c/test/clinker/build_testfiles.dart @@ -33,11 +33,7 @@ Future buildTestArchive( targetOS: os, buildMode: BuildMode.release, linkModePreference: LinkModePreference.dynamic, - cCompiler: CCompilerConfig( - compiler: cc, - envScript: envScript, - envScriptArgs: envScriptArgs, - ), + cCompiler: cCompiler, linkingEnabled: false, ); final buildOutput = BuildOutput(); diff --git a/pkgs/native_toolchain_c/test/clinker/objects_test.dart b/pkgs/native_toolchain_c/test/clinker/objects_test.dart index 8713e83de..0caec889a 100644 --- a/pkgs/native_toolchain_c/test/clinker/objects_test.dart +++ b/pkgs/native_toolchain_c/test/clinker/objects_test.dart @@ -31,7 +31,6 @@ Future main() async { final tempUri = await tempDirForTest(); final uri = await buildTestArchive(tempUri, os, architecture); - final linkConfig = LinkConfig.build( outputDirectory: tempUri, packageName: 'testpackage', @@ -41,15 +40,10 @@ Future main() async { buildMode: BuildMode.debug, linkModePreference: LinkModePreference.dynamic, assets: [], - cCompiler: CCompilerConfig( - compiler: cc, - archiver: ar, - linker: ld, - envScript: envScript, - envScriptArgs: envScriptArgs, - ), + cCompiler: cCompiler, ); printOnFailure(linkConfig.cCompiler.toString()); + printOnFailure(Platform.environment.keys.toList().toString()); await CLinker.library( name: name, assetName: '', diff --git a/pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart b/pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart index 2b8983365..5dcaf7896 100644 --- a/pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart +++ b/pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart @@ -67,15 +67,10 @@ Future runTests(List architectures) async { buildMode: BuildMode.release, linkModePreference: LinkModePreference.dynamic, assets: [], - cCompiler: CCompilerConfig( - compiler: cc, - archiver: ar, - linker: ld, - envScript: envScript, - envScriptArgs: envScriptArgs, - ), + cCompiler: cCompiler, ); printOnFailure(config.cCompiler.toString()); + printOnFailure(Platform.environment.keys.toList().toString()); await clinker.linker([testArchive.toFilePath()]).run( config: config, output: linkOutput, diff --git a/pkgs/native_toolchain_c/test/helpers.dart b/pkgs/native_toolchain_c/test/helpers.dart index 31b0d458b..69992a284 100644 --- a/pkgs/native_toolchain_c/test/helpers.dart +++ b/pkgs/native_toolchain_c/test/helpers.dart @@ -123,31 +123,42 @@ String unparseKey(String key) => key.replaceAll('.', '__').toUpperCase(); /// Archiver provided by the environment. /// /// Provided on Dart CI. -final Uri? ar = Platform.environment[unparseKey('c_compiler.ar')]?.asFileUri(); +final Uri? _ar = Platform.environment[unparseKey('c_compiler.ar')]?.asFileUri(); /// Compiler provided by the environment. /// /// Provided on Dart CI. -final Uri? cc = Platform.environment[unparseKey('c_compiler.cc')]?.asFileUri(); +final Uri? _cc = Platform.environment[unparseKey('c_compiler.cc')]?.asFileUri(); /// Linker provided by the environment. /// /// Provided on Dart CI. -final Uri? ld = Platform.environment[unparseKey('c_compiler.ld')]?.asFileUri(); +final Uri? _ld = Platform.environment[unparseKey('c_compiler.ld')]?.asFileUri(); -/// Path to script that sets environment variables for [cc], [ld], and [ar]. +/// Path to script that sets environment variables for [_cc], [_ld], and [_ar]. /// /// Provided on Dart CI. -final Uri? envScript = +final Uri? _envScript = Platform.environment[unparseKey('c_compiler.env_script')]?.asFileUri(); -/// Arguments for [envScript] provided by environment. +/// Arguments for [_envScript] provided by environment. /// /// Provided on Dart CI. -final List? envScriptArgs = Platform +final List? _envScriptArgs = Platform .environment[unparseKey('c_compiler.env_script_arguments')] ?.split(' '); +/// Configuration for the native toolchain. +/// +/// Provided on Dart CI. +final cCompiler = CCompilerConfig( + compiler: _cc, + archiver: _ar, + linker: _ld, + envScript: _envScript, + envScriptArgs: _envScriptArgs, +); + extension on String { Uri asFileUri() => Uri.file(this); }