Skip to content

Commit bd3f830

Browse files
committed
feat(xar): define package
1 parent 2dc96f2 commit bd3f830

File tree

2 files changed

+343
-0
lines changed

2 files changed

+343
-0
lines changed
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
diff --git a/configure.ac b/configure.ac
2+
index 3a36f42..fc53a55 100644
3+
--- a/configure.ac
4+
+++ b/configure.ac
5+
@@ -319,6 +319,16 @@ if test "x${have_libxml2}" = "x0" ; then
6+
AC_MSG_ERROR([Cannot build without libxml2])
7+
fi
8+
9+
+dnl
10+
+dnl Configure libcrypto (part of OpenSSL).
11+
+dnl
12+
+have_libcrypto="1"
13+
+AC_CHECK_HEADERS([openssl/evp.h], , [have_libcrypto="0"])
14+
+AC_CHECK_LIB([crypto], [OPENSSL_init_crypto], , [have_libcrypto="0"])
15+
+if test "x${have_libcrypto}" = "x0" ; then
16+
+ AC_MSG_ERROR([Cannot build withotu libcrypto (OpenSSL)])
17+
+fi
18+
+
19+
dnl
20+
dnl Configure libz.
21+
dnl
22+
diff --git a/include/xar.h.in b/include/xar.h.in
23+
index 054b742..77f0cad 100644
24+
--- a/include/xar.h.in
25+
+++ b/include/xar.h.in
26+
@@ -49,6 +49,9 @@ extern "C" {
27+
#include <sys/stat.h>
28+
29+
#ifdef __APPLE__
30+
+#include <AvailabilityMacros.h>
31+
+#endif
32+
+#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
33+
#import <os/availability.h>
34+
#else
35+
#define API_DEPRECATED(...)
36+
diff --git a/lib/archive.h b/lib/archive.h
37+
index f926245..c1096b2 100644
38+
--- a/lib/archive.h
39+
+++ b/lib/archive.h
40+
@@ -40,12 +40,12 @@
41+
#define _XAR_ARCHIVE_H_
42+
#include <zlib.h>
43+
#include <libxml/hash.h>
44+
-#ifdef __APPLE__
45+
+/* #ifdef __APPLE__
46+
#include <CommonCrypto/CommonDigest.h>
47+
#include <CommonCrypto/CommonDigestSPI.h>
48+
-#else
49+
+#else */
50+
#include <openssl/evp.h>
51+
-#endif
52+
+/* #endif */
53+
#include <sys/types.h>
54+
#include <sys/stat.h>
55+
#include "xar.h"
56+
diff --git a/lib/filetree.c b/lib/filetree.c
57+
index f31682a..6de7bdf 100644
58+
--- a/lib/filetree.c
59+
+++ b/lib/filetree.c
60+
@@ -46,6 +46,7 @@
61+
#include <libxml/xmlwriter.h>
62+
#include <libxml/xmlreader.h>
63+
#include <libxml/xmlstring.h>
64+
+#include <libxml/encoding.h>
65+
66+
#ifndef HAVE_ASPRINTF
67+
#include "asprintf.h"
68+
@@ -752,7 +753,8 @@ int xar_file_equals_file(xar_file_t f1, xar_file_t f2)
69+
size_t fspath1_size = 0, fspath2_size = 0;
70+
size_t ns1_size = 0, ns2_size = 0;
71+
const struct __xar_file_t * child1 = NULL, * child2 = NULL;
72+
- const uint keys_to_ignore_count = 1;
73+
+ // const uint keys_to_ignore_count = 1;
74+
+ #define keys_to_ignore_count 1
75+
char * keys_to_ignore[keys_to_ignore_count] = { "id" }; // ID is allowed ot mismatch
76+
77+
// If the two pointers match, call it the same.
78+
diff --git a/lib/hash.c b/lib/hash.c
79+
index 66876ad..6e055da 100644
80+
--- a/lib/hash.c
81+
+++ b/lib/hash.c
82+
@@ -41,12 +41,14 @@
83+
#include <string.h>
84+
#include <sys/types.h>
85+
#include <zlib.h>
86+
+/*
87+
#ifdef __APPLE__
88+
#include <CommonCrypto/CommonDigest.h>
89+
#include <CommonCrypto/CommonDigestSPI.h>
90+
#else
91+
+*/
92+
#include <openssl/evp.h>
93+
-#endif
94+
+/* #endif */
95+
96+
#include "xar.h"
97+
#include "hash.h"
98+
@@ -57,7 +59,7 @@
99+
100+
101+
#pragma mark Hash Wrapper Object
102+
-
103+
+/*
104+
#ifdef __APPLE__
105+
106+
CCDigestRef digestRef_from_name(const char* name, unsigned int *outHashSize) {
107+
@@ -89,17 +91,19 @@ CCDigestRef digestRef_from_name(const char* name, unsigned int *outHashSize) {
108+
return result;
109+
}
110+
#endif // __APPLE__
111+
-
112+
+*/
113+
114+
struct __xar_hash_t {
115+
const char *digest_name;
116+
void *context;
117+
+/*
118+
#ifdef __APPLE__
119+
CCDigestRef digest;
120+
#else
121+
- EVP_MD_CTX digest;
122+
+*/
123+
+ EVP_MD_CTX *digest;
124+
const EVP_MD *type;
125+
-#endif
126+
+/* #endif */
127+
unsigned int length;
128+
};
129+
130+
@@ -112,14 +116,16 @@ xar_hash_t xar_hash_new(const char *digest_name, void *context) {
131+
132+
if( context )
133+
HASH_CTX(hash)->context = context;
134+
-
135+
+/*
136+
#ifdef __APPLE__
137+
HASH_CTX(hash)->digest = digestRef_from_name(digest_name, &HASH_CTX(hash)->length);
138+
#else
139+
+*/
140+
OpenSSL_add_all_digests();
141+
HASH_CTX(hash)->type = EVP_get_digestbyname(digest_name);
142+
- EVP_DigestInit(&HASH_CTX(hash)->digest, HASH_CTX(hash)->type);
143+
-#endif
144+
+ HASH_CTX(hash)->digest = EVP_MD_CTX_create();
145+
+ EVP_DigestInit(HASH_CTX(hash)->digest, HASH_CTX(hash)->type);
146+
+/* #endif */
147+
148+
HASH_CTX(hash)->digest_name = strdup(digest_name);
149+
150+
@@ -135,28 +141,34 @@ const char *xar_hash_get_digest_name(xar_hash_t hash) {
151+
}
152+
153+
void xar_hash_update(xar_hash_t hash, void *buffer, size_t nbyte) {
154+
+/*
155+
#ifdef __APPLE__
156+
CCDigestUpdate(HASH_CTX(hash)->digest, buffer, nbyte);
157+
#else
158+
- EVP_DigestUpdate(&HASH_CTX(hash)->digest, buffer, nbyte);
159+
-#endif
160+
+*/
161+
+ EVP_DigestUpdate(HASH_CTX(hash)->digest, buffer, nbyte);
162+
+/* #endif */
163+
}
164+
165+
void *xar_hash_finish(xar_hash_t hash, size_t *nbyte) {
166+
+/*
167+
#ifdef __APPLE__
168+
void *buffer = calloc(1, CC_SHA512_DIGEST_LENGTH); // current biggest digest size This is what OpenSSL uses
169+
#else
170+
+*/
171+
void *buffer = calloc(1, EVP_MAX_MD_SIZE);
172+
-#endif
173+
+/* #endif */
174+
if( ! buffer )
175+
return NULL;
176+
-
177+
+/*
178+
#ifdef __APPLE__
179+
CCDigestFinal(HASH_CTX(hash)->digest, buffer);
180+
CCDigestDestroy(HASH_CTX(hash)->digest);
181+
#else
182+
- EVP_DigestFinal(&HASH_CTX(hash)->digest, buffer, &HASH_CTX(hash)->length);
183+
-#endif
184+
+*/
185+
+ EVP_DigestFinal(HASH_CTX(hash)->digest, buffer, &HASH_CTX(hash)->length);
186+
+ EVP_MD_CTX_destroy(HASH_CTX(hash)->digest);
187+
+/* #endif */
188+
189+
*nbyte = HASH_CTX(hash)->length;
190+
free((void *)HASH_CTX(hash)->digest_name);
191+
diff --git a/lib/linuxattr.c b/lib/linuxattr.c
192+
index 0fec2bb..58ee6a8 100644
193+
--- a/lib/linuxattr.c
194+
+++ b/lib/linuxattr.c
195+
@@ -226,7 +226,7 @@ int32_t xar_linuxattr_extract(xar_t x, xar_file_t f, const char* file, char *buf
196+
if( statfs(file, &sfs) != 0 ) {
197+
char *tmp, *bname;
198+
tmp = strdup(file);
199+
- bname = safe_dirname(tmp);
200+
+ bname = xar_safe_dirname(tmp);
201+
statfs(bname, &sfs);
202+
free(tmp);
203+
free(bname);
204+
diff --git a/src/xar.c b/src/xar.c
205+
index 9977e8a..4e01f4d 100644
206+
--- a/src/xar.c
207+
+++ b/src/xar.c
208+
@@ -51,7 +51,7 @@
209+
#include <time.h>
210+
#include "xar_internal.h"
211+
#include "config.h"
212+
-#include "filetree.h"
213+
+#include "../lib/filetree.h"
214+
#include "util.h"
215+
#define SYMBOLIC 1
216+
#define NUMERIC 2

packages/xar/tangram.ts

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import * as std from "std" with { local: "../std" };
2+
import * as openssl from "openssl" with { local: "../openssl" };
3+
import * as libiconv from "libiconv" with { local: "../libiconv" };
4+
import * as libxml2 from "libxml2" with { local: "../libxml2" };
5+
import * as xz from "xz" with { local: "../xz" };
6+
import * as zlib from "zlib" with { local: "../zlib" };
7+
8+
export const metadata = {
9+
homepage: "https://github.com/apple-oss-distributions/xar",
10+
hostPlatforms: ["aarch64-darwin", "x86_64-darwin"],
11+
license: "BSD-3-Clause",
12+
name: "xar",
13+
repository: "https://github.com/mackyle/xar/tree/master",
14+
version: "498",
15+
provides: {
16+
binaries: ["xar"],
17+
},
18+
};
19+
20+
// NOTE - patches lifted from MacPorts and combined: https://github.com/macports/macports-ports/tree/master/archivers/xar/files
21+
import patches from "./patches" with { type: "directory" };
22+
23+
export const source = async (): Promise<tg.Directory> => {
24+
const { name, version } = metadata;
25+
const checksum =
26+
"sha256:9cee4f80b96cf592ccc545a4fdd51e4da4a5bd3b4734901637d67b043eff3c75";
27+
const owner = "apple-oss-distributions";
28+
const repo = name;
29+
const tag = `${name}-${version}`;
30+
return await std.download
31+
.fromGithub({
32+
checksum,
33+
owner,
34+
repo,
35+
source: "tag",
36+
tag,
37+
})
38+
.then((d) => d.get(name))
39+
.then(tg.Directory.expect)
40+
.then((d) => std.patch(d, patches));
41+
};
42+
43+
export type Arg = {
44+
autotools?: std.autotools.Arg;
45+
build?: string;
46+
dependencies?: {
47+
openssl?: std.args.DependencyArg<openssl.Arg>;
48+
libiconv?: std.args.DependencyArg<libiconv.Arg>;
49+
libxml2?: std.args.DependencyArg<libxml2.Arg>;
50+
xz?: std.args.DependencyArg<xz.Arg>;
51+
zlib?: std.args.DependencyArg<zlib.Arg>;
52+
};
53+
env?: std.env.Arg;
54+
host?: string;
55+
sdk?: std.sdk.Arg;
56+
source?: tg.Directory;
57+
};
58+
59+
export const build = async (...args: std.Args<Arg>) => {
60+
const {
61+
autotools = {},
62+
build,
63+
dependencies: dependencyArgs = {},
64+
env: env_,
65+
host,
66+
sdk,
67+
source: source_,
68+
} = await std.packages.applyArgs<Arg>(...args);
69+
70+
std.assert.supportedHost(host, metadata);
71+
72+
const processDependency = (dep: any) =>
73+
std.env.envArgFromDependency(build, env_, host, sdk, dep);
74+
75+
const deps = [
76+
std.env.buildDependency(libxml2.build, dependencyArgs.libxml2),
77+
std.env.runtimeDependency(libiconv.build, dependencyArgs.libiconv),
78+
std.env.runtimeDependency(libxml2.build, dependencyArgs.libxml2),
79+
std.env.runtimeDependency(openssl.build, dependencyArgs.openssl),
80+
std.env.runtimeDependency(xz.build, dependencyArgs.xz),
81+
std.env.runtimeDependency(zlib.build, dependencyArgs.zlib),
82+
];
83+
84+
const envs = [
85+
...deps.map(processDependency),
86+
{
87+
// NOTE - this define is included in libxml/encoding.h but not expanding.
88+
CFLAGS: tg.Mutation.suffix("-DUTF8Toisolat1=xmlUTF8ToIsolat1", " "),
89+
},
90+
env_,
91+
];
92+
const env = std.env.arg(...envs);
93+
94+
const configure = {
95+
pre: "./autogen.sh",
96+
};
97+
const phases = { configure };
98+
99+
return std.autotools.build(
100+
{
101+
...(await std.triple.rotate({ build, host })),
102+
buildInTree: true,
103+
developmentTools: true,
104+
env,
105+
phases,
106+
sdk,
107+
// setRuntimeLibraryPath: true,
108+
source: source_ ?? source(),
109+
},
110+
autotools,
111+
);
112+
};
113+
114+
export default build;
115+
116+
export const test = async () => {
117+
const spec = {
118+
...std.assert.defaultSpec(metadata),
119+
binaries: [
120+
{
121+
name: "xar",
122+
testPredicate: (stdout: string) => stdout.includes("xar 1.8dev"),
123+
},
124+
],
125+
};
126+
return await std.assert.pkg(build, spec);
127+
};

0 commit comments

Comments
 (0)