-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(std/utils/patch): preserve xattrs on linux
- add test verifying xattrs are preserved - bump file_cmds version, cleanup implementation - add patch_cmds build for macOS that does not preserve
- Loading branch information
1 parent
fab0654
commit f533c75
Showing
3 changed files
with
199 additions
and
18 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import * as bootstrap from "../bootstrap.tg.ts"; | ||
import * as std from "../tangram.ts"; | ||
|
||
export const metadata = { | ||
name: "patch_cmds", | ||
version: "66", | ||
}; | ||
|
||
export const source = tg.target(async () => { | ||
const { name, version } = metadata; | ||
const checksum = | ||
"sha256:ce39ccafd2690e1f7cf825d20043a42614814e6f7bc9f7638fbbec328a0f282d"; | ||
const owner = "apple-oss-distributions"; | ||
const repo = name; | ||
const tag = std.download.packageName({ name, version }); | ||
return std.download.fromGithub({ | ||
checksum, | ||
source: "tag", | ||
owner, | ||
repo, | ||
tag, | ||
}); | ||
}); | ||
|
||
export type Arg = { | ||
build?: string | undefined; | ||
env?: std.env.Arg; | ||
host?: string | undefined; | ||
sdk?: std.sdk.Arg | boolean; | ||
source?: tg.Directory; | ||
}; | ||
|
||
/** Produce an `patch` executable that preserves xattrs on macOS. */ | ||
export const macOsPatchCmds = tg.target(async (arg?: Arg) => { | ||
const build = arg?.build ?? (await std.triple.host()); | ||
const os = std.triple.os(build); | ||
|
||
// Assert that the system is macOS. | ||
if (os !== "darwin") { | ||
throw new Error(`patchCmds is only supported on macOS, detected ${os}.`); | ||
} | ||
|
||
const sourceDir = await source(); | ||
|
||
const script = tg` | ||
set -eux | ||
cp -R ${sourceDir}/patch/* . | ||
CC="cc" | ||
CFLAGS="-Wall -Oz" | ||
SOURCES="backupfile.c inp.c mkpath.c pch.c util.c patch.c vcs.c" | ||
OBJS=$(echo "$SOURCES" | sed 's/\.c$/\.o/') | ||
for src in $SOURCES; do | ||
obj=$(echo "$src" | sed 's/\.c$/\.o/') | ||
$CC $CFLAGS -c "$src" -o "$obj" | ||
if [ $? -ne 0 ]; then | ||
echo "Error compiling $src" | ||
exit 1 | ||
fi | ||
done | ||
mkdir -p $OUTPUT/bin | ||
$CC $CFLAGS $OBJS -o $OUTPUT/bin/patch | ||
if [ $? -ne 0 ]; then | ||
echo "Linking failed" | ||
exit 1 | ||
fi | ||
rm -f $OBJS | ||
`; | ||
|
||
const result = await tg | ||
.target(script, { | ||
host: std.triple.archAndOs(build), | ||
env: std.env.arg(arg.env ?? {}, bootstrap.sdk.env()), | ||
}) | ||
.then((target) => target.output()) | ||
.then(tg.Directory.expect); | ||
|
||
return result; | ||
}); | ||
|
||
export default macOsPatchCmds; |