findBuiltExecutable function
Uri
findBuiltExecutable(
- String executableName,
- Uri packageRoot, {
- String dir = 'build/',
})
Implementation
Uri findBuiltExecutable(String executableName, Uri packageRoot,
{String dir = 'build/'}) {
List<String> locations = [
'Release/$executableName',
'Release/$executableName.exe',
'Debug/$executableName',
'Debug/$executableName.exe',
executableName,
'$executableName.exe',
];
final Uri buildDirectory = packageRoot.resolve(dir);
Uri? found;
List<Uri> tried = [];
for (final location in locations) {
final uri = buildDirectory.resolve(location);
tried.add(uri);
if (File.fromUri(uri).existsSync()) {
found = uri;
break;
}
}
if (found == null) {
throw Exception(
'Unable to find build executable $executableName! Tried the following locations: $tried');
}
return found;
}