Skip to content
Merged
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
6 changes: 6 additions & 0 deletions pkgs/native_toolchain_c/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.17.4

- For Windows, include errors from the standard output of `cl` in the logger's
output of CBuilder.
([#2809](https://github.com/dart-lang/native/issues/2809))

## 0.17.3

- Bump `package:hooks` and `package:code_assets`to 1.0.0.
Expand Down
2 changes: 2 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 @@ -399,6 +399,7 @@ class RunCBuilder {
environment: environment,
logger: logger,
captureOutput: false,
stdoutLogLevel: Level.INFO,
throwOnUnexpectedExitCode: true,
);

Expand All @@ -410,6 +411,7 @@ class RunCBuilder {
environment: environment,
logger: logger,
captureOutput: false,
stdoutLogLevel: Level.INFO,
throwOnUnexpectedExitCode: true,
);
}
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 @@ -19,6 +19,7 @@ Future<RunProcessResult> runProcess({
Map<String, String>? environment,
required Logger? logger,
bool captureOutput = true,
Level stdoutLogLevel = Level.FINE,
int expectedExitCode = 0,
bool throwOnUnexpectedExitCode = false,
}) async {
Expand Down Expand Up @@ -46,7 +47,7 @@ Future<RunProcessResult> runProcess({
final stdoutSub = process.stdout.listen((List<int> data) {
try {
final decoded = systemEncoding.decode(data);
logger?.fine(decoded);
logger?.log(stdoutLogLevel, decoded);
if (captureOutput) {
stdoutBuffer.write(decoded);
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/native_toolchain_c/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: native_toolchain_c
description: >-
A library to invoke the native C compiler installed on the host machine.
version: 0.17.3
version: 0.17.4
repository: https://github.com/dart-lang/native/tree/main/pkgs/native_toolchain_c

topics:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ library;
import 'dart:io';

import 'package:code_assets/code_assets.dart';
import 'package:collection/collection.dart';
import 'package:hooks/hooks.dart';
import 'package:logging/logging.dart';
import 'package:native_toolchain_c/native_toolchain_c.dart';
import 'package:test/test.dart';

Expand Down Expand Up @@ -68,4 +70,60 @@ void main() {
throwsException,
);
});

test('CL build failure include error output', () async {
if (!Platform.isWindows) {
// Avoid needing status files on Dart SDK CI.
return;
}

final tempUri = await tempDirForTest();
final tempUri2 = await tempDirForTest();
final source = packageUri.resolve(
'test/cbuilder/testfiles/build_failure/cl.c',
);
const name = 'cl';

final buildInputBuilder = BuildInputBuilder()
..setupShared(
packageName: name,
packageRoot: tempUri,
outputFile: tempUri.resolve('output.json'),
outputDirectoryShared: tempUri2,
)
..config.setupBuild(linkingEnabled: false)
..addExtension(
CodeAssetExtension(
targetOS: OS.windows,
targetArchitecture: Architecture.current,
linkModePreference: LinkModePreference.dynamic,
cCompiler: cCompiler,
),
);

final buildInput = buildInputBuilder.build();
final buildOutput = BuildOutputBuilder();

final logs = <LogRecord>[];
final logger = createCapturingRecordLogger(logs);
final cbuilder = CBuilder.library(
sources: [source.toFilePath()],
name: name,
assetName: name,
includes: [],
buildMode: BuildMode.release,
);
await expectLater(
cbuilder.run(input: buildInput, output: buildOutput, logger: logger),
throwsException,
);

// Note: don't check the entire message as CL output is based on user
// locale.
final line = logs.firstWhereOrNull(
(log) =>
log.level == Level.INFO && log.message.contains('fatal error C1070'),
);
expect(line != null, true);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

#include "cl.h"
14 changes: 14 additions & 0 deletions pkgs/native_toolchain_c/test/cbuilder/testfiles/build_failure/cl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

#ifndef BUILD_FAILURE_CL_H
#define BUILD_FAILURE_CL_H

#ifdef _WIN32
#define INCLUDE_EXPORT __declspec(dllexport)
#else
#define INCLUDE_EXPORT
//#endif

#endif
22 changes: 13 additions & 9 deletions pkgs/native_toolchain_c/test/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,19 @@ Logger? _logger;
Logger createCapturingLogger(List<String> capturedMessages) =>
_createTestLogger(capturedMessages: capturedMessages);

Logger _createTestLogger({List<String>? capturedMessages}) =>
Logger.detached('')
..level = Level.ALL
..onRecord.listen((record) {
printOnFailure(
'${record.level.name}: ${record.time}: ${record.message}',
);
capturedMessages?.add(record.message);
});
Logger createCapturingRecordLogger(List<LogRecord> capturedLogs) =>
_createTestLogger(capturedLogs: capturedLogs);

Logger _createTestLogger({
List<String>? capturedMessages,
List<LogRecord>? capturedLogs,
}) => Logger.detached('')
..level = Level.ALL
..onRecord.listen((record) {
printOnFailure('${record.level.name}: ${record.time}: ${record.message}');
capturedMessages?.add(record.message);
capturedLogs?.add(record);
});

Uri packageUri = findPackageRoot('native_toolchain_c');

Expand Down