Skip to content
Closed
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: 2 additions & 1 deletion pkgs/c_compiler/lib/src/cbuilder/cbuilder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class CBuilder implements Builder {
final exeUri =
outDir.resolve(buildConfig.target.os.executableFileName(name));
final sources = [
for (final source in this.sources) packageRoot.resolve(source),
for (final source in this.sources)
packageRoot.resolveUri(Uri.file(source)),
];
final dartBuildFiles = [
for (final source in this.dartBuildFiles) packageRoot.resolve(source),
Expand Down
2 changes: 1 addition & 1 deletion pkgs/c_compiler/lib/src/native_toolchain/android_ndk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class _AndroidNdkResolver implements ToolResolver {
RelativeToolResolver(
toolName: 'Android NDK',
wrappedResolver: PathToolResolver(toolName: 'ndk-build'),
relativePath: Uri(path: '.'),
relativePath: Uri(path: ''),
),
InstallLocationResolver(
toolName: 'Android NDK',
Expand Down
16 changes: 14 additions & 2 deletions pkgs/c_compiler/lib/src/tool/tool_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,25 @@ class RelativeToolResolver implements ToolResolver {

logger?.finer('Looking for $toolName relative to $otherToolInstances '
'with $relativePath.');
final result = [
final globs = [
for (final toolInstance in otherToolInstances)
Glob([
Glob.quote(
toolInstance.uri.resolve('.').toFilePath().replaceAll('\\', '/')),
relativePath.path
].join())
];
final fileSystemEntities = [
for (final glob in globs) ...await glob.list().toList(),
];
final result = [
for (final fileSystemEntity in fileSystemEntities)
ToolInstance(
tool: Tool(name: toolName),
uri: toolInstance.uri.resolveUri(relativePath),
uri: fileSystemEntity.uri,
),
];

if (result.isNotEmpty) {
logger?.fine('Found $result.');
} else {
Expand Down
4 changes: 2 additions & 2 deletions pkgs/c_compiler/lib/src/utils/run_process.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Future<RunProcessResult> runProcess({
final printWorkingDir =
workingDirectory != null && workingDirectory != Directory.current.uri;
final commandString = [
if (printWorkingDir) '(cd ${workingDirectory.path};',
if (printWorkingDir) '(cd ${workingDirectory.toFilePath()};',
...?environment?.entries.map((entry) => '${entry.key}=${entry.value}'),
executable,
executable.toFilePath(),
...arguments.map((a) => a.contains(' ') ? "'$a'" : a),
if (printWorkingDir) ')',
].join(' ');
Expand Down
10 changes: 5 additions & 5 deletions pkgs/native_assets_cli/lib/src/model/build_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ class BuildConfig {
}

Map<String, Object> toYaml() => {
outDirConfigKey: _outDir.path,
packageRootConfigKey: _packageRoot.path,
outDirConfigKey: _outDir.toFilePath(),
packageRootConfigKey: _packageRoot.toFilePath(),
Target.configKey: _target.toString(),
if (_targetIOSSdk != null) IOSSdk.configKey: _targetIOSSdk.toString(),
if (_ar != null) arConfigKey: _ar!.path,
if (_cc != null) ccConfigKey: _cc!.path,
if (_ld != null) ldConfigKey: _ld!.path,
if (_ar != null) arConfigKey: _ar!.toFilePath(),
if (_cc != null) ccConfigKey: _cc!.toFilePath(),
if (_ld != null) ldConfigKey: _ld!.toFilePath(),
PackagingPreference.configKey: _packaging.toString(),
if (_dependencyMetadata != null)
dependencyMetadataConfigKey: {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/native_assets_cli/lib/src/model/dependencies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Dependencies {
]);

List<String> toYaml() => [
for (final dependency in dependencies) dependency.path,
for (final dependency in dependencies) dependency.toFilePath(),
];

String toYamlString() => yamlEncode(toYaml());
Expand Down
8 changes: 4 additions & 4 deletions pkgs/native_assets_cli/test/example/native_add_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ void main() async {
final dartUri = Uri.file(Platform.resolvedExecutable);

final processResult = await Process.run(
dartUri.path,
dartUri.toFilePath(),
[
'build.dart',
'-Dout_dir=${tempUri.path}',
'-Dpackage_root=${testPackageUri.path}',
'-Dout_dir=${tempUri.toFilePath()}',
'-Dpackage_root=${testPackageUri.toFilePath()}',
'-Dtarget=${Target.current}',
'-Dpackaging=dynamic',
if (cc != null) '-Dcc=${cc!.toFilePath()}',
],
workingDirectory: testPackageUri.path,
workingDirectory: testPackageUri.toFilePath(),
);
if (processResult.exitCode != 0) {
print(processResult.stdout);
Expand Down
45 changes: 25 additions & 20 deletions pkgs/native_assets_cli/test/model/asset_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,27 @@ import 'package:native_assets_cli/native_assets_cli.dart';
import 'package:test/test.dart';

void main() {
final fooUri = Uri.file('path/to/libfoo.so');
final foo2Uri = Uri.file('path/to/libfoo2.so');
final foo3Uri = Uri(path: 'libfoo3.so');
final barUri = Uri(path: 'path/to/libbar.a');
final blaUri = Uri(path: 'path/with spaces/bla.dll');
final assets = [
Asset(
name: 'foo',
path: AssetAbsolutePath(Uri(path: 'path/to/libfoo.so')),
path: AssetAbsolutePath(fooUri),
target: Target.androidX64,
packaging: Packaging.dynamic,
),
Asset(
name: 'foo2',
path: AssetRelativePath(Uri(path: 'path/to/libfoo2.so')),
path: AssetRelativePath(foo2Uri),
target: Target.androidX64,
packaging: Packaging.dynamic,
),
Asset(
name: 'foo3',
path: AssetSystemPath(Uri(path: 'libfoo3.so')),
path: AssetSystemPath(foo3Uri),
target: Target.androidX64,
packaging: Packaging.dynamic,
),
Expand All @@ -40,35 +45,35 @@ void main() {
),
Asset(
name: 'bar',
path: AssetAbsolutePath(Uri(path: 'path/to/libbar.a')),
path: AssetAbsolutePath(barUri),
target: Target.linuxArm64,
packaging: Packaging.static,
),
Asset(
name: 'bla',
path: AssetAbsolutePath(Uri(path: 'path/with spaces/bla.dll')),
path: AssetAbsolutePath(blaUri),
target: Target.windowsX64,
packaging: Packaging.dynamic,
),
];

const assetsYamlEncoding = '''- name: foo
final assetsYamlEncoding = '''- name: foo
packaging: dynamic
path:
path_type: absolute
uri: path/to/libfoo.so
uri: ${fooUri.toFilePath()}
target: android_x64
- name: foo2
packaging: dynamic
path:
path_type: relative
uri: path/to/libfoo2.so
uri: ${foo2Uri.toFilePath()}
target: android_x64
- name: foo3
packaging: dynamic
path:
path_type: system
uri: libfoo3.so
uri: ${foo3Uri.toFilePath()}
target: android_x64
- name: foo4
packaging: dynamic
Expand All @@ -84,53 +89,53 @@ void main() {
packaging: static
path:
path_type: absolute
uri: path/to/libbar.a
uri: ${barUri.toFilePath()}
target: linux_arm64
- name: bla
packaging: dynamic
path:
path_type: absolute
uri: path/with spaces/bla.dll
uri: ${blaUri.toFilePath()}
target: windows_x64''';

const assetsDartEncoding = '''format-version:
final assetsDartEncoding = '''format-version:
- 1
- 0
- 0
native-assets:
android_x64:
foo:
- absolute
- path/to/libfoo.so
- ${fooUri.toFilePath()}
foo2:
- relative
- path/to/libfoo2.so
- ${foo2Uri.toFilePath()}
foo3:
- system
- libfoo3.so
- ${foo3Uri.toFilePath()}
foo4:
- executable
foo5:
- process
linux_arm64:
bar:
- absolute
- path/to/libbar.a
- ${barUri.toFilePath()}
windows_x64:
bla:
- absolute
- path/with spaces/bla.dll''';
- ${blaUri.toFilePath()}''';

test('asset yaml', () {
final yaml = assets.toYamlString().replaceAll('\\', '/');
final yaml = assets.toYamlString();
expect(yaml, assetsYamlEncoding);
final assets2 = Asset.listFromYamlString(yaml);
expect(assets, assets2);
});

test('asset yaml', () async {
final fileContents = assets.toNativeAssetsFile();
expect(fileContents.replaceAll('\\', '/'), assetsDartEncoding);
expect(fileContents, assetsDartEncoding);
});

test('AssetPath factory', () async {
Expand Down Expand Up @@ -173,7 +178,7 @@ name: foo
packaging: dynamic
path:
path_type: absolute
uri: path/to/libfoo.so
uri: ${fooUri.toFilePath()}
target: android_x64
'''
.trim());
Expand Down
22 changes: 11 additions & 11 deletions pkgs/native_assets_cli/test/model/build_config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ void main() async {
);

final config = Config(fileParsed: {
'out_dir': tempUri.resolve('out2/').path,
'package_root': tempUri.resolve('packageRoot/').path,
'out_dir': tempUri.resolve('out2/').toFilePath(),
'package_root': tempUri.resolve('packageRoot/').toFilePath(),
'target': 'android_arm64',
'packaging': 'prefer-static',
});
Expand Down Expand Up @@ -155,7 +155,7 @@ void main() async {
},
);
final yamlString = buildConfig1.toYamlString();
final expectedYamlString = '''cc: ${fakeClang.path}
final expectedYamlString = '''cc: ${fakeClang.toFilePath()}
dependency_metadata:
bar:
key: value
Expand All @@ -164,9 +164,9 @@ dependency_metadata:
z:
- z
- a
ld: ${fakeLd.path}
out_dir: ${outDir.path}
package_root: ${tempUri.path}
ld: ${fakeLd.toFilePath()}
out_dir: ${outDir.toFilePath()}
package_root: ${tempUri.toFilePath()}
packaging: prefer-static
target: ios_arm64
target_ios_sdk: iphoneos''';
Expand All @@ -187,16 +187,16 @@ target_ios_sdk: iphoneos''';
);
expect(
() => BuildConfig.fromConfig(Config(fileParsed: {
'package_root': tempUri.resolve('packageRoot/').path,
'package_root': tempUri.resolve('packageRoot/').toFilePath(),
'target': 'android_arm64',
'packaging': 'prefer-static',
})),
throwsFormatException,
);
expect(
() => BuildConfig.fromConfig(Config(fileParsed: {
'out_dir': tempUri.resolve('out2/').path,
'package_root': tempUri.resolve('packageRoot/').path,
'out_dir': tempUri.resolve('out2/').toFilePath(),
'package_root': tempUri.resolve('packageRoot/').toFilePath(),
'target': 'android_arm64',
'packaging': 'prefer-static',
'dependency_metadata': {
Expand All @@ -211,8 +211,8 @@ target_ios_sdk: iphoneos''';
test('FormatExceptions contain full stack trace of wrapped exception', () {
try {
BuildConfig.fromConfig(Config(fileParsed: {
'out_dir': tempUri.resolve('out2/').path,
'package_root': tempUri.resolve('packageRoot/').path,
'out_dir': tempUri.resolve('out2/').toFilePath(),
'package_root': tempUri.resolve('packageRoot/').toFilePath(),
'target': [1, 2, 3, 4, 5],
'packaging': 'prefer-static',
}));
Expand Down