Skip to content

Commit f77246f

Browse files
authored
[objective_c] - fix private pub dev issue (dart-lang#2996)
1 parent d296579 commit f77246f

3 files changed

Lines changed: 120 additions & 3 deletions

File tree

‎pkgs/objective_c/CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 9.2.4
2+
3+
- Fix a [bug](https://github.com/dart-lang/native/issues/2990) build hook path
4+
issue that could pass percent-encoded cache paths to clang, leading to missing
5+
source file errors.
6+
17
## 9.2.3
28

39
- Fix a [bug](https://github.com/dart-lang/native/issues/2973) where the

‎pkgs/objective_c/hook/build.dart‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,17 @@ void main(List<String> args) async {
6363
// aren't supported on iOS, like mach_vm_region. We don't need them on iOS
6464
// anyway since we only run memory tests on mac.
6565
if (os == OS.macOS) {
66-
cFiles.addAll(testFiles.map((f) => input.packageRoot.resolve(f).path));
66+
cFiles.addAll(
67+
testFiles.map((f) => input.packageRoot.resolve(f).toFilePath()),
68+
);
6769
}
6870

6971
final sysroot = sdkPath(codeConfig);
7072
final cFlags = <String>['-isysroot', sysroot, '-target', target];
7173
final mFlags = [...cFlags, ...objCFlags];
7274
final linkFlags = cFlags;
7375

74-
final builder = await Builder.create(input, input.packageRoot.path);
76+
final builder = await Builder.create(input, input.packageRoot.toFilePath());
7577

7678
final objectFiles = await Future.wait(<Future<String>>[
7779
for (final src in cFiles) builder.buildObject(src, cFlags),
@@ -115,7 +117,7 @@ class Builder {
115117
Future<String> buildObject(String input, List<String> flags) async {
116118
assert(input.startsWith(_rootDir));
117119
final relativeInput = input.substring(_rootDir.length);
118-
final output = '${_tempOutDir.resolve(relativeInput).path}.o';
120+
final output = '${_tempOutDir.resolve(relativeInput).toFilePath()}.o';
119121
File(output).parent.createSync(recursive: true);
120122
await _compile([...flags, '-c', input, '-fpic', '-I', 'src'], output);
121123
return output;
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:convert';
6+
import 'dart:io';
7+
8+
import 'package:code_assets/code_assets.dart';
9+
import 'package:hooks/hooks.dart';
10+
import 'package:native_test_helpers/native_test_helpers.dart';
11+
import 'package:test/test.dart';
12+
13+
import '../hook/build.dart' as hook;
14+
15+
void main() {
16+
test(
17+
'build hook decodes percent-encoded package root paths',
18+
() async {
19+
final tempDir = await Directory.systemTemp.createTemp(
20+
'objective_c_hook_path',
21+
);
22+
addTearDown(() => tempDir.delete(recursive: true));
23+
24+
final realPackageRoot = findPackageRoot('objective_c');
25+
const rootDirName = 'pkg%47root';
26+
final rootDir = Directory('${tempDir.path}/$rootDirName');
27+
await rootDir.create();
28+
final symlinkPath = '${rootDir.path}/objective_c';
29+
await Link(symlinkPath).create(realPackageRoot.toFilePath());
30+
final symlinkDir = Directory(symlinkPath);
31+
32+
final encodedPath = symlinkPath.replaceAll('%', '%25');
33+
final encodedPackageRoot = Uri.parse(
34+
'file:///${encodedPath.substring(1)}/',
35+
);
36+
expect(encodedPackageRoot.toString(), contains('%2547'));
37+
38+
final compilerLog = tempDir.uri.resolve('compiler_args.txt').toFilePath();
39+
File(compilerLog).writeAsStringSync('');
40+
final compilerScript = tempDir.uri.resolve('clang').toFilePath();
41+
File(compilerScript).writeAsStringSync('''#!/bin/sh
42+
if [ "\$1" = "--version" ]; then
43+
echo "Apple clang version 15.0.0"
44+
exit 0
45+
fi
46+
log="$compilerLog"
47+
out=""
48+
prev=""
49+
for arg in "\$@"; do
50+
if [ "\$prev" = "-o" ]; then
51+
out="\$arg"
52+
fi
53+
prev="\$arg"
54+
printf '%s\\n' "\$arg" >> "\$log"
55+
done
56+
if [ -n "\$out" ]; then
57+
mkdir -p "\$(dirname "\$out")"
58+
: > "\$out"
59+
fi
60+
exit 0
61+
''');
62+
Process.runSync('chmod', ['+x', compilerScript]);
63+
64+
final outputDirectoryShared = tempDir.uri.resolve('output_shared/');
65+
await Directory.fromUri(outputDirectoryShared).create();
66+
final outputFile = tempDir.uri.resolve('output.json');
67+
68+
final inputBuilder = BuildInputBuilder()
69+
..setupShared(
70+
packageRoot: encodedPackageRoot,
71+
packageName: 'objective_c',
72+
outputFile: outputFile,
73+
outputDirectoryShared: outputDirectoryShared,
74+
)
75+
..setupBuildInput()
76+
..config.setupBuild(linkingEnabled: false)
77+
..addExtension(
78+
CodeAssetExtension(
79+
targetArchitecture: Architecture.current,
80+
targetOS: OS.macOS,
81+
linkModePreference: LinkModePreference.dynamic,
82+
macOS: MacOSCodeConfig(targetVersion: 13),
83+
cCompiler: CCompilerConfig(
84+
compiler: Uri.file(compilerScript),
85+
linker: Uri.file(compilerScript),
86+
archiver: Uri.file(compilerScript),
87+
),
88+
),
89+
);
90+
final input = inputBuilder.build();
91+
final inputFile = tempDir.uri.resolve('input.json');
92+
File.fromUri(inputFile).writeAsStringSync(json.encode(input.json));
93+
94+
final originalCwd = Directory.current;
95+
Directory.current = symlinkDir;
96+
try {
97+
await (hook.main as dynamic)(['--config=${inputFile.toFilePath()}']);
98+
} finally {
99+
Directory.current = originalCwd;
100+
}
101+
102+
final logLines = File(compilerLog).readAsLinesSync();
103+
final decodedUtil = '$symlinkPath/test/util.c';
104+
expect(logLines, contains(decodedUtil));
105+
expect(logLines.any((line) => line.contains('%2547')), isFalse);
106+
},
107+
skip: !Platform.isMacOS ? 'Requires macOS' : null,
108+
);
109+
}

0 commit comments

Comments
 (0)