Skip to content

Kill server and prepare for TOML in rust-toolchain #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions prusti-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ doctest = false # we have no doc tests
log = { version = "0.4", features = ["release_max_level_info"] }
viper = { path = "../viper" }
config = "0.9.0"
serde = "1.0"
serde_derive = "1.0"
serde = { version = "1.0", features = ["derive"] }
lazy_static = "1.4.0"
uuid = { version = "0.8", features = ["v4"] }
regex = "1.3.9"
3 changes: 1 addition & 2 deletions prusti-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ extern crate config as config_crate;
#[macro_use]
extern crate lazy_static;
extern crate regex;
#[macro_use]
extern crate serde;
extern crate uuid;
extern crate viper;
#[macro_use]
extern crate serde_derive;

pub mod config;
pub mod report;
Expand Down
3 changes: 1 addition & 2 deletions prusti-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ log = { version = "0.4", features = ["release_max_level_info"] }
lazy_static = "1.4.0"
polonius-engine = "0.12.1"
csv = "1"
serde = "1.0"
serde_derive = "1.0"
serde = { version = "1.0", features = ["derive"] }
regex = "1.3.9"
config = "0.9.0"
rustc-hash = "1.1.0"
Expand Down
2 changes: 1 addition & 1 deletion prusti-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ extern crate rustc_index;
// extern crate rustc_mir;
// extern crate rustc_target;
// #[macro_use]
// extern crate serde_derive;
// extern crate serde;
// extern crate serde;
// extern crate syntax;
// extern crate syntax_pos;
Expand Down
4 changes: 3 additions & 1 deletion prusti-launch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ test = false
doctest = false

[dependencies]
walkdir = "2"
walkdir = "2.0.0"
serde = { version = "1.0", features = ["derive"] }
toml = "0.5.0"

[dev-dependencies]
glob = "0.3.0"
5 changes: 2 additions & 3 deletions prusti-launch/src/bin/cargo-prusti.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use std::process::Command;
use prusti_launch::get_rust_toolchain_channel;

fn main(){
if let Err(code) = process(std::env::args().skip(1)) {
Expand All @@ -23,12 +24,10 @@ fn process<I>(args: I) -> Result<(), i32>
prusti_rustc_path.set_extension("exe");
}

let rust_toolchain = include_str!("../../../rust-toolchain");

let exit_status = Command::new("cargo".to_string())
.arg("check")
.args(args)
.env("RUST_TOOLCHAIN", rust_toolchain)
.env("RUST_TOOLCHAIN", get_rust_toolchain_channel())
.env("PRUSTI_QUIET", "true")
.env("PRUSTI_FULL_COMPILATION", "true")
.env("RUSTC_WRAPPER", prusti_rustc_path)
Expand Down
27 changes: 26 additions & 1 deletion prusti-launch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
path::{Path, PathBuf},
process::Command,
};
use serde::Deserialize;

/// Append paths to the loader environment variable
pub fn add_to_loader_path(paths: Vec<PathBuf>, cmd: &mut Command) {
Expand Down Expand Up @@ -89,11 +90,35 @@ pub fn find_java_home() -> Option<PathBuf> {
})
}

pub fn get_rust_toolchain_channel() -> String {
#[derive(Deserialize)]
struct RustToolchain {
toolchain: RustToolchainZone,
}

#[derive(Deserialize)]
struct RustToolchainZone {
channel: String,
components: Option<Vec<String>>,
}

let content = include_str!("../../rust-toolchain");
// Be ready to accept TOML format
// See: https://github.com/rust-lang/rustup/pull/2438
if content.starts_with("[toolchain]") {
let rust_toolchain: RustToolchain = toml::from_str(content)
.expect("failed to parse rust-toolchain file");
rust_toolchain.toolchain.channel
} else {
content.trim().to_string()
}
}

/// Find Prusti's sysroot
pub fn prusti_sysroot() -> Option<PathBuf> {
Command::new("rustup")
.arg("run")
.arg(include_str!("../../rust-toolchain").trim())
.arg(get_rust_toolchain_channel())
.arg("rustc")
.arg("--print")
.arg("sysroot")
Expand Down
17 changes: 14 additions & 3 deletions prusti-launch/tests/test_binaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use glob::glob;
use std::process::{Command, ExitStatus, Stdio};
use std::process::{Command, ExitStatus, Stdio, Child};
use std::path::PathBuf;
use std::io::{BufReader, BufRead};
use std::env;
Expand Down Expand Up @@ -81,6 +81,17 @@ fn run_on_test_files<F: Fn(&PathBuf) -> ExitStatus>(run: F) {
}
}

/// Kill a spawned Child process even in case of panics.
struct ChildGuard(Child);

impl Drop for ChildGuard {
fn drop(&mut self) {
if let Err(e) = self.0.kill() {
panic!("Could not kill child process: {}", e);
}
}
}

#[test]
fn test_prusti_rustc() {
let prusti_rustc = find_executable_path("prusti-rustc");
Expand Down Expand Up @@ -141,6 +152,8 @@ fn test_prusti_rustc_with_server() {
opt_server_port.expect("failed to read prusti-server port")
};

let _server_child_guard = ChildGuard(server_child);

run_on_test_files(|program: &PathBuf| -> ExitStatus {
println!("Running {:?} on {:?}...", prusti_rustc.display(), program.display());
Command::new(&prusti_rustc)
Expand All @@ -152,6 +165,4 @@ fn test_prusti_rustc_with_server() {
.status()
.expect("failed to execute prusti-rustc")
});

server_child.kill().expect("failed to kill prusti-server");
}
3 changes: 1 addition & 2 deletions prusti-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ reqwest = "0.9.1"
warp = "0.1.11"
tokio = "0.1.11"
num_cpus = "1.8.0"
serde = "1.0"
serde_derive = "1.0"
serde = { version = "1.0", features = ["derive"] }

[dev-dependencies]
lazy_static = "1.4.0"
2 changes: 1 addition & 1 deletion prusti-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern crate num_cpus;
extern crate prusti_common;
extern crate tokio;
#[macro_use]
extern crate serde_derive;
extern crate serde;

mod service;
mod verifier_runner;
Expand Down
3 changes: 1 addition & 2 deletions viper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ error-chain = "0.12.0"
viper-sys = { path = "../viper-sys" }
jni = { version = "0.17.0", features = ["backtrace", "invocation"] }
uuid = { version = "0.8", features = ["v4"] }
serde = "1.0"
serde_derive = "1.0"
serde = { version = "1.0", features = ["derive"] }

[dev-dependencies]
lazy_static = "1.4.0"
Expand Down
2 changes: 1 addition & 1 deletion viper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern crate log;
extern crate uuid;
extern crate viper_sys;
#[macro_use]
extern crate serde_derive;
extern crate serde;

mod ast_factory;
mod ast_utils;
Expand Down