Skip to content

Commit c7d5263

Browse files
committed
Add scripts to verify example binaries
1 parent 0538ac7 commit c7d5263

File tree

3 files changed

+96
-3
lines changed

3 files changed

+96
-3
lines changed

packages/node-addon-examples/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
"name": "react-native-node-addon-examples",
33
"private": true,
44
"scripts": {
5-
"e2e": "rm -rf tests && npm run copy-examples && npm run gyp-to-cmake && npm run build",
65
"copy-examples": "tsx scripts/copy-examples.mts",
76
"gyp-to-cmake": "gyp-to-cmake ./examples",
8-
"build": "tsx scripts/build-examples.mts"
7+
"build": "tsx scripts/build-examples.mts",
8+
"copy-and-build": "npm run copy-examples && npm run gyp-to-cmake && npm run build",
9+
"verify": "tsx scripts/verify-prebuilds.mts",
10+
"test": "npm run copy-and-build && npm run verify"
911
},
1012
"devDependencies": {
1113
"node-addon-examples": "github:nodejs/node-addon-examples#4213d4c9d07996ae68629c67926251e117f8e52a",

packages/node-addon-examples/scripts/build-examples.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const projectDirectories = findCMakeProjects();
77
for (const projectDirectory of projectDirectories) {
88
console.log(`Running "react-native-node-api-cmake" in ${projectDirectory}`);
99
execSync(
10-
"react-native-node-api-cmake --triplet aarch64-linux-android --triplet arm64-apple-ios-sim",
10+
"react-native-node-api-cmake --android --apple",
11+
// "react-native-node-api-cmake --triplet aarch64-linux-android --triplet arm64-apple-ios-sim",
1112
{
1213
cwd: projectDirectory,
1314
stdio: "inherit",
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import fs from "node:fs";
2+
import assert from "node:assert/strict";
3+
import path from "node:path";
4+
5+
import { EXAMPLES_DIR } from "./cmake-projects.mjs";
6+
7+
const EXPECTED_ANDROID_ARCHS = ["armeabi-v7a", "arm64-v8a", "x86_64", "x86"];
8+
9+
const EXPECTED_XCFRAMEWORK_PLATFORMS = [
10+
"ios-arm64",
11+
"ios-arm64-simulator",
12+
"macos-arm64_x86_64",
13+
"tvos-arm64",
14+
"tvos-arm64-simulator",
15+
"xros-arm64",
16+
"xros-arm64-simulator",
17+
];
18+
19+
async function verifyAndroidDirectory(dirent: fs.Dirent) {
20+
for (const arch of EXPECTED_ANDROID_ARCHS) {
21+
const archDir = path.join(dirent.parentPath, dirent.name, arch);
22+
for (const file of await fs.promises.readdir(archDir, {
23+
withFileTypes: true,
24+
})) {
25+
assert(file.isFile());
26+
assert(
27+
!file.name.endsWith(".node"),
28+
`Unexpected .node file: ${path.join(file.parentPath, file.name)}`
29+
);
30+
}
31+
}
32+
}
33+
34+
async function verifyXcframework(dirent: fs.Dirent) {
35+
for (const arch of EXPECTED_XCFRAMEWORK_PLATFORMS) {
36+
const archDir = path.join(dirent.parentPath, dirent.name, arch);
37+
for (const file of await fs.promises.readdir(archDir, {
38+
withFileTypes: true,
39+
})) {
40+
assert(
41+
file.isDirectory(),
42+
"Expected only directories in xcframework arch directory"
43+
);
44+
assert(file.name.endsWith(".framework"), "Expected framework directory");
45+
const frameworkDir = path.join(file.parentPath, file.name);
46+
for (const file of await fs.promises.readdir(frameworkDir, {
47+
withFileTypes: true,
48+
})) {
49+
if (file.isDirectory()) {
50+
assert.equal(
51+
file.name,
52+
"Headers",
53+
"Unexpected directory in xcframework"
54+
);
55+
} else {
56+
assert(
57+
file.isFile(),
58+
"Expected only directory and files in framework"
59+
);
60+
if (file.name === "Info.plist") {
61+
// TODO: Verify the contents of the Info.plist file
62+
continue;
63+
} else {
64+
assert(
65+
!file.name.endsWith(".node"),
66+
`Didn't expected a .node file in xcframework: ${path.join(
67+
frameworkDir,
68+
file.name
69+
)}`
70+
);
71+
}
72+
}
73+
}
74+
}
75+
}
76+
}
77+
78+
for (const dirent of await fs.promises.readdir(EXAMPLES_DIR, {
79+
withFileTypes: true,
80+
recursive: true,
81+
})) {
82+
if (!dirent.isDirectory()) {
83+
continue;
84+
}
85+
if (dirent.name.endsWith(".android.node")) {
86+
await verifyAndroidDirectory(dirent);
87+
} else if (dirent.name.endsWith(".xcframework")) {
88+
await verifyXcframework(dirent);
89+
}
90+
}

0 commit comments

Comments
 (0)