-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support releasing and patching Windows apps (#2712)
Co-authored-by: Felix Angelov <[email protected]>
- Loading branch information
1 parent
7f38e8f
commit 691cd0a
Showing
42 changed files
with
2,247 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
77b6dc95d4e1f2de2af3c9241b874f0ede96e1ed | ||
56228c343d6c7fd3e1e548dbb290f9713bb22aa9 |
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
24 changes: 24 additions & 0 deletions
24
packages/shorebird_cli/lib/src/archive_analysis/portable_executable.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,24 @@ | ||
import 'dart:io'; | ||
import 'dart:typed_data'; | ||
|
||
/// Utilities for interacting with Windows Portable Executable files. | ||
class PortableExecutable { | ||
/// Zeroes out the timestamps in the provided PE file to enable comparison of | ||
/// binaries with different build times. | ||
/// | ||
/// Timestamps are DWORD (4-byte) values at: | ||
/// 1. offset 0x110 in the PE header. | ||
/// 2. offset 0x6e14 (seems to be in section 1, need to figure out a robust | ||
/// way to find this). | ||
/// | ||
/// https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#coff-file-header-object-and-image | ||
static Uint8List bytesWithZeroedTimestamps(File file) { | ||
final bytes = file.readAsBytesSync(); | ||
final timestampLocations = [0x110, 0x6e14]; | ||
for (final location in timestampLocations) { | ||
bytes.setRange(location, location + 4, List.filled(4, 0)); | ||
} | ||
|
||
return bytes; | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
packages/shorebird_cli/lib/src/archive_analysis/windows_archive_differ.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,105 @@ | ||
import 'dart:io'; | ||
import 'dart:isolate'; | ||
|
||
import 'package:archive/archive_io.dart'; | ||
import 'package:crypto/crypto.dart'; | ||
import 'package:path/path.dart' as p; | ||
import 'package:shorebird_cli/src/archive_analysis/archive_analysis.dart'; | ||
import 'package:shorebird_cli/src/archive_analysis/archive_differ.dart'; | ||
import 'package:shorebird_cli/src/archive_analysis/portable_executable.dart'; | ||
|
||
/// {@template windows_archive_differ} | ||
/// Finds differences between two Windows app packages. | ||
/// {@endtemplate} | ||
class WindowsArchiveDiffer extends ArchiveDiffer { | ||
/// {@macro windows_archive_differ} | ||
const WindowsArchiveDiffer(); | ||
|
||
String _hash(List<int> bytes) => sha256.convert(bytes).toString(); | ||
|
||
bool _isDirectoryPath(String path) { | ||
return path.endsWith('/'); | ||
} | ||
|
||
@override | ||
bool isAssetFilePath(String filePath) { | ||
// We don't care if an empty directory is added or removed, so ignore paths | ||
// that end with a '/'. | ||
return !_isDirectoryPath(filePath) && | ||
p.split(filePath).contains('flutter_assets'); | ||
} | ||
|
||
@override | ||
bool isDartFilePath(String filePath) { | ||
return p.basename(filePath) == 'app.so'; | ||
} | ||
|
||
@override | ||
bool isNativeFilePath(String filePath) { | ||
// TODO(bryanoltman): reenable this check once we can reliably report | ||
// native diffs | ||
// const nativeFileExtensions = ['.dll', '.exe']; | ||
// return nativeFileExtensions.contains(p.extension(filePath)); | ||
return false; | ||
} | ||
|
||
@override | ||
Future<FileSetDiff> changedFiles( | ||
String oldArchivePath, | ||
String newArchivePath, | ||
) async { | ||
var oldPathHashes = await fileHashes(File(oldArchivePath)); | ||
var newPathHashes = await fileHashes(File(newArchivePath)); | ||
|
||
oldPathHashes = await _updateHashes( | ||
archivePath: oldArchivePath, | ||
pathHashes: oldPathHashes, | ||
); | ||
newPathHashes = await _updateHashes( | ||
archivePath: newArchivePath, | ||
pathHashes: newPathHashes, | ||
); | ||
|
||
return FileSetDiff.fromPathHashes( | ||
oldPathHashes: oldPathHashes, | ||
newPathHashes: newPathHashes, | ||
); | ||
} | ||
|
||
/// Removes the timestamps from exe headers | ||
Future<PathHashes> _updateHashes({ | ||
required String archivePath, | ||
required PathHashes pathHashes, | ||
}) async { | ||
return Isolate.run(() async { | ||
for (final file in _exeFiles(archivePath)) { | ||
pathHashes[file.name] = await _sanitizedFileHash(file); | ||
} | ||
|
||
return pathHashes; | ||
}); | ||
} | ||
|
||
Future<String> _sanitizedFileHash(ArchiveFile file) async { | ||
final tempDir = Directory.systemTemp.createTempSync(); | ||
final outPath = p.join(tempDir.path, file.name); | ||
final outputStream = OutputFileStream(outPath); | ||
file.writeContent(outputStream); | ||
await outputStream.close(); | ||
|
||
final outFile = File(outPath); | ||
final bytes = PortableExecutable.bytesWithZeroedTimestamps(outFile); | ||
return _hash(bytes); | ||
} | ||
|
||
List<ArchiveFile> _exeFiles(String archivePath) { | ||
return ZipDecoder() | ||
.decodeStream(InputFileStream(archivePath)) | ||
.files | ||
.where((file) => file.isFile) | ||
.where( | ||
(file) => p.extension(file.name) == '.exe', | ||
) | ||
.toList(); | ||
} | ||
} |
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
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.