diff --git a/pkgs/native_toolchain_c/CHANGELOG.md b/pkgs/native_toolchain_c/CHANGELOG.md index b61dd3577..7221bedca 100644 --- a/pkgs/native_toolchain_c/CHANGELOG.md +++ b/pkgs/native_toolchain_c/CHANGELOG.md @@ -1,5 +1,6 @@ -## 0.3.3-wip +## 0.3.3 +- Export `environmentFromBatchFile`. - Bump `package:native_assets_cli` to 0.3.2. ## 0.3.2 diff --git a/pkgs/native_toolchain_c/lib/native_toolchain_c.dart b/pkgs/native_toolchain_c/lib/native_toolchain_c.dart index f6f90d188..1b52aaefb 100644 --- a/pkgs/native_toolchain_c/lib/native_toolchain_c.dart +++ b/pkgs/native_toolchain_c/lib/native_toolchain_c.dart @@ -6,3 +6,4 @@ library; export 'src/cbuilder/cbuilder.dart'; +export 'src/utils/env_from_bat.dart'; diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart index ecb91823c..dc2b8fb21 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart @@ -232,7 +232,8 @@ class RunCBuilder { Future runCl({required ToolInstance compiler}) async { final vcvars = (await _resolver.toolchainEnvironmentScript(compiler))!; final vcvarsArgs = _resolver.toolchainEnvironmentScriptArguments(); - final environment = await envFromBat(vcvars, arguments: vcvarsArgs ?? []); + final environment = + await environmentFromBatchFile(vcvars, arguments: vcvarsArgs ?? []); final isStaticLib = staticLibrary != null; Uri? archiver_; diff --git a/pkgs/native_toolchain_c/lib/src/utils/env_from_bat.dart b/pkgs/native_toolchain_c/lib/src/utils/env_from_bat.dart index 31958bb15..3c53f25b2 100644 --- a/pkgs/native_toolchain_c/lib/src/utils/env_from_bat.dart +++ b/pkgs/native_toolchain_c/lib/src/utils/env_from_bat.dart @@ -4,7 +4,13 @@ import 'dart:io'; -Future> envFromBat( +/// Extracts the environment variables set by [batchFile]. +/// +/// If provided, passes [arguments] to the batch file invocation. +/// +/// Note: needs to run [batchFile] to extract the modifications to the +/// environment variables. +Future> environmentFromBatchFile( Uri batchFile, { List arguments = const [], }) async { @@ -20,8 +26,8 @@ Future> envFromBat( assert(processResult.exitCode == 0); final resultSplit = (processResult.stdout as String).split(separator); assert(resultSplit.length == 2); - final unmodifiedParsed = parseDefines(resultSplit.first.trim()); - final modifiedParsed = parseDefines(resultSplit[1].trim()); + final unmodifiedParsed = _parseDefines(resultSplit.first.trim()); + final modifiedParsed = _parseDefines(resultSplit[1].trim()); final result = {}; for (final entry in modifiedParsed.entries) { final key = entry.key; @@ -33,8 +39,12 @@ Future> envFromBat( return result; } -// Ensures it doesn't return empty keys. -Map parseDefines(String defines) { +/// Parses a string of defines. +/// +/// Expected format is separate lines of `KEY=value`. +/// +/// Ensures it doesn't return empty keys. +Map _parseDefines(String defines) { final result = {}; final lines = defines.trim().split('\r\n'); for (final line in lines) { diff --git a/pkgs/native_toolchain_c/pubspec.yaml b/pkgs/native_toolchain_c/pubspec.yaml index 3695391d8..b14924f12 100644 --- a/pkgs/native_toolchain_c/pubspec.yaml +++ b/pkgs/native_toolchain_c/pubspec.yaml @@ -1,7 +1,7 @@ name: native_toolchain_c description: >- A library to invoke the native C compiler installed on the host machine. -version: 0.3.3-wip +version: 0.3.3 repository: https://github.com/dart-lang/native/tree/main/pkgs/native_toolchain_c topics: @@ -12,7 +12,7 @@ topics: - native-toolchain environment: - sdk: '>=3.1.0 <4.0.0' + sdk: ">=3.1.0 <4.0.0" dependencies: cli_config: ^0.1.1 diff --git a/pkgs/native_toolchain_c/test/native_toolchain/msvc_test.dart b/pkgs/native_toolchain_c/test/native_toolchain/msvc_test.dart index 7e9e348a0..59a584cce 100644 --- a/pkgs/native_toolchain_c/test/native_toolchain/msvc_test.dart +++ b/pkgs/native_toolchain_c/test/native_toolchain/msvc_test.dart @@ -98,7 +98,7 @@ void main() { expect(instances.isNotEmpty, true); final instance = instances.first; expect(instance.tool, vcvars32); - final env = await envFromBat(instance.uri); + final env = await environmentFromBatchFile(instance.uri); expect(env['INCLUDE'] != null, true); expect(env['WindowsSdkDir'] != null, true); // stdio.h }); @@ -113,7 +113,7 @@ void main() { expect(instances.isNotEmpty, true); final instance = instances.first; expect(instance.tool, vcvars64); - final env = await envFromBat(instance.uri); + final env = await environmentFromBatchFile(instance.uri); expect(env['INCLUDE'] != null, true); expect(env['WindowsSdkDir'] != null, true); // stdio.h }); @@ -128,7 +128,7 @@ void main() { expect(instances.isNotEmpty, true); final instance = instances.first; expect(instance.tool, vcvarsarm64); - final env = await envFromBat(instance.uri); + final env = await environmentFromBatchFile(instance.uri); expect(env['INCLUDE'] != null, true); expect(env['WindowsSdkDir'] != null, true); // stdio.h }); @@ -137,7 +137,7 @@ void main() { final instances = await vcvars32.defaultResolver!.resolve(logger: logger); expect(instances.isNotEmpty, true); final instance = instances.first; - final env = await envFromBat(instance.uri); + final env = await environmentFromBatchFile(instance.uri); expect(env['INCLUDE'] != null, true); expect(env['WindowsSdkDir'] != null, true); // stdio.h }); @@ -146,7 +146,7 @@ void main() { final instances = await vcvars64.defaultResolver!.resolve(logger: logger); expect(instances.isNotEmpty, true); final instance = instances.first; - final env = await envFromBat(instance.uri); + final env = await environmentFromBatchFile(instance.uri); expect(env['INCLUDE'] != null, true); expect(env['WindowsSdkDir'] != null, true); // stdio.h }); @@ -156,7 +156,7 @@ void main() { await vcvarsarm64.defaultResolver!.resolve(logger: logger); expect(instances.isNotEmpty, true); final instance = instances.first; - final env = await envFromBat(instance.uri); + final env = await environmentFromBatchFile(instance.uri); expect(env['INCLUDE'] != null, true); expect(env['WindowsSdkDir'] != null, true); // stdio.h }); @@ -165,7 +165,7 @@ void main() { final instances = await vcvarsall.defaultResolver!.resolve(logger: logger); expect(instances.isNotEmpty, true); final instance = instances.first; - final env = await envFromBat( + final env = await environmentFromBatchFile( instance.uri, arguments: [ 'x64', @@ -181,7 +181,7 @@ void main() { final instances = await vsDevCmd.defaultResolver!.resolve(logger: logger); expect(instances.isNotEmpty, true); final instance = instances.first; - final env = await envFromBat(instance.uri); + final env = await environmentFromBatchFile(instance.uri); expect(env['INCLUDE'] != null, true); expect(env['WindowsSdkDir'] != null, true); // stdio.h });