Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class CBuilder extends CTool implements Builder {
super.linkModePreference,
super.optimizationLevel = OptimizationLevel.o3,
this.buildMode = BuildMode.release,
super.runInShell,
}) : super(type: OutputType.library);

CBuilder.executable({
Expand All @@ -105,6 +106,7 @@ class CBuilder extends CTool implements Builder {
super.cppLinkStdLib,
super.optimizationLevel = OptimizationLevel.o3,
this.buildMode = BuildMode.release,
super.runInShell,
}) : super(
type: OutputType.executable,
assetName: null,
Expand Down Expand Up @@ -203,6 +205,7 @@ class CBuilder extends CTool implements Builder {
language: language,
cppLinkStdLib: cppLinkStdLib,
optimizationLevel: optimizationLevel,
runInShell: runInShell,
);
await task.run();

Expand Down
2 changes: 2 additions & 0 deletions pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class CLinker extends CTool implements Linker {
super.cppLinkStdLib,
super.linkModePreference,
super.optimizationLevel = OptimizationLevel.o3,
super.runInShell,
}) : super(type: OutputType.library);

/// Runs the C Linker with on this C build spec.
Expand Down Expand Up @@ -94,6 +95,7 @@ class CLinker extends CTool implements Linker {
language: language,
cppLinkStdLib: cppLinkStdLib,
optimizationLevel: optimizationLevel,
runInShell: runInShell,
);
await task.run();

Expand Down
7 changes: 7 additions & 0 deletions pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ abstract class CTool {
/// What optimization level should be used for compiling.
final OptimizationLevel optimizationLevel;

/// Whether to run the process in a shell.
///
/// If the path to cl.exe contains spaces, this option needs to be set to
/// false.
final bool? runInShell;

CTool({
required this.name,
required this.packageName,
Expand All @@ -186,5 +192,6 @@ abstract class CTool {
required this.linkModePreference,
required this.type,
required this.optimizationLevel,
this.runInShell,
});
}
5 changes: 5 additions & 0 deletions pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class RunCBuilder {
final Language language;
final String? cppLinkStdLib;
final OptimizationLevel optimizationLevel;
final bool? runInShell;

RunCBuilder({
required this.input,
Expand All @@ -73,6 +74,7 @@ class RunCBuilder {
this.language = Language.c,
this.cppLinkStdLib,
required this.optimizationLevel,
this.runInShell,
}) : outDir = input.outputDirectory,
assert(
[executable, dynamicLibrary, staticLibrary].whereType<Uri>().length ==
Expand Down Expand Up @@ -196,6 +198,7 @@ class RunCBuilder {
captureOutput: false,
throwOnUnexpectedExitCode: true,
environment: environment,
runInShell: runInShell,
);
} else {
await _compile(
Expand Down Expand Up @@ -343,6 +346,7 @@ class RunCBuilder {
logger: logger,
captureOutput: false,
throwOnUnexpectedExitCode: true,
runInShell: runInShell,
);
}

Expand Down Expand Up @@ -401,6 +405,7 @@ class RunCBuilder {
captureOutput: false,
stdoutLogLevel: Level.INFO,
throwOnUnexpectedExitCode: true,
runInShell: runInShell,
);

if (staticLibrary != null) {
Expand Down
3 changes: 2 additions & 1 deletion pkgs/native_toolchain_c/lib/src/utils/run_process.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Future<RunProcessResult> runProcess({
Level stdoutLogLevel = Level.FINE,
int expectedExitCode = 0,
bool throwOnUnexpectedExitCode = false,
bool? runInShell,
}) async {
final printWorkingDir =
workingDirectory != null && workingDirectory != Directory.current.uri;
Expand All @@ -41,7 +42,7 @@ Future<RunProcessResult> runProcess({
arguments,
workingDirectory: workingDirectory?.toFilePath(),
environment: environment,
runInShell: Platform.isWindows && workingDirectory != null,
runInShell: runInShell ?? Platform.isWindows && workingDirectory != null,
);

final stdoutSub = process.stdout.listen((List<int> data) {
Expand Down