Skip to content

Commit 91cf4f8

Browse files
committed
artifact: add path/binary/isInstalled static helpers
Give zig, rust, go_win and go_xcaddy a small consistent surface for locating the install directory and a binary inside it: - path(): install/extract root for the artifact - binary($name = '<default>'): full path to a binary under that root, picking the artifact's natural layout (top-level for zig, bin/ for rust and the go toolchains) - isInstalled(): is the default binary present on disk Callers that previously concatenated PKG_ROOT_PATH . '/zig/zig' (and the equivalents for the other artifacts) by hand can call the helpers instead, and any later code that needs to ask "is this toolchain available" can use isInstalled() without rebuilding the path.
1 parent 582a88e commit 91cf4f8

4 files changed

Lines changed: 68 additions & 0 deletions

File tree

src/Package/Artifact/go_win.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@
1515

1616
class go_win
1717
{
18+
/** GOROOT for the Windows Go toolchain. */
19+
public static function path(): string
20+
{
21+
return PKG_ROOT_PATH . '/go-win';
22+
}
23+
24+
/** Path to a binary inside go-win's bin/ (go.exe, gofmt.exe, …). */
25+
public static function binary(string $name = 'go.exe'): string
26+
{
27+
return self::path() . '/bin/' . $name;
28+
}
29+
30+
public static function isInstalled(): bool
31+
{
32+
return is_file(self::binary());
33+
}
34+
1835
#[CustomBinary('go-win', [
1936
'windows-x86_64',
2037
])]

src/Package/Artifact/go_xcaddy.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@
1717

1818
class go_xcaddy
1919
{
20+
/** GOROOT for the bundled Go toolchain used to build xcaddy. */
21+
public static function path(): string
22+
{
23+
return PKG_ROOT_PATH . '/go-xcaddy';
24+
}
25+
26+
/** Path to a binary inside go-xcaddy's bin/ (xcaddy, go, …). */
27+
public static function binary(string $name = 'xcaddy'): string
28+
{
29+
return self::path() . '/bin/' . $name;
30+
}
31+
32+
public static function isInstalled(): bool
33+
{
34+
return is_file(self::binary());
35+
}
36+
2037
#[CustomBinary('go-xcaddy', [
2138
'linux-x86_64',
2239
'linux-aarch64',

src/Package/Artifact/rust.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@
1616

1717
class rust
1818
{
19+
/** Install prefix the rust tarball's install.sh writes into. */
20+
public static function path(): string
21+
{
22+
return PKG_ROOT_PATH . '/rust';
23+
}
24+
25+
/** Path to a binary inside the rust install dir (cargo, rustc, rustup, …). */
26+
public static function binary(string $name = 'cargo'): string
27+
{
28+
return self::path() . '/bin/' . $name;
29+
}
30+
31+
public static function isInstalled(): bool
32+
{
33+
return is_file(self::binary());
34+
}
35+
1936
#[CustomBinary('rust', [
2037
'linux-x86_64',
2138
'linux-aarch64',

src/Package/Artifact/zig.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@
1515

1616
class zig
1717
{
18+
/** Directory zig extracts into. */
19+
public static function path(): string
20+
{
21+
return PKG_ROOT_PATH . '/zig';
22+
}
23+
24+
/** Path to a binary inside the zig install dir (zig, zig-cc, zig-c++, zig-ar, …). */
25+
public static function binary(string $name = 'zig'): string
26+
{
27+
return self::path() . '/' . $name;
28+
}
29+
30+
public static function isInstalled(): bool
31+
{
32+
return is_file(self::binary());
33+
}
34+
1835
#[CustomBinary('zig', [
1936
'linux-x86_64',
2037
'linux-aarch64',

0 commit comments

Comments
 (0)