Skip to content

Commit

Permalink
fix: bbup cleanup and fix (#10067)
Browse files Browse the repository at this point in the history
  • Loading branch information
signorecello authored Dec 4, 2024
1 parent f3c7294 commit 0ff8177
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 48 deletions.
1 change: 1 addition & 0 deletions barretenberg/bbup/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
yarn.lock
*.js
.yarn
bun.lockb
38 changes: 20 additions & 18 deletions barretenberg/bbup/bbup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
import { Command } from "commander";
import { Command, Option } from "commander";
const program = new Command();
import { installBB } from "./shell.js";
import ora from "ora";
Expand All @@ -10,20 +10,19 @@ const spinner = ora({ color: "blue", discardStdin: false });
const bbup = program
.command("install", { isDefault: true })
.description("Installs Barretenberg.")
.option("-f, --frontend", "Match the version of a specific frontend language", "noir");
const options = bbup.opts();
if (options.frontend === "noir") {
bbup
.requiredOption("-v, --version <version>", "The Noir version to match", "current")
.action(async ({ version }) => {
let resolvedVersion = version;
if (version === "current") {
.addOption(new Option("-v, --version <version>", "The Barretenberg version to install").implies({ noirVersion: null }))
.addOption(new Option("-nv, --noir-version <version>", "The Noir version to match").default("current"))
.action(async ({ version, noirVersion }) => {
let resolvedBBVersion = "";
if (noirVersion) {
let resolvedNoirVersion = noirVersion;
if (noirVersion === "current") {
spinner.start(`Querying noir version from nargo`);
try {
const output = execSync("nargo --version", { encoding: "utf-8" });
resolvedVersion = output.match(/nargo version = (\d+\.\d+\.\d+)/)[1];
resolvedNoirVersion = output.match(/nargo version = (\d+\.\d+\.\d+)/)[1];
spinner.stopAndPersist({
text: `Resolved noir version ${resolvedVersion} from nargo`,
text: `Resolved noir version ${resolvedNoirVersion} from nargo`,
symbol: logSymbols.success,
});
}
Expand All @@ -35,14 +34,17 @@ if (options.frontend === "noir") {
process.exit(1);
}
}
spinner.start(`Getting compatible barretenberg version for noir version ${resolvedVersion}`);
const compatibleVersion = await getBbVersionForNoir(resolvedVersion, spinner);
spinner.start(`Getting compatible barretenberg version for noir version ${resolvedNoirVersion}`);
resolvedBBVersion = await getBbVersionForNoir(resolvedNoirVersion, spinner);
spinner.stopAndPersist({
text: `Resolved to barretenberg version ${compatibleVersion}`,
text: `Resolved to barretenberg version ${resolvedBBVersion}`,
symbol: logSymbols.success,
});
spinner.start(`Installing barretenberg`);
await installBB(compatibleVersion, spinner);
});
}
}
else if (version) {
resolvedBBVersion = version;
}
spinner.start(`Installing barretenberg`);
await installBB(resolvedBBVersion, spinner);
});
bbup.parse();
3 changes: 2 additions & 1 deletion barretenberg/bbup/bbup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ const bbup = program
try {
const output = execSync("nargo --version", { encoding: "utf-8" });
resolvedNoirVersion = output.match(
/nargo version = (\d+\.\d+\.\d+)/
/nargo version = (\d+\.\d+\.\d+(-\w+\.\d+)?)/
)![1];
console.log(resolvedNoirVersion);
spinner.stopAndPersist({
text: `Resolved noir version ${resolvedNoirVersion} from nargo`,
symbol: logSymbols.success,
Expand Down
3 changes: 2 additions & 1 deletion barretenberg/bbup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "module",
"description": "Barretenberg installation script",
"bin": "bbup.js",
"version": "0.0.7",
"version": "0.0.12",
"license": "ISC",
"scripts": {
"start": "npx tsx bbup.ts",
Expand All @@ -13,6 +13,7 @@
"dependencies": {
"@inquirer/input": "^1.2.16",
"@inquirer/select": "^1.3.3",
"@types/node": "^22.9.1",
"axios": "^1.7.7",
"commander": "^11.1.0",
"log-symbols": "^7.0.0",
Expand Down
27 changes: 16 additions & 11 deletions barretenberg/bbup/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,25 @@ import tar from "tar-fs";
import { promisify } from "util";
import { pipeline } from "stream";
import path from "path";
import { appendFileSync, existsSync } from "fs";
export function sourceShellConfig() {
const shell = execSync("echo $SHELL", { encoding: "utf-8" }).trim();
if (shell.includes("bash")) {
process.env.PATH = execSync("echo $PATH", { encoding: "utf-8" }).trim();
const home = os.homedir();
const bbBinPath = path.join(home, ".bb");
const pathEntry = `export PATH="${bbBinPath}:$PATH"\n`;
if (existsSync(path.join(home, ".bashrc"))) {
const bashrcPath = path.join(home, ".bashrc");
appendFileSync(bashrcPath, pathEntry);
}
else if (shell.includes("zsh")) {
process.env.PATH = execSync('zsh -c "echo $PATH"', {
encoding: "utf-8",
}).trim();
if (existsSync(path.join(home, ".zshrc"))) {
const zshrcPath = path.join(home, ".zshrc");
appendFileSync(zshrcPath, pathEntry);
}
else if (shell.includes("fish")) {
process.env.PATH = execSync('fish -c "echo $PATH"', {
encoding: "utf-8",
}).trim();
if (existsSync(path.join(home, ".config", "fish", "config.fish"))) {
const fishConfigPath = path.join(home, ".config", "fish", "config.fish");
appendFileSync(fishConfigPath, `set -gx PATH ${bbBinPath} $PATH\n`);
}
// Update the current session's PATH
process.env.PATH = `${bbBinPath}:${process.env.PATH}`;
}
export function exec(cmd, options = {}) {
return execSync(cmd, {
Expand Down Expand Up @@ -65,4 +69,5 @@ export async function installBB(version, spinner) {
text: `Installed barretenberg to ${bbPath}`,
symbol: logSymbols.success,
});
sourceShellConfig();
}
31 changes: 20 additions & 11 deletions barretenberg/bbup/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,28 @@ import { promisify } from "util";
import { pipeline } from "stream";
import path from "path";

import { appendFileSync, existsSync } from "fs";

export function sourceShellConfig() {
const shell = execSync("echo $SHELL", { encoding: "utf-8" }).trim();
const home = os.homedir();
const bbBinPath = path.join(home, ".bb");
const pathEntry = `export PATH="${bbBinPath}:$PATH"\n`;

if (shell.includes("bash")) {
process.env.PATH = execSync("echo $PATH", { encoding: "utf-8" }).trim();
} else if (shell.includes("zsh")) {
process.env.PATH = execSync('zsh -c "echo $PATH"', {
encoding: "utf-8",
}).trim();
} else if (shell.includes("fish")) {
process.env.PATH = execSync('fish -c "echo $PATH"', {
encoding: "utf-8",
}).trim();
if (existsSync(path.join(home, ".bashrc"))) {
const bashrcPath = path.join(home, ".bashrc");
appendFileSync(bashrcPath, pathEntry);
}
if (existsSync(path.join(home, ".zshrc"))) {
const zshrcPath = path.join(home, ".zshrc");
appendFileSync(zshrcPath, pathEntry);
}
if (existsSync(path.join(home, ".config", "fish", "config.fish"))) {
const fishConfigPath = path.join(home, ".config", "fish", "config.fish");
appendFileSync(fishConfigPath, `set -gx PATH ${bbBinPath} $PATH\n`);
}

// Update the current session's PATH
process.env.PATH = `${bbBinPath}:${process.env.PATH}`;
}

export function exec(cmd: string, options = {}) {
Expand Down Expand Up @@ -82,4 +90,5 @@ export async function installBB(version: string, spinner: Ora) {
text: `Installed barretenberg to ${bbPath}`,
symbol: logSymbols.success,
});
sourceShellConfig();
}
14 changes: 8 additions & 6 deletions barretenberg/bbup/versions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios';
import logSymbols from 'log-symbols';
import axios from "axios";
import logSymbols from "log-symbols";
async function getNamedVersions(githubToken) {
const fetchOpts = {
// eslint-disable-next-line camelcase
Expand All @@ -9,16 +9,18 @@ async function getNamedVersions(githubToken) {
if (githubToken)
fetchOpts.headers = { Authorization: `token ${githubToken}` };
const { data } = await axios.get(`https://api.github.com/repos/noir-lang/noir/releases`, fetchOpts);
const stable = data.filter((release) => !release.tag_name.includes('aztec') && !release.tag_name.includes('nightly') && !release.prerelease)[0].tag_name;
const nightly = data.filter((release) => release.tag_name.startsWith('nightly'))[0].tag_name;
const stable = data.filter((release) => !release.tag_name.includes("aztec") &&
!release.tag_name.includes("nightly") &&
!release.prerelease)[0].tag_name;
const nightly = data.filter((release) => release.tag_name.startsWith("nightly"))[0].tag_name;
return {
stable,
nightly,
};
}
export async function getBbVersionForNoir(noirVersion, spinner, githubToken) {
let url = '';
if (noirVersion === 'stable' || noirVersion === 'nightly') {
let url = "";
if (noirVersion === "stable" || noirVersion === "nightly") {
spinner.start(`Resolving noir version ${noirVersion}...`);
const resolvedVersions = await getNamedVersions(githubToken);
spinner.stopAndPersist({
Expand Down

0 comments on commit 0ff8177

Please sign in to comment.