Skip to content

Commit e98ce8d

Browse files
Convert boolean option to function delegate, defaulting to CliPlatform::useExe
1 parent 9549186 commit e98ce8d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/src/standalone.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ import 'utils.dart';
3333
final standaloneName = InternalConfigVariable.fn<String>(() => name.value);
3434

3535
/// Whether to build native exe for the current platform instead of AOT snapshot.
36+
/// Defined as a function of a [CliPlatform] to allow different behavior on different platforms.
3637
///
37-
/// This defaults to `false`.
38-
final useExe = InternalConfigVariable.value(false);
38+
/// This defaults to `CliPlatform::useExe`.
39+
final useExe = InternalConfigVariable.value<bool Function(CliPlatform)>((CliPlatform platform) => platform.useExe);
3940

4041
/// For each executable entrypoint in [executables], builds a script snapshot
4142
/// to `build/${executable}.snapshot`.
@@ -79,7 +80,7 @@ void _compileNative() {
7980
existingSnapshots[path] = name;
8081
run('dart', arguments: [
8182
'compile',
82-
CliPlatform.current.useExe || useExe.value ? 'exe' : 'aot-snapshot',
83+
useExe.value(CliPlatform.current) ? 'exe' : 'aot-snapshot',
8384
path,
8485
for (var entry in environmentConstants.value.entries)
8586
'-D${entry.key}=${entry.value}',
@@ -172,15 +173,15 @@ Future<void> _buildPackage(CliPlatform platform) async {
172173
var archive = Archive()
173174
..addFile(fileFromString("$standaloneName/src/LICENSE", await license));
174175

175-
if (!(platform.useExe || (useExe.value && platform.isCurrent))) {
176+
if (!(platform.useNative && useExe.value(platform))) {
176177
archive.addFile(fileFromBytes(
177178
"$standaloneName/src/dart${platform.binaryExtension}",
178179
await _dartExecutable(platform),
179180
executable: true));
180181
}
181182

182183
for (var name in executables.value.keys) {
183-
if (platform.useExe || (useExe.value && platform.isCurrent)) {
184+
if (platform.useNative && useExe.value(platform)) {
184185
archive.addFile(file("$standaloneName/$name${platform.binaryExtension}",
185186
"build/$name.native",
186187
executable: true));
@@ -190,7 +191,7 @@ Future<void> _buildPackage(CliPlatform platform) async {
190191
}
191192
}
192193

193-
if (!(platform.useExe || (useExe.value && platform.isCurrent))) {
194+
if (!(platform.useNative && useExe.value(platform))) {
194195
// Do this separately from adding entrypoints because multiple executables
195196
// may have the same entrypoint.
196197
for (var name in executables.value.keys) {

0 commit comments

Comments
 (0)