Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.15.1

* Expand and upgrade some dependency versions.

## 2.15.0

* Allow `pkg.npmToken` to be null. This causes npm deployment to use the system
Expand Down
14 changes: 10 additions & 4 deletions lib/src/github.dart
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,17 @@ Future<void> _fixPermissions() async {
);
}

var archive = TarDecoder().decodeBytes(
var originalArchive = TarDecoder().decodeBytes(
GZipDecoder().decodeBytes(getResponse.bodyBytes),
);
for (var file in archive.files) {
var fixedArchive = Archive();
for (var file in originalArchive.files) {
// 0o755: ensure that the write permission bits aren't set for
// non-owners.
file.mode &= 493;
fixedArchive.add(
ArchiveFile.bytes(file.name, file.content)
..mode = file.mode & 493, // 0o755
);
}

var deleteResponse = await client.delete(
Expand Down Expand Up @@ -392,7 +396,9 @@ Future<void> _fixPermissions() async {
await _uploadToRelease(
release,
archiveName,
GZipEncoder().encode(TarEncoder().encode(archive))!,
GZipEncoder().encodeBytes(
TarEncoder().encodeBytes(fixedArchive),
),
);
print("Fixed $archiveName");
},
Expand Down
33 changes: 16 additions & 17 deletions lib/src/standalone.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,12 @@ Future<void> _buildDev() async {
/// Builds a package for the given [platform].
Future<void> _buildPackage(CliPlatform platform) async {
var archive = Archive()
..addFile(fileFromString("$standaloneName/src/LICENSE", await license));
..add(fileFromString("$standaloneName/src/LICENSE", await license));

var nativeExe = useExe.value(platform);

if (!(platform.useNative && nativeExe)) {
archive.addFile(
archive.add(
fileFromBytes(
"$standaloneName/src/dart${platform.binaryExtension}",
await _dartExecutable(platform),
Expand All @@ -238,15 +238,15 @@ Future<void> _buildPackage(CliPlatform platform) async {

for (var name in executables.value.keys) {
if (platform.useNative && nativeExe) {
archive.addFile(
archive.add(
file(
"$standaloneName/$name${platform.binaryExtension}",
"build/$name.native",
executable: true,
),
);
} else {
archive.addFile(
archive.add(
file(
"$standaloneName/src/$name.snapshot",
platform.useNative ? "build/$name.native" : "build/$name.snapshot",
Expand All @@ -259,7 +259,7 @@ Future<void> _buildPackage(CliPlatform platform) async {
// Do this separately from adding entrypoints because multiple executables
// may have the same entrypoint.
for (var name in executables.value.keys) {
archive.addFile(
archive.add(
fileFromString(
"$standaloneName/$name${platform.os.isWindows ? '.bat' : ''}",
renderTemplate(
Expand All @@ -276,17 +276,17 @@ Future<void> _buildPackage(CliPlatform platform) async {
if (platform.os.isWindows) {
var output = "$prefix.zip";
log("Creating $output...");
File(output).writeAsBytesSync(ZipEncoder().encode(archive)!);
File(output).writeAsBytesSync(ZipEncoder().encodeBytes(archive));
} else {
var output = "$prefix.tar.gz";
log("Creating $output...");
File(
output,
).writeAsBytesSync(GZipEncoder().encode(TarEncoder().encode(archive))!);
File(output).writeAsBytesSync(
GZipEncoder().encodeBytes(TarEncoder().encodeBytes(archive)),
);
}
}

/// Returns the binary contents of the `dart` or `dartaotruntime` exectuable for
/// Returns the binary contents of the `dart` or `dartaotruntime` executable for
/// the given [platform].
Future<List<int>> _dartExecutable(CliPlatform platform) async {
// If we're building for the same SDK we're using, load its executable from
Expand Down Expand Up @@ -336,11 +336,10 @@ Future<List<int>> _dartExecutable(CliPlatform platform) async {
var dartvm = dartVersion >= Version(3, 10, 0, pre: '0') ? 'dartvm' : 'dart';
var filename = "/bin/$dartvm${platform.binaryExtension}";
return (url.endsWith(".zip")
? ZipDecoder().decodeBytes(response.bodyBytes)
: TarDecoder().decodeBytes(
GZipDecoder().decodeBytes(response.bodyBytes),
))
.firstWhere((file) => file.name.endsWith(filename))
.content
as List<int>;
? ZipDecoder().decodeBytes(response.bodyBytes)
: TarDecoder().decodeBytes(
GZipDecoder().decodeBytes(response.bodyBytes),
))
.firstWhere((file) => file.name.endsWith(filename))
.content;
}
2 changes: 1 addition & 1 deletion lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ ArchiveFile fileFromBytes(
String path,
List<int> data, {
bool executable = false,
}) => ArchiveFile(path, data.length, data)
}) => ArchiveFile.bytes(path, data)
..mode = executable ? 493 : 420
..lastModTime = DateTime.now().millisecondsSinceEpoch ~/ 1000;

Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: cli_pkg
version: 2.15.0
version: 2.15.1
description: Grinder tasks for releasing Dart CLI packages.
homepage: https://github.com/google/dart_cli_pkg

environment:
sdk: ">=3.8.0 <4.0.0"

dependencies:
archive: ^3.1.2
archive: ^4.0.6
async: ^2.5.0
charcode: ^1.2.0
cli_util: ^0.4.0
Expand Down
19 changes: 11 additions & 8 deletions test/descriptor/archive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

import 'dart:io';
import 'dart:typed_data';

import 'package:archive/archive.dart';
import 'package:async/async.dart';
Expand All @@ -33,7 +34,7 @@ class ArchiveDescriptor extends Descriptor implements FileDescriptor {
/// this file.
Future<Archive> get archive async {
var archive = Archive();
(await _files(contents)).forEach(archive.addFile);
(await _files(contents)).forEach(archive.add);
return archive;
}

Expand Down Expand Up @@ -101,7 +102,7 @@ class ArchiveDescriptor extends Descriptor implements FileDescriptor {
}());

Future<void> validate([String? parent]) async {
// Access this first so we eaerly throw an error for a path with an invalid
// Access this first so we eagerly throw an error for a path with an invalid
// extension.
var decoder = _decodeFunction();

Expand Down Expand Up @@ -131,7 +132,7 @@ class ArchiveDescriptor extends Descriptor implements FileDescriptor {
archive.files.map((file) async {
var path = p.join(tempDir, file.name);
await Directory(p.dirname(path)).create(recursive: true);
await File(path).writeAsBytes(file.content as List<int>);
await File(path).writeAsBytes(file.content);
}),
);

Expand All @@ -155,23 +156,25 @@ class ArchiveDescriptor extends Descriptor implements FileDescriptor {
/// [name].
List<int> Function(Archive) _encodeFunction() {
if (name.endsWith('.zip')) {
return (archive) => ZipEncoder().encode(archive)!;
return ZipEncoder().encodeBytes;
} else if (name.endsWith('.tar')) {
return TarEncoder().encode;
return TarEncoder().encodeBytes;
} else if (name.endsWith('.tar.gz') ||
name.endsWith('.tar.gzip') ||
name.endsWith('.tgz')) {
return (archive) => GZipEncoder().encode(TarEncoder().encode(archive))!;
return (archive) =>
GZipEncoder().encodeBytes(TarEncoder().encodeBytes(archive));
} else if (name.endsWith('.tar.bz2') || name.endsWith('.tar.bzip2')) {
return (archive) => BZip2Encoder().encode(TarEncoder().encode(archive));
return (archive) =>
BZip2Encoder().encodeBytes(TarEncoder().encodeBytes(archive));
} else {
throw UnsupportedError('Unknown file format $name.');
}
}

/// Returns the function to use to decode this file from binary, based on its
/// [name].
Archive Function(List<int>) _decodeFunction() {
Archive Function(Uint8List) _decodeFunction() {
if (name.endsWith('.zip')) {
return ZipDecoder().decodeBytes;
} else if (name.endsWith('.tar')) {
Expand Down
8 changes: 4 additions & 4 deletions test/github_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,11 @@ void main() {
"GET",
"/assets/1/download/tar",
(request) => shelf.Response.ok(
GZipEncoder().encode(
TarEncoder().encode(
GZipEncoder().encodeBytes(
TarEncoder().encodeBytes(
Archive()
..addFile(fileFromString("foo", "foo contents")..mode = 495)
..addFile(fileFromString("bar", "bar contents")..mode = 506),
..add(fileFromString("foo", "foo contents")..mode = 495)
..add(fileFromString("bar", "bar contents")..mode = 506),
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Future<void> extract(String path, String destination) async {
for (var file in archive.files) {
var filePath = p.join(d.path(destination), file.name);
Directory(p.dirname(filePath)).createSync(recursive: true);
File(filePath).writeAsBytesSync(file.content as List<int>);
File(filePath).writeAsBytesSync(file.content);

// Mark the file executable if necessary.
if (!Platform.isWindows && file.mode & 1 == 1) {
Expand Down