-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[native_assets_cli] Add
outputDirectoryShared
to config (#1557)
- Loading branch information
Showing
61 changed files
with
785 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
pkgs/native_assets_builder/test/build_runner/concurrency_shared_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:native_assets_builder/src/utils/run_process.dart' | ||
show RunProcessResult; | ||
import 'package:native_assets_cli/native_assets_cli_internal.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import '../helpers.dart'; | ||
import 'helpers.dart'; | ||
|
||
const Timeout longTimeout = Timeout(Duration(minutes: 5)); | ||
|
||
void main() async { | ||
const packageName = 'transformer'; | ||
|
||
test('Concurrent invocations', timeout: longTimeout, () async { | ||
await inTempDir((tempUri) async { | ||
final packageUri = tempUri.resolve('$packageName/'); | ||
await copyTestProjects( | ||
sourceUri: testDataUri.resolve('$packageName/'), | ||
targetUri: packageUri, | ||
); | ||
|
||
await runPubGet( | ||
workingDirectory: packageUri, | ||
logger: logger, | ||
); | ||
|
||
Future<RunProcessResult> runBuildInProcess( | ||
Target target, | ||
) async { | ||
final result = await runProcess( | ||
executable: dartExecutable, | ||
arguments: [ | ||
pkgNativeAssetsBuilderUri | ||
.resolve( | ||
'test/build_runner/concurrency_shared_test_helper.dart', | ||
) | ||
.toFilePath(), | ||
packageUri.toFilePath(), | ||
target.toString(), | ||
], | ||
workingDirectory: packageUri, | ||
logger: logger, | ||
); | ||
expect(result.exitCode, 0); | ||
return result; | ||
} | ||
|
||
// Simulate running `dart run` concurrently in 3 different terminals. | ||
// Twice for the same target and also for a different target. | ||
final results = await Future.wait([ | ||
runBuildInProcess(Target.androidArm64), | ||
runBuildInProcess(Target.current), | ||
runBuildInProcess(Target.current), | ||
]); | ||
final stdouts = results.map((e) => e.stdout).join('\n'); | ||
// One run for the two targets wins in running first. | ||
expect(stdouts, stringContainsInOrder(['Reused 0 cached files.'])); | ||
// The other run reuses the cached results. | ||
expect(stdouts, stringContainsInOrder(['Reused 10 cached files.'])); | ||
// One of the two runs for the same target will not be invoked at all. | ||
expect( | ||
stdouts, | ||
stringContainsInOrder([ | ||
'Waiting to be able to obtain lock of directory', | ||
'Skipping build for', | ||
]), | ||
); | ||
}); | ||
}); | ||
} |
38 changes: 38 additions & 0 deletions
38
pkgs/native_assets_builder/test/build_runner/concurrency_shared_test_helper.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
import 'package:logging/logging.dart'; | ||
import 'package:native_assets_builder/native_assets_builder.dart'; | ||
import 'package:native_assets_cli/native_assets_cli.dart'; | ||
import 'package:native_assets_cli/native_assets_cli_internal.dart'; | ||
|
||
import '../helpers.dart'; | ||
|
||
// Is invoked concurrently multiple times in separate processes. | ||
void main(List<String> args) async { | ||
final packageUri = Uri.directory(args[0]); | ||
final target = Target.fromString(args[1]); | ||
|
||
final logger = Logger('') | ||
..level = Level.ALL | ||
..onRecord.listen((event) => print(event.message)); | ||
|
||
final result = await NativeAssetsBuildRunner( | ||
logger: logger, | ||
dartExecutable: dartExecutable, | ||
).build( | ||
buildMode: BuildModeImpl.release, | ||
linkModePreference: LinkModePreferenceImpl.dynamic, | ||
target: target, | ||
workingDirectory: packageUri, | ||
includeParentEnvironment: true, | ||
linkingEnabled: false, | ||
supportedAssetTypes: [DataAsset.type], | ||
targetAndroidNdkApi: target.os == OS.android ? 30 : null, | ||
); | ||
if (!result.success) { | ||
throw Error(); | ||
} | ||
print('done'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.