Skip to content

Commit

Permalink
fix: flakeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohe-Am committed Jan 10, 2025
1 parent 1c7f9dd commit f8549e0
Show file tree
Hide file tree
Showing 18 changed files with 219 additions and 740 deletions.
20 changes: 20 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Frequently Asked Questions

This list is incomplete; you can help by [expanding it](https://github.com/metatypedev/ghjk/discussions).

## How to increase verbosity?

Set the `GHJK_LOG` environment variable to `debug` to enable more verbose logging.

```bash
export GHJK_LOG=debug
```

For even more logs, one can set the `RUST_LOG` to `debug` or `trace`.
This is usually too verbose to be useful so a more targeted logging level is required.

```bash
export GHJK_LOG='info,ghjk=debug'
```
Setting `info,ghjk=debug`.
Please refer to the tracing [docs](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives) to learn how to manage log verbosity per module.
2 changes: 1 addition & 1 deletion ports/asdf_plugin_git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ export type AsdfPluginInstallConf =
*/
export default function conf(config: AsdfPluginInstallConf) {
return {
...readGhVars(),
...confValidator.parse(config),
port: manifest,
};
}

export function buildDep(): AllowedPortDep {
return {
...readGhVars(),
manifest,
defaultInst: {
portRef: getPortRef(manifest),
Expand Down
7 changes: 5 additions & 2 deletions ports/npmi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ export class Port extends PortBase {
const conf = confValidator.parse(args.config);
await $.raw`${depExecShimPath(std_ports.node_org, "npm", args.depArts)
// provide prefix flat to avoid looking at package.json in parent dirs
} install --prefix ${args.tmpDirPath} --no-fund ${conf.packageName}@${args.installVersion}`
} install --prefix ${args.tmpDirPath} --no-update-notifier --no-fund ${conf.packageName}@${args.installVersion}`
.cwd(args.tmpDirPath)
.env(pathsWithDepArts(args.depArts, args.platform.os));
.env({
...pathsWithDepArts(args.depArts, args.platform.os),
NO_UPDATE_NOTIFIER: "1",
});
await std_fs.move(args.tmpDirPath, args.downloadPath);
}

Expand Down
94 changes: 93 additions & 1 deletion src/deno_ports/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ export * from "./unar/mod.ts";
export { default as portsValidators } from "../sys_deno/ports/types.ts";
export { serializePlatform } from "../sys_deno/ports/types/platform.ts";

import { $ } from "../deno_utils/mod.ts";
import { std_url } from "../deps.ts";
import { PortBase } from "../sys_deno/ports/base.ts";
import type { ArchEnum, ListAllArgs, OsEnum } from "../sys_deno/ports/types.ts";
import type {
ArchEnum,
DepArts,
ListAllArgs,
OsEnum,
PortDep,
} from "../sys_deno/ports/types.ts";
import { serializePlatform } from "../sys_deno/ports/types/platform.ts";

export function dwnUrlOut(url: string) {
Expand All @@ -43,3 +50,88 @@ export async function defaultLatestStable(
}
return allVers[allVers.length - 1];
}

export function depExecShimPath(
dep: PortDep,
execName: string,
depArts: DepArts,
) {
const path = tryDepExecShimPath(dep, execName, depArts);
if (!path) {
throw new Error(
`unable to find shim path for bin "${execName}" of dep ${dep.name}`,
);
}
return path;
}

export function depEnv(
dep: PortDep,
depArts: DepArts,
) {
return depArts[dep.name]?.env ?? {};
}

export function tryDepExecShimPath(
dep: PortDep,
execName: string,
depArts: DepArts,
) {
const shimPaths = depArts[dep.name];
if (!shimPaths) {
return;
}
// FIXME: match despite `.exe` extension on windows
const path = shimPaths.execs[execName];
if (!path) {
return;
}
return path;
}

export function pathsWithDepArts(
depArts: DepArts,
os: OsEnum,
) {
const pathSet = new Set();
const libSet = new Set();
const includesSet = new Set();
for (const [_, { execs, libs, includes }] of Object.entries(depArts)) {
for (const [_, binPath] of Object.entries(execs)) {
pathSet.add($.path(binPath).parentOrThrow());
}
for (const [_, libPath] of Object.entries(libs)) {
libSet.add($.path(libPath).parentOrThrow());
}
for (const [_, incPath] of Object.entries(includes)) {
includesSet.add($.path(incPath).parentOrThrow());
}
}

let LD_LIBRARY_ENV: string;
switch (os) {
case "darwin":
LD_LIBRARY_ENV = "DYLD_LIBRARY_PATH";
break;
case "linux":
LD_LIBRARY_ENV = "LD_LIBRARY_PATH";
break;
default:
throw new Error(`unsupported os ${os}`);
}
return {
PATH: `${[...pathSet.keys()].join(":")}:${Deno.env.get("PATH") ?? ""}`,
LIBRARY_PATH: `${[...libSet.keys()].join(":")}:${
Deno.env.get("LIBRARY_PATH") ?? ""
}`,
C_INCLUDE_PATH: `${[...includesSet.keys()].join(":")}:${
Deno.env.get("C_INCLUDE_PATH") ?? ""
}`,
CPLUS_INCLUDE_PATH: `${[...includesSet.keys()].join(":")}:${
Deno.env.get("CPLUS_INCLUDE_PATH") ?? ""
}`,
[LD_LIBRARY_ENV]: `${[...libSet.keys()].join(":")}:${
Deno.env.get(LD_LIBRARY_ENV) ?? ""
}`,
};
}
181 changes: 8 additions & 173 deletions src/deno_utils/mod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/// <reference lib="deno.worker" />

// class re-exports are tricky. We want al importers
// of path to get it from here so we rename in common.ts
export { _DaxPath as Path } from "./deps.ts";

import {
_DaxPath as Path,
dax,
Expand All @@ -13,19 +17,9 @@ import {
zod,
zod_val_err,
} from "./deps.ts";
// class re-exports are tricky. We want al importers
// of path to get it from here so we rename in common.ts
export { _DaxPath as Path } from "./deps.ts";
import logger, { isColorfulTty } from "./logger.ts";
// NOTE: only use type imports only when getting stuff from "./modules"
import type {
DepArts,
InstallConfigFat,
InstallConfigResolvedX,
OsEnum,
PortDep,
PortManifest,
} from "../sys_deno/ports/types.ts";
// NOTE: only use type imports only when getting stuff from "./sys_deno"
import type { OsEnum } from "../sys_deno/ports/types.ts";

export type DeArrayify<T> = T extends Array<infer Inner> ? Inner : T;
const literalSchema = zod.union([
Expand All @@ -47,91 +41,6 @@ export function dbg<T>(val: T, ...more: unknown[]) {
return val;
}

export function pathsWithDepArts(
depArts: DepArts,
os: OsEnum,
) {
const pathSet = new Set();
const libSet = new Set();
const includesSet = new Set();
for (const [_, { execs, libs, includes }] of Object.entries(depArts)) {
for (const [_, binPath] of Object.entries(execs)) {
pathSet.add($.path(binPath).parentOrThrow());
}
for (const [_, libPath] of Object.entries(libs)) {
libSet.add($.path(libPath).parentOrThrow());
}
for (const [_, incPath] of Object.entries(includes)) {
includesSet.add($.path(incPath).parentOrThrow());
}
}

let LD_LIBRARY_ENV: string;
switch (os) {
case "darwin":
LD_LIBRARY_ENV = "DYLD_LIBRARY_PATH";
break;
case "linux":
LD_LIBRARY_ENV = "LD_LIBRARY_PATH";
break;
default:
throw new Error(`unsupported os ${os}`);
}
return {
PATH: `${[...pathSet.keys()].join(":")}:${Deno.env.get("PATH") ?? ""}`,
LIBRARY_PATH: `${[...libSet.keys()].join(":")}:${
Deno.env.get("LIBRARY_PATH") ?? ""
}`,
C_INCLUDE_PATH: `${[...includesSet.keys()].join(":")}:${
Deno.env.get("C_INCLUDE_PATH") ?? ""
}`,
CPLUS_INCLUDE_PATH: `${[...includesSet.keys()].join(":")}:${
Deno.env.get("CPLUS_INCLUDE_PATH") ?? ""
}`,
[LD_LIBRARY_ENV]: `${[...libSet.keys()].join(":")}:${
Deno.env.get(LD_LIBRARY_ENV) ?? ""
}`,
};
}

export function depExecShimPath(
dep: PortDep,
execName: string,
depArts: DepArts,
) {
const path = tryDepExecShimPath(dep, execName, depArts);
if (!path) {
throw new Error(
`unable to find shim path for bin "${execName}" of dep ${dep.name}`,
);
}
return path;
}

export function depEnv(
dep: PortDep,
depArts: DepArts,
) {
return depArts[dep.name]?.env ?? {};
}

export function tryDepExecShimPath(
dep: PortDep,
execName: string,
depArts: DepArts,
) {
const shimPaths = depArts[dep.name];
if (!shimPaths) {
return;
}
// FIXME: match despite `.exe` extension on windows
const path = shimPaths.execs[execName];
if (!path) {
return;
}
return path;
}

const syncSha256Hasher = multihasher.from({
code: multisha2.sha256.code,
name: multisha2.sha256.name,
Expand Down Expand Up @@ -168,15 +77,6 @@ export function objectHash(
return stringHash(json_canonicalize(object));
}

export function getPortRef(manifest: PortManifest) {
return `${manifest.name}@${manifest.version}`;
}

export function getInstallHash(install: InstallConfigResolvedX) {
const fullHashHex = objectHash(JSON.parse(JSON.stringify(install)));
return `${install.portRef}!${fullHashHex}`;
}

export function defaultCommandBuilder() {
const builder = new dax.CommandBuilder()
.printCommand(true);
Expand All @@ -187,16 +87,6 @@ export function defaultCommandBuilder() {
return builder;
}

// type Last<T extends readonly any[]> = T extends readonly [...any, infer R] ? R
// : DeArrayify<T>;
//
// type Ser<T extends readonly Promise<any>[]> = T extends
// readonly [...Promise<any>[], infer R] ? { (...promises: T): R }
// : {
// (...promises: T): DeArrayify<T>;
// };
//

let requestBuilder;
try {
requestBuilder = new dax.RequestBuilder()
Expand Down Expand Up @@ -250,29 +140,10 @@ export const $ = dax.build$(
depth: 10,
});
},

co: ((values: any[]) => Promise.all(values)) as typeof Promise.all,
collector: promiseCollector,
/* co<T extends readonly unknown[] | []>(
values: T,
): Promise<{ -readonly [P in keyof T]: Awaited<T[P]> }> {
return Promise.all(values);
}, */
// coIter<T, O>(
// items: Iterable<T>,
// fn: (item:T) => PromiseLike<O>,
// opts: {
// limit: "cpu" | number;
// } = {
// limit: "cpu"
// },
// ): Promise<Awaited<O>[]> {
// const limit = opts.limit == "cpu" ? AVAIL_CONCURRENCY : opts.limit;
// const promises = [] as PromiseLike<O>[];
// let freeSlots = limit;
// do {
// } while(true);
// return Promise.all(promises);
// }

pathToString(path: Path) {
return path.toString();
},
Expand Down Expand Up @@ -514,14 +385,6 @@ export function asyncRc<T>(val: T, onDrop: (val: T) => Promise<void>) {
return rc;
}

export function thinInstallConfig(fat: InstallConfigFat) {
const { port, ...lite } = fat;
return {
portRef: getPortRef(port),
...lite,
};
}

export type OrRetOf<T> = T extends () => infer Inner ? Inner : T;

/**
Expand Down Expand Up @@ -672,31 +535,3 @@ export function promiseCollector<T>(promises: Promise<T>[] = []) {
},
};
}

// /**
// * Blocks the event loop till the promise is resolved
// */
// export function deasyncPromise<T>(promise: Promise<T>) {
// // Note: npm:deasync does not work on deno
// // TODO: better impl or use a lib?
// const sleepSync = (timeout: number) => {
// Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, timeout);
// };

// let resolved = false;
// let ret: T | undefined, err;

// promise
// .then((r) => { ret = r; })
// .catch((e) => { err = e; })
// .finally(() => { resolved = true; });

// while (!resolved) {
// sleepSync(100);
// }

// if (err) {
// throw err;
// }
// return ret;
// }
Loading

0 comments on commit f8549e0

Please sign in to comment.