Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d73ac54

Browse files
author
Dart CI
committed
Version 2.18.0-125.0.dev
Merge commit '4e520ec7a7ceb903da0c4ec04da7eeb635524748' into 'dev'
2 parents f5b7d49 + 4e520ec commit d73ac54

File tree

3 files changed

+88
-9
lines changed

3 files changed

+88
-9
lines changed

pkg/dart2native/lib/dart2native_macho.dart

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,32 @@ Future<int> pipeStream(RandomAccessFile from, RandomAccessFile to,
265265
return numWritten;
266266
}
267267

268+
class _MacOSVersion {
269+
final int? _major;
270+
final int? _minor;
271+
272+
static final _regexp = RegExp(r'Version (?<major>\d+).(?<minor>\d+)');
273+
static const _parseFailure = 'Could not determine macOS version';
274+
275+
const _MacOSVersion._internal(this._major, this._minor);
276+
277+
static const _unknown = _MacOSVersion._internal(null, null);
278+
279+
factory _MacOSVersion() {
280+
if (!Platform.isMacOS) return _unknown;
281+
final match =
282+
_regexp.matchAsPrefix(Platform.operatingSystemVersion) as RegExpMatch?;
283+
if (match == null) return _unknown;
284+
final minor = int.tryParse(match.namedGroup('minor')!);
285+
final major = int.tryParse(match.namedGroup('major')!);
286+
return _MacOSVersion._internal(major, minor);
287+
}
288+
289+
bool get isValid => _major != null;
290+
int get major => _major ?? (throw _parseFailure);
291+
int get minor => _minor ?? (throw _parseFailure);
292+
}
293+
268294
// Writes an "appended" dart runtime + script snapshot file in a format
269295
// compatible with MachO executables.
270296
Future writeAppendedMachOExecutable(
@@ -312,17 +338,39 @@ Future writeAppendedMachOExecutable(
312338
await stream.close();
313339

314340
if (machOFile.hasCodeSignature) {
341+
if (!Platform.isMacOS) {
342+
throw 'Cannot sign MachO binary on non-macOS platform';
343+
}
344+
315345
// After writing the modified file, we perform ad-hoc signing (no identity)
316-
// similar to the linker (the linker-signed option flag) to ensure that any
317-
// LC_CODE_SIGNATURE block has the correct CD hashes. This is necessary for
318-
// platforms where signature verification is always on (e.g., OS X on M1).
346+
// to ensure that any LC_CODE_SIGNATURE block has the correct CD hashes.
347+
// This is necessary for platforms where signature verification is always on
348+
// (e.g., OS X on M1).
319349
//
320350
// We use the `-f` flag to force signature overwriting as the official
321351
// Dart binaries (including dartaotruntime) are fully signed.
322-
final signingProcess = await Process.run(
323-
'codesign', ['-f', '-o', 'linker-signed', '-s', '-', outputPath]);
352+
final args = ['-f', '-s', '-', outputPath];
353+
354+
// If running on macOS >=11.0, then the linker-signed option flag can be
355+
// used to create a signature that does not need to be force overridden.
356+
final version = _MacOSVersion();
357+
if (version.isValid && version.major >= 11) {
358+
final signingProcess =
359+
await Process.run('codesign', ['-o', 'linker-signed', ...args]);
360+
if (signingProcess.exitCode == 0) {
361+
return;
362+
}
363+
print('Failed to add a linker signed signature, '
364+
'adding a regular signature instead.');
365+
}
366+
367+
// If that fails or we're running on an older or undetermined version of
368+
// macOS, we fall back to signing without the linker-signed option flag.
369+
// Thus, to sign the binary, the developer must force signature overwriting.
370+
final signingProcess = await Process.run('codesign', args);
324371
if (signingProcess.exitCode != 0) {
325-
print('Subcommand terminated with exit code ${signingProcess.exitCode}.');
372+
print('Failed to replace the dartaotruntime signature, ');
373+
print('subcommand terminated with exit code ${signingProcess.exitCode}.');
326374
if (signingProcess.stdout.isNotEmpty) {
327375
print('Subcommand stdout:');
328376
print(signingProcess.stdout);

pkg/dartdev/test/commands/compile_test.dart

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void defineCompileTests() {
187187
expect(result.stdout, contains('2: foo'));
188188
});
189189

190-
test('Compile and run executable', () async {
190+
Future<void> basicCompileTest() async {
191191
final p = project(mainSrc: 'void main() { print("I love executables"); }');
192192
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
193193
final outFile = path.canonicalize(path.join(p.dirPath, 'lib', 'main.exe'));
@@ -213,7 +213,9 @@ void defineCompileTests() {
213213
expect(result.stderr, isEmpty);
214214
expect(result.exitCode, 0);
215215
expect(result.stdout, contains('I love executables'));
216-
}, skip: isRunningOnIA32);
216+
}
217+
218+
test('Compile and run executable', basicCompileTest, skip: isRunningOnIA32);
217219

218220
test('Compile to executable disabled on IA32', () async {
219221
final p = project(mainSrc: 'void main() { print("I love executables"); }');
@@ -1112,4 +1114,33 @@ void main() {
11121114
expect(result.stderr, contains('Warning:'));
11131115
expect(result.exitCode, 0);
11141116
});
1117+
1118+
if (Platform.isMacOS) {
1119+
test('Compile and run executable from signed dartaotruntime', () async {
1120+
// Either the locally built dartaotruntime is already linker signed
1121+
// (on M1) or it is unsigned (on X64). For this test, sign the
1122+
// dartaotruntime executable with a non-linker signed adhoc signature,
1123+
// which won't cause issues with any other tests that use it. This
1124+
// ensures the code signing path in dart2native is exercised on X64
1125+
// (macOS <11.0), and also mimics the case for end users that are using
1126+
// the published Dart SDK (which is fully signed, not linker signed).
1127+
final Directory binDir = File(Platform.resolvedExecutable).parent;
1128+
final String originalRuntimePath =
1129+
path.join(binDir.path, 'dartaotruntime');
1130+
final codeSigningProcess = await Process.start('codesign', [
1131+
'-o',
1132+
'runtime',
1133+
'-s',
1134+
'-',
1135+
originalRuntimePath,
1136+
]);
1137+
1138+
final signingResult = await codeSigningProcess.exitCode;
1139+
expect(signingResult, 0);
1140+
1141+
// Now perform the same basic compile and run test with the signed
1142+
// dartaotruntime.
1143+
await basicCompileTest();
1144+
}, skip: isRunningOnIA32);
1145+
}
11151146
}

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ CHANNEL dev
2727
MAJOR 2
2828
MINOR 18
2929
PATCH 0
30-
PRERELEASE 124
30+
PRERELEASE 125
3131
PRERELEASE_PATCH 0

0 commit comments

Comments
 (0)