From 34ce0cd38b8ae461e039a46d9dc340058309aa07 Mon Sep 17 00:00:00 2001 From: Im-Beast Date: Tue, 10 Dec 2024 23:34:14 +0100 Subject: tests: add file data for more targets --- tests/deno.lock | 14 +++++-- tests/download_deps.ts | 103 ++++++++++++++++++++++++++++++++++++++++--------- tests/utils.ts | 11 +++--- 3 files changed, 101 insertions(+), 27 deletions(-) diff --git a/tests/deno.lock b/tests/deno.lock index 8d368f6..5ed1a7a 100644 --- a/tests/deno.lock +++ b/tests/deno.lock @@ -4,8 +4,10 @@ "jsr:@david/dax@*": "0.42.0", "jsr:@david/path@0.2": "0.2.0", "jsr:@david/which@~0.4.1": "0.4.1", + "jsr:@std/assert@*": "0.221.0", "jsr:@std/assert@0.221": "0.221.0", "jsr:@std/bytes@0.221": "0.221.0", + "jsr:@std/fmt@0.221": "0.221.0", "jsr:@std/fmt@1": "1.0.2", "jsr:@std/fs@1": "1.0.5", "jsr:@std/io@0.221": "0.221.0", @@ -20,7 +22,7 @@ "dependencies": [ "jsr:@david/path", "jsr:@david/which", - "jsr:@std/fmt", + "jsr:@std/fmt@1", "jsr:@std/fs", "jsr:@std/io", "jsr:@std/path@1", @@ -38,11 +40,17 @@ "integrity": "896a682b111f92ab866cc70c5b4afab2f5899d2f9bde31ed00203b9c250f225e" }, "@std/assert@0.221.0": { - "integrity": "a5f1aa6e7909dbea271754fd4ab3f4e687aeff4873b4cef9a320af813adb489a" + "integrity": "a5f1aa6e7909dbea271754fd4ab3f4e687aeff4873b4cef9a320af813adb489a", + "dependencies": [ + "jsr:@std/fmt@0.221" + ] }, "@std/bytes@0.221.0": { "integrity": "64a047011cf833890a4a2ab7293ac55a1b4f5a050624ebc6a0159c357de91966" }, + "@std/fmt@0.221.0": { + "integrity": "379fed69bdd9731110f26b9085aeb740606b20428ce6af31ef6bd45ef8efa62a" + }, "@std/fmt@1.0.2": { "integrity": "87e9dfcdd3ca7c066e0c3c657c1f987c82888eb8103a3a3baa62684ffeb0f7a7" }, @@ -55,7 +63,7 @@ "@std/io@0.221.0": { "integrity": "faf7f8700d46ab527fa05cc6167f4b97701a06c413024431c6b4d207caa010da", "dependencies": [ - "jsr:@std/assert", + "jsr:@std/assert@0.221", "jsr:@std/bytes" ] }, diff --git a/tests/download_deps.ts b/tests/download_deps.ts index 81d7f9d..3ed4e25 100644 --- a/tests/download_deps.ts +++ b/tests/download_deps.ts @@ -1,16 +1,10 @@ import { join, resolve } from "jsr:@std/path"; -import { getMoneroCTags } from "./utils.ts"; +import { Coin, getMoneroCTags } from "./utils.ts"; export type Target = `${typeof Deno["build"]["os"]}_${typeof Deno["build"]["arch"]}`; -export const target = (() => { - let target: Target = `${Deno.build.os}_${Deno.build.arch}`; - const FORCED_TARGET = Deno.env.get("FORCED_TARGET"); - if (FORCED_TARGET) target = FORCED_TARGET as Target; - return target; -})(); - interface FileInfo { + overrideMirrors?: string[]; name: string; sha256?: string; } @@ -23,7 +17,10 @@ interface DownloadInfo { outDir?: string; } -export function getFileInfo(downloadInfo: DownloadInfo): FileInfo { +export function getFileInfo( + downloadInfo: DownloadInfo, + target: Target = `${Deno.build.os}_${Deno.build.arch}`, +): FileInfo { const fileInfo = "name" in downloadInfo.file ? downloadInfo.file : downloadInfo.file[target]; if (!fileInfo) { throw new Error(`No fileInfo set for target: ${target}`); @@ -36,8 +33,11 @@ async function sha256(buffer: Uint8Array): Promise { return Array.from(hashed).map((i) => i.toString(16).padStart(2, "0")).join(""); } -let outDir = "./tests/dependencies"; export async function downloadDependencies(...infos: DownloadInfo[]): Promise { + return await downloadFiles("./tests/dependencies", `${Deno.build.os}_${Deno.build.arch}`, ...infos); +} + +export async function downloadFiles(outDir: string, target: Target, ...infos: DownloadInfo[]): Promise { try { await Deno.mkdir(outDir, { recursive: true }); } catch (error) { @@ -47,24 +47,38 @@ export async function downloadDependencies(...infos: DownloadInfo[]): Promise = { + monero: [], + wownero: [], +}; + for (const tag of await getMoneroCTags()) { - for (const coin of ["monero", "wownero"]) { - moneroCInfos.push({ + for (const coin of ["monero", "wownero"] as const) { + dylibInfos[coin].push({ mirrors: [ `https://static.mrcyjanek.net/monero_c/libs/${tag}/`, `https://github.com/MrCyjaneK/monero_c/releases/download/${tag}/`, ], file: { + linux_aarch64: { name: `${coin}_aarch64-linux-gnu_libwallet2_api_c.so.xz` }, linux_x86_64: { name: `${coin}_x86_64-linux-gnu_libwallet2_api_c.so.xz` }, darwin_aarch64: { name: `${coin}_aarch64-apple-darwin11_libwallet2_api_c.dylib.xz` }, + darwin_x86_64: { name: `${coin}_x86_64-apple-darwin11_libwallet2_api_c.dylib.xz` }, windows_x86_64: { name: `${coin}_x86_64-w64-mingw32_libwallet2_api_c.dll.xz` }, + android_aarch64: { name: `${coin}_aarch64-linux-android_libwallet2_api_c.so.xz` }, }, outDir: `libs/${tag}`, }); @@ -159,6 +214,16 @@ for (const tag of await getMoneroCTags()) { // Download files to the monero_c folder // (used on mirror to keep files up to date) if (import.meta.main) { - outDir = "./monero_c"; - downloadDependencies(moneroCliInfo, wowneroCliInfo, ...moneroCInfos); + const supportedTargets: Target[] = [ + "linux_x86_64", + "linux_aarch64", + "darwin_x86_64", + "darwin_aarch64", + "windows_x86_64", + "android_aarch64", + ]; + + for (const target of supportedTargets) { + await downloadFiles("./monero_c", target, moneroCliInfo, wowneroCliInfo, ...Object.values(dylibInfos).flat()); + } } diff --git a/tests/utils.ts b/tests/utils.ts index f564e6c..0326d11 100755 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -2,15 +2,18 @@ import { build$, CommandBuilder } from "jsr:@david/dax"; import { dirname, join } from "jsr:@std/path"; import { downloadDependencies, + dylibInfos, getFileInfo, - moneroCInfos, moneroCliInfo, Target, - target, wowneroCliInfo, } from "./download_deps.ts"; import { loadMoneroDylib, loadWowneroDylib, moneroSymbols, wowneroSymbols } from "../impls/monero.ts/mod.ts"; +export type Coin = "monero" | "wownero"; + +const target = `${Deno.build.os}_${Deno.build.arch}` as const; + export const $ = build$({ commandBuilder: new CommandBuilder() .printCommand(true) @@ -19,8 +22,6 @@ export const $ = build$({ .stderr("inherit"), }); -type Coin = "monero" | "wownero"; - export const dylibNames: (coin: Coin) => Partial> = (coin) => ({ linux_x86_64: `${coin}_x86_64-linux-gnu_libwallet2_api_c.so`, darwin_aarch64: `${coin}_aarch64-apple-darwin11_libwallet2_api_c.dylib`, @@ -173,7 +174,7 @@ export async function prepareMoneroC(coin: Coin, version: MoneroCVersion) { `./tests/dependencies/libs/next/${moneroTsDylibName}`, ); } else { - const downloadInfo = moneroCInfos.find((info) => info.outDir?.endsWith(version)); + const downloadInfo = dylibInfos[coin].find((info) => info.outDir?.endsWith(version)); if (downloadInfo) { await downloadDependencies(downloadInfo); } -- cgit v1.2.3