Skip to content

Commit

Permalink
Fix selecting incorrect target for examples, ensure downloaded binari…
Browse files Browse the repository at this point in the history
…es are executable
  • Loading branch information
willcrichton committed Feb 27, 2022
1 parent beb109c commit af41085
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
26 changes: 21 additions & 5 deletions crates/flowistry_ide/src/bin/cargo-flowistry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn main() {
let file_path = PathBuf::from(file_name);
let metadata = cargo_metadata::MetadataCommand::new()
.no_deps()
.other_options(["--offline".to_string()])
.other_options(["--all-features".to_string(), "--offline".to_string()])
.exec()
.unwrap();

Expand All @@ -138,14 +138,25 @@ fn main() {
})
.collect::<Vec<_>>();

// Find the package and target that corresponds to a given file path
let (pkg, target) = workspace_members
.iter()
.filter_map(|pkg| {
let target = pkg
let targets = pkg
.targets
.iter()
.filter(|target| file_path.starts_with(target.src_path.parent().unwrap()))
.max_by_key(|target| target.src_path.components().count())?;
.collect::<Vec<_>>();

// If there are multiple targets that match a given directory, e.g. `examples/whatever.rs`, then
// find the target whose name matches the file stem
let target = (match targets.len() {
0 => None,
1 => Some(targets[0]),
_ => targets
.into_iter()
.find(|target| target.name == file_path.file_stem().unwrap().to_string_lossy()),
})?;

Some((pkg, target))
})
Expand All @@ -165,10 +176,9 @@ fn main() {
]);

let bench = matches.is_present("BENCH");
cmd.arg(if bench { "-v" } else { "-q" });
cmd.arg(if bench { "-q" } else { "-v" });

// Add compile filter to specify the target corresponding to the given file
log::debug!("Package: {}", pkg.name);
cmd.arg("-p").arg(&pkg.name);
let kind = &target.kind[0];
if kind != "proc-macro" {
Expand All @@ -180,6 +190,12 @@ fn main() {
cmd.arg(&target.name);
}
};
log::debug!(
"Package: {}, target kind {}, target name {}",
pkg.name,
kind,
target.name
);

// RNG is necessary to avoid caching
let n = thread_rng().gen::<u64>();
Expand Down
17 changes: 11 additions & 6 deletions ide/src/download.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import AdmZip from "adm-zip";
import * as cp from "child_process";
import { promises as fs } from "fs";
import got from "got";
import _ from "lodash";
import os from "os";
import path from "path";
import * as util from "util";

import { globals } from "./extension";
import { log } from "./logging";
import { cargo_bin } from "./setup";

declare const VERSION: string;

Expand All @@ -31,12 +32,16 @@ export let download = async () => {
let release_name = `${target}.zip`;
let release_url = `${release_base_url}/${release_name}`;

let cargo_home = process.env.CARGO_HOME || path.join(os.homedir(), ".cargo");
let cargo_bin = path.join(cargo_home, "bin");

log(`Downloading ${release_url} to ${cargo_bin}`);
let dir = cargo_bin();
log(`Downloading ${release_url} to ${dir}`);
let buffer = await got.get(release_url).buffer();
let zip = new AdmZip(buffer);
zip.extractAllTo(cargo_bin, true);
zip.extractAllTo(dir, true);

// Ensure downloaded binaries are executable
let suffix = process.platform == "win32" ? ".exe" : "";
await fs.chmod(path.join(dir, "cargo-flowistry" + suffix), "755");
await fs.chmod(path.join(dir, "flowistry-driver" + suffix), "755");

globals.status_bar.set_state("idle");
};
12 changes: 11 additions & 1 deletion ide/src/setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as cp from "child_process";
import _ from "lodash";
import open from "open";
import os from "os";
import path from "path";
import { Readable } from "stream";
import * as vscode from "vscode";

Expand Down Expand Up @@ -50,11 +52,14 @@ export const get_flowistry_opts = async (cwd: string) => {

const library_path = LIBRARY_PATHS[process.platform] || "LD_LIBRARY_PATH";

const PATH = cargo_bin() + ";" + process.env.PATH;

return {
cwd,
[library_path]: target_libdir,
SYSROOT: sysroot,
RUST_BACKTRACE: "1",
PATH,
};
};

Expand Down Expand Up @@ -108,6 +113,11 @@ export type CallFlowistry = <T>(
_no_output?: boolean
) => Promise<FlowistryResult<T>>;

export let cargo_bin = () => {
let cargo_home = process.env.CARGO_HOME || path.join(os.homedir(), ".cargo");
return path.join(cargo_home, "bin");
};

export async function setup(
context: vscode.ExtensionContext
): Promise<CallFlowistry | null> {
Expand All @@ -134,7 +144,7 @@ export async function setup(

if (version !== VERSION) {
let components = TOOLCHAIN.components.map((c) => `-c ${c}`).join(" ");
let rustup_cmd = `rustup toolchain install ${TOOLCHAIN.channel} ${components}`;
let rustup_cmd = `rustup toolchain install ${TOOLCHAIN.channel} --profile minimal ${components}`;
try {
await exec_notify(rustup_cmd, "Installing nightly Rust...");
} catch (e: any) {
Expand Down

0 comments on commit af41085

Please sign in to comment.