Skip to content

Commit

Permalink
Slightly hacky fix for workspace support
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Sep 23, 2021
1 parent 69bbbea commit 87f644d
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 19 deletions.
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ intervaltree = "0.2"

# For binaries
clap = {version = "2.33", default-features = false}
cargo_toml = "0.10"

[dev-dependencies]
lazy_static = "1.4"
Expand Down
4 changes: 3 additions & 1 deletion ide/build.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ const pkg = require("./package.json");
const options = cli();

const rust_toolchain = toml.parse(fs.readFileSync("../rust-toolchain.toml"));
const install_script = fs.readFileSync('../scripts/install-binaries.sh').toString();
const define = {
TOOLCHAIN: JSON.stringify(rust_toolchain.toolchain),
VERSION: JSON.stringify(pkg.version)
VERSION: JSON.stringify(pkg.version),
INSTALL_SCRIPT: JSON.stringify(install_script)
};

let common = {
Expand Down
1 change: 0 additions & 1 deletion ide/src/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export let effects = async (
try {
let cmd = `effects ${doc.fileName} ${doc.offsetAt(selection.anchor)}`;
let stdout = await call_flowistry(cmd);
log(stdout);
let lines = stdout.split("\n");
let last_line = lines[lines.length - 1];
let effects: Effects = JSON.parse(last_line);
Expand Down
19 changes: 14 additions & 5 deletions ide/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare const TOOLCHAIN: {
channel: string;
components: string[];
};
declare const INSTALL_SCRIPT: string;

const SHOW_LOADER_THRESHOLD = 1000;

Expand Down Expand Up @@ -99,11 +100,19 @@ export async function setup(): Promise<CallFlowistry | null> {
if (version != VERSION) {
let components = TOOLCHAIN.components.join(",");
let rustup_cmd = `rustup toolchain install ${TOOLCHAIN.channel} -c ${components}`;
let cargo_cmd = `${cargo} install flowistry --version ${VERSION} --force`;
await exec(
`${rustup_cmd} && ${cargo_cmd}`,
"Installing Flowistry crate... (this may take a minute)"
);
await exec(rustup_cmd, "Installing nightly Rust...");

try {
await exec(INSTALL_SCRIPT, "Downloading Flowistry binaries...");
} catch (e) {
log("Install script failed with error:", e.toString());

let cargo_cmd = `${cargo} install flowistry --version ${VERSION} --force`;
await exec(
cargo_cmd,
"Flowistry binaries not available, instead installing Flowistry crate from source... (this may take a minute)"
);
}

if (version == "") {
vscode.window.showInformationMessage(
Expand Down
1 change: 0 additions & 1 deletion ide/src/slicing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export async function slice(
let stdout = await call_flowistry(cmd);

let lines = stdout.split("\n");
log(lines);
let last_line = lines[lines.length - 1];
let slice_output: SliceOutput = JSON.parse(last_line);

Expand Down
23 changes: 23 additions & 0 deletions scripts/install-binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -e
cd $(mktemp -d)

REPO="willcrichton/flowistry"
TARGET=$(rustc -Vv | grep host | cut -d' ' -f2)
LATEST=$(curl -s https://api.github.com/repos/${REPO}/releases/latest | jq -r '.name')
RELEASE_URL="https://github.com/${REPO}/releases/download/${LATEST}"

BINARY_PATH="${TARGET}.tar.gz"
BINARY_URL="${RELEASE_URL}/${BINARY_PATH}"
LOCAL_BIN_DIR="${CARGO_HOME:-$HOME/.cargo}/bin"

if wget -q --spider ${BINARY_URL}; then
wget -q ${BINARY_URL}
tar -xf ${BINARY_PATH}
rm ${BINARY_PATH}
mkdir -p ${LOCAL_BIN_DIR}
mv ./* ${LOCAL_BIN_DIR}
else
exit 1
fi
48 changes: 37 additions & 11 deletions src/bin/cargo-flowistry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern crate rustc_interface;
use clap::clap_app;
use std::{
env,
path::PathBuf,
process::{exit, Command},
};

Expand Down Expand Up @@ -40,21 +41,27 @@ fn main() {
)
.get_matches_from(env::args().skip(1));

let mut args = match matches.subcommand() {
let (mut args, file_name) = match matches.subcommand() {
("rustc_version", _) => {
let commit_hash = rustc_interface::util::commit_hash_str().unwrap_or("unknown");
println!("{}", commit_hash);
exit(0);
}
("backward_slice" | "forward_slice", Some(sub_m)) => vec![
("FILE", sub_m.value_of("file").unwrap()),
("START", sub_m.value_of("start").unwrap()),
("END", sub_m.value_of("end").unwrap()),
],
("effects", Some(sub_m)) => vec![
("FILE", sub_m.value_of("file").unwrap()),
("POS", sub_m.value_of("pos").unwrap()),
],
("backward_slice" | "forward_slice", Some(sub_m)) => (
vec![
("FILE", sub_m.value_of("file").unwrap()),
("START", sub_m.value_of("start").unwrap()),
("END", sub_m.value_of("end").unwrap()),
],
sub_m.value_of("file").unwrap(),
),
("effects", Some(sub_m)) => (
vec![
("FILE", sub_m.value_of("file").unwrap()),
("POS", sub_m.value_of("pos").unwrap()),
],
sub_m.value_of("file").unwrap(),
),
_ => {
unimplemented!()
}
Expand All @@ -66,14 +73,33 @@ fn main() {
};
args.push(("COMMAND", cmd));

let mut file_path = PathBuf::from(file_name);
let mut package = None;
while let Some(parent) = file_path.parent() {
file_path = parent.to_path_buf();

let manifest_path = file_path.join("Cargo.toml");
if manifest_path.exists() {
let manifest = cargo_toml::Manifest::from_path(manifest_path).unwrap();
package = Some(manifest.package.unwrap().name);
break;
}
}

let mut cmd = Command::new(cargo_path);
cmd
.arg("check")
.arg("-q")
.arg("--all")
.args(flags)
.env("RUSTC_WORKSPACE_WRAPPER", flowistry_rustc_path);

match package {
Some(package) => {
cmd.arg("-p").arg(package);
}
None => panic!("Could not find package for file: {}", file_path.display()),
};

for (k, v) in args {
cmd.env(format!("FLOWISTRY_{}", k), v);
}
Expand Down

0 comments on commit 87f644d

Please sign in to comment.