Skip to content

Commit

Permalink
fix: don't ensure rust when showing versions (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
shamsartem authored Aug 13, 2024
1 parent a8e1118 commit 4200df2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 49 deletions.
30 changes: 11 additions & 19 deletions cli/src/commands/dep/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { initCli } from "../../lib/lifeCycle.js";
import { ensureMarinePath, ensureMreplPath } from "../../lib/marineCli.js";
import {
getRustToolchainToUse,
resolveMarineAndMreplDependencies,
getMarineOrMreplVersion,
} from "../../lib/rust.js";
import CLIPackageJSON from "../../versions/cli.package.json" assert { type: "json" };
import JSClientPackageJSON from "../../versions/js-client.package.json" assert { type: "json" };
Expand Down Expand Up @@ -85,24 +85,16 @@ export default class Versions extends BaseCommand<typeof Versions> {
maybeFluenceConfig === null
? versions.npm
: maybeFluenceConfig.aquaDependencies,
tools: Object.fromEntries(
await Promise.all(
(await resolveMarineAndMreplDependencies()).map(
async ([tool, version]) => {
return [
tool,
{
version,
path:
tool === "marine"
? await ensureMarinePath()
: await ensureMreplPath(),
},
] as const;
},
),
),
),
tools: {
marine: {
version: await getMarineOrMreplVersion("marine"),
path: await ensureMarinePath(),
},
mrepl: {
version: await getMarineOrMreplVersion("mrepl"),
path: await ensureMreplPath(),
},
},
"internal dependencies": filterOutNonFluenceDependencies(
CLIPackageJSON.dependencies,
),
Expand Down
12 changes: 5 additions & 7 deletions cli/src/lib/marineCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import { join } from "node:path";

import { commandObj } from "./commandObj.js";
import { BIN_DIR_NAME, MARINE_CARGO_DEPENDENCY } from "./const.js";
import { BIN_DIR_NAME } from "./const.js";
import { execPromise } from "./execPromise.js";
import { ensureMarineOrMreplDependency } from "./rust.js";
import { ensureMarineOrMreplDependency, ensureRust } from "./rust.js";
import { type Flags } from "./typeHelpers.js";

type MarineCliInput =
Expand All @@ -44,19 +44,17 @@ export type MarineCLI = {
};

export async function ensureMarinePath() {
const marineCLIDirPath = await ensureMarineOrMreplDependency({
name: MARINE_CARGO_DEPENDENCY,
});

const marineCLIDirPath = await ensureMarineOrMreplDependency("marine");
return join(marineCLIDirPath, BIN_DIR_NAME, "marine");
}

export async function ensureMreplPath() {
const mreplDirPath = await ensureMarineOrMreplDependency({ name: "mrepl" });
const mreplDirPath = await ensureMarineOrMreplDependency("mrepl");
return join(mreplDirPath, BIN_DIR_NAME, "mrepl");
}

export async function initMarineCli(): Promise<MarineCLI> {
await ensureRust();
const marineCLIPath = await ensureMarinePath();

return async ({
Expand Down
36 changes: 13 additions & 23 deletions cli/src/lib/rust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
const CARGO = "cargo";
const RUSTUP = "rustup";

async function ensureRust(): Promise<void> {
export async function ensureRust(): Promise<void> {
if (!(await isRustInstalled())) {
if (commandObj.config.windows) {
commandObj.error(
Expand Down Expand Up @@ -333,17 +333,11 @@ async function tryDownloadingBinary({
return true;
}

type CargoDependencyArg = {
name: MarineOrMrepl;
version?: string | undefined;
};

export async function ensureMarineOrMreplDependency({
name,
}: CargoDependencyArg): Promise<string> {
await ensureRust();
export async function ensureMarineOrMreplDependency(
name: MarineOrMrepl,
): Promise<string> {
const fluenceConfig = await initFluenceConfig();
const version = fluenceConfig?.[`${name}Version`] ?? versions.cargo[name];
const version = await getMarineOrMreplVersion(name);

const { dependencyDirPath, dependencyTmpDirPath } =
await resolveDependencyDirPathAndTmpPath({ name, version });
Expand Down Expand Up @@ -385,20 +379,16 @@ export async function ensureMarineOrMreplDependency({
}

export async function ensureMarineAndMreplDependencies(): Promise<void> {
for (const [name, version] of await resolveMarineAndMreplDependencies()) {
// Not installing dependencies in parallel
// for cargo logs to be clearly readable
await ensureMarineOrMreplDependency({ name, version });
}
await ensureRust();
await ensureMarineOrMreplDependency("marine");
await ensureMarineOrMreplDependency("mrepl");
}

export async function resolveMarineAndMreplDependencies() {
const fluenceConfig = await initFluenceConfig();

return [
["marine", fluenceConfig?.marineVersion ?? versions.cargo.marine],
["mrepl", fluenceConfig?.mreplVersion ?? versions.cargo.mrepl],
] as const;
export async function getMarineOrMreplVersion(marineOrMrepl: MarineOrMrepl) {
return (
(await initFluenceConfig())?.[`${marineOrMrepl}Version`] ??
versions.cargo[marineOrMrepl]
);
}

type ResolveDependencyDirPathAndTmpPath = {
Expand Down

0 comments on commit 4200df2

Please sign in to comment.