mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 01:04:43 +01:00
build: packages now require fingerprint
also the name must be an enum literal. delete some .tar.gz test data. Test data should be in text form when it can be, and this could definitely be.
This commit is contained in:
parent
64dc1cdad8
commit
df64a3a368
6 changed files with 7 additions and 163 deletions
|
|
@ -60,8 +60,6 @@ omit_missing_hash_error: bool,
|
|||
/// which specifies inclusion rules. This is intended to be true for the first
|
||||
/// fetch task and false for the recursive dependencies.
|
||||
allow_missing_paths_field: bool,
|
||||
allow_missing_fingerprint: bool,
|
||||
allow_name_string: bool,
|
||||
/// If true and URL points to a Git repository, will use the latest commit.
|
||||
use_latest_commit: bool,
|
||||
|
||||
|
|
@ -675,8 +673,6 @@ fn loadManifest(f: *Fetch, pkg_root: Cache.Path) RunError!void {
|
|||
|
||||
f.manifest = try Manifest.parse(arena, ast.*, rng.interface(), .{
|
||||
.allow_missing_paths_field = f.allow_missing_paths_field,
|
||||
.allow_missing_fingerprint = f.allow_missing_fingerprint,
|
||||
.allow_name_string = f.allow_name_string,
|
||||
});
|
||||
const manifest = &f.manifest.?;
|
||||
|
||||
|
|
@ -794,8 +790,6 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
|
|||
.job_queue = f.job_queue,
|
||||
.omit_missing_hash_error = false,
|
||||
.allow_missing_paths_field = true,
|
||||
.allow_missing_fingerprint = true,
|
||||
.allow_name_string = true,
|
||||
.use_latest_commit = false,
|
||||
|
||||
.package_root = undefined,
|
||||
|
|
@ -2049,130 +2043,6 @@ const UnpackResult = struct {
|
|||
}
|
||||
};
|
||||
|
||||
test "tarball with duplicate paths" {
|
||||
// This tarball has duplicate path 'dir1/file1' to simulate case sensitve
|
||||
// file system on any file sytstem.
|
||||
//
|
||||
// duplicate_paths/
|
||||
// duplicate_paths/dir1/
|
||||
// duplicate_paths/dir1/file1
|
||||
// duplicate_paths/dir1/file1
|
||||
// duplicate_paths/build.zig.zon
|
||||
// duplicate_paths/src/
|
||||
// duplicate_paths/src/main.zig
|
||||
// duplicate_paths/src/root.zig
|
||||
// duplicate_paths/build.zig
|
||||
//
|
||||
|
||||
const gpa = std.testing.allocator;
|
||||
const io = std.testing.io;
|
||||
var tmp = std.testing.tmpDir(.{});
|
||||
defer tmp.cleanup();
|
||||
|
||||
const tarball_name = "duplicate_paths.tar.gz";
|
||||
try saveEmbedFile(io, tarball_name, tmp.dir);
|
||||
const tarball_path = try std.fmt.allocPrint(gpa, ".zig-cache/tmp/{s}/{s}", .{ tmp.sub_path, tarball_name });
|
||||
defer gpa.free(tarball_path);
|
||||
|
||||
// Run tarball fetch, expect to fail
|
||||
var fb: TestFetchBuilder = undefined;
|
||||
var fetch = try fb.build(gpa, io, tmp.dir, tarball_path);
|
||||
defer fb.deinit();
|
||||
try std.testing.expectError(error.FetchFailed, fetch.run());
|
||||
|
||||
try fb.expectFetchErrors(1,
|
||||
\\error: unable to unpack tarball
|
||||
\\ note: unable to create file 'dir1/file1': PathAlreadyExists
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "tarball with excluded duplicate paths" {
|
||||
// Same as previous tarball but has build.zig.zon wich excludes 'dir1'.
|
||||
//
|
||||
// .paths = .{
|
||||
// "build.zig",
|
||||
// "build.zig.zon",
|
||||
// "src",
|
||||
// }
|
||||
//
|
||||
|
||||
const gpa = std.testing.allocator;
|
||||
const io = std.testing.io;
|
||||
var tmp = std.testing.tmpDir(.{});
|
||||
defer tmp.cleanup();
|
||||
|
||||
const tarball_name = "duplicate_paths_excluded.tar.gz";
|
||||
try saveEmbedFile(io, tarball_name, tmp.dir);
|
||||
const tarball_path = try std.fmt.allocPrint(gpa, ".zig-cache/tmp/{s}/{s}", .{ tmp.sub_path, tarball_name });
|
||||
defer gpa.free(tarball_path);
|
||||
|
||||
// Run tarball fetch, should succeed
|
||||
var fb: TestFetchBuilder = undefined;
|
||||
var fetch = try fb.build(gpa, io, tmp.dir, tarball_path);
|
||||
defer fb.deinit();
|
||||
try fetch.run();
|
||||
|
||||
const hex_digest = Package.multiHashHexDigest(fetch.computed_hash.digest);
|
||||
try std.testing.expectEqualStrings(
|
||||
"12200bafe035cbb453dd717741b66e9f9d1e6c674069d06121dafa1b2e62eb6b22da",
|
||||
&hex_digest,
|
||||
);
|
||||
|
||||
const expected_files: []const []const u8 = &.{
|
||||
"build.zig",
|
||||
"build.zig.zon",
|
||||
"src/main.zig",
|
||||
"src/root.zig",
|
||||
};
|
||||
try fb.expectPackageFiles(expected_files);
|
||||
}
|
||||
|
||||
test "tarball without root folder" {
|
||||
// Tarball with root folder. Manifest excludes dir1 and dir2.
|
||||
//
|
||||
// build.zig
|
||||
// build.zig.zon
|
||||
// dir1/
|
||||
// dir1/file2
|
||||
// dir1/file1
|
||||
// dir2/
|
||||
// dir2/file2
|
||||
// src/
|
||||
// src/main.zig
|
||||
//
|
||||
|
||||
const gpa = std.testing.allocator;
|
||||
const io = std.testing.io;
|
||||
|
||||
var tmp = std.testing.tmpDir(.{});
|
||||
defer tmp.cleanup();
|
||||
|
||||
const tarball_name = "no_root.tar.gz";
|
||||
try saveEmbedFile(io, tarball_name, tmp.dir);
|
||||
const tarball_path = try std.fmt.allocPrint(gpa, ".zig-cache/tmp/{s}/{s}", .{ tmp.sub_path, tarball_name });
|
||||
defer gpa.free(tarball_path);
|
||||
|
||||
// Run tarball fetch, should succeed
|
||||
var fb: TestFetchBuilder = undefined;
|
||||
var fetch = try fb.build(gpa, io, tmp.dir, tarball_path);
|
||||
defer fb.deinit();
|
||||
try fetch.run();
|
||||
|
||||
const hex_digest = Package.multiHashHexDigest(fetch.computed_hash.digest);
|
||||
try std.testing.expectEqualStrings(
|
||||
"12209f939bfdcb8b501a61bb4a43124dfa1b2848adc60eec1e4624c560357562b793",
|
||||
&hex_digest,
|
||||
);
|
||||
|
||||
const expected_files: []const []const u8 = &.{
|
||||
"build.zig",
|
||||
"build.zig.zon",
|
||||
"src/main.zig",
|
||||
};
|
||||
try fb.expectPackageFiles(expected_files);
|
||||
}
|
||||
|
||||
test "set executable bit based on file content" {
|
||||
if (!Io.File.Permissions.has_executable_bit) return error.SkipZigTest;
|
||||
const gpa = std.testing.allocator;
|
||||
|
|
@ -2288,8 +2158,6 @@ const TestFetchBuilder = struct {
|
|||
.job_queue = &self.job_queue,
|
||||
.omit_missing_hash_error = true,
|
||||
.allow_missing_paths_field = false,
|
||||
.allow_missing_fingerprint = true, // so we can keep using the old testdata .tar.gz
|
||||
.allow_name_string = true, // so we can keep using the old testdata .tar.gz
|
||||
.use_latest_commit = true,
|
||||
|
||||
.package_root = undefined,
|
||||
|
|
|
|||
BIN
src/Package/Fetch/testdata/duplicate_paths.tar.gz
vendored
BIN
src/Package/Fetch/testdata/duplicate_paths.tar.gz
vendored
Binary file not shown.
Binary file not shown.
BIN
src/Package/Fetch/testdata/no_root.tar.gz
vendored
BIN
src/Package/Fetch/testdata/no_root.tar.gz
vendored
Binary file not shown.
|
|
@ -49,10 +49,6 @@ arena_state: std.heap.ArenaAllocator.State,
|
|||
|
||||
pub const ParseOptions = struct {
|
||||
allow_missing_paths_field: bool = false,
|
||||
/// Deprecated, to be removed after 0.14.0 is tagged.
|
||||
allow_name_string: bool = true,
|
||||
/// Deprecated, to be removed after 0.14.0 is tagged.
|
||||
allow_missing_fingerprint: bool = true,
|
||||
};
|
||||
|
||||
pub const Error = Allocator.Error;
|
||||
|
|
@ -77,8 +73,6 @@ pub fn parse(gpa: Allocator, ast: Ast, rng: std.Random, options: ParseOptions) E
|
|||
.dependencies_node = .none,
|
||||
.paths = .{},
|
||||
.allow_missing_paths_field = options.allow_missing_paths_field,
|
||||
.allow_name_string = options.allow_name_string,
|
||||
.allow_missing_fingerprint = options.allow_missing_fingerprint,
|
||||
.minimum_zig_version = null,
|
||||
.buf = .{},
|
||||
};
|
||||
|
|
@ -151,8 +145,6 @@ const Parse = struct {
|
|||
dependencies_node: Ast.Node.OptionalIndex,
|
||||
paths: std.StringArrayHashMapUnmanaged(void),
|
||||
allow_missing_paths_field: bool,
|
||||
allow_name_string: bool,
|
||||
allow_missing_fingerprint: bool,
|
||||
minimum_zig_version: ?std.SemanticVersion,
|
||||
|
||||
const InnerError = error{ ParseFailure, OutOfMemory };
|
||||
|
|
@ -221,12 +213,10 @@ const Parse = struct {
|
|||
});
|
||||
}
|
||||
p.id = n.id;
|
||||
} else if (!p.allow_missing_fingerprint) {
|
||||
} else {
|
||||
try appendError(p, main_token, "missing top-level 'fingerprint' field; suggested value: 0x{x}", .{
|
||||
Package.Fingerprint.generate(rng, p.name).int(),
|
||||
});
|
||||
} else {
|
||||
p.id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -395,19 +385,6 @@ const Parse = struct {
|
|||
const ast = p.ast;
|
||||
const main_token = ast.nodeMainToken(node);
|
||||
|
||||
if (p.allow_name_string and ast.nodeTag(node) == .string_literal) {
|
||||
const name = try parseString(p, node);
|
||||
if (!std.zig.isValidId(name))
|
||||
return fail(p, main_token, "name must be a valid bare zig identifier (hint: switch from string to enum literal)", .{});
|
||||
|
||||
if (name.len > max_name_len)
|
||||
return fail(p, main_token, "name '{f}' exceeds max length of {d}", .{
|
||||
std.zig.fmtId(name), max_name_len,
|
||||
});
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
if (ast.nodeTag(node) != .enum_literal)
|
||||
return fail(p, main_token, "expected enum literal", .{});
|
||||
|
||||
|
|
@ -606,7 +583,8 @@ test "basic" {
|
|||
|
||||
const example =
|
||||
\\.{
|
||||
\\ .name = "foo",
|
||||
\\ .name = .foo,
|
||||
\\ .fingerprint = 0x8c736521490b23df,
|
||||
\\ .version = "3.2.1",
|
||||
\\ .paths = .{""},
|
||||
\\ .dependencies = .{
|
||||
|
|
@ -656,7 +634,8 @@ test "minimum_zig_version" {
|
|||
|
||||
const example =
|
||||
\\.{
|
||||
\\ .name = "foo",
|
||||
\\ .name = .foo,
|
||||
\\ .fingerprint = 0x8c736521490b23df,
|
||||
\\ .version = "3.2.1",
|
||||
\\ .paths = .{""},
|
||||
\\ .minimum_zig_version = "0.11.1",
|
||||
|
|
@ -690,7 +669,8 @@ test "minimum_zig_version - invalid version" {
|
|||
|
||||
const example =
|
||||
\\.{
|
||||
\\ .name = "foo",
|
||||
\\ .name = .foo,
|
||||
\\ .fingerprint = 0x8c736521490b23df,
|
||||
\\ .version = "3.2.1",
|
||||
\\ .minimum_zig_version = "X.11.1",
|
||||
\\ .paths = .{""},
|
||||
|
|
|
|||
|
|
@ -5285,8 +5285,6 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
|
|||
.job_queue = &job_queue,
|
||||
.omit_missing_hash_error = true,
|
||||
.allow_missing_paths_field = false,
|
||||
.allow_missing_fingerprint = false,
|
||||
.allow_name_string = false,
|
||||
.use_latest_commit = false,
|
||||
|
||||
.package_root = undefined,
|
||||
|
|
@ -7044,8 +7042,6 @@ fn cmdFetch(
|
|||
.job_queue = &job_queue,
|
||||
.omit_missing_hash_error = true,
|
||||
.allow_missing_paths_field = false,
|
||||
.allow_missing_fingerprint = true,
|
||||
.allow_name_string = true,
|
||||
.use_latest_commit = true,
|
||||
|
||||
.package_root = undefined,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue