Skip to content

Commit ab45eec

Browse files
authored
Improve SSH support and remove count-line in compile (#7)
1 parent 1b5b379 commit ab45eec

File tree

3 files changed

+38
-34
lines changed

3 files changed

+38
-34
lines changed

src/executable.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crate::files;
2-
use colored::Colorize;
2+
33
use std::env;
44
use std::path::{Path, PathBuf};
5-
use std::process::Command;
65

76
pub fn locate_from_path<P>(binary: &P) -> Option<PathBuf>
87
where
@@ -73,7 +72,10 @@ where
7372

7473
// On Windows, prefer pwsh if available, otherwise fall back to powershell.
7574
#[cfg(target_os = "windows")]
76-
pub fn get_powershell_command() -> std::io::Result<Command> {
75+
pub fn get_powershell_command() -> std::io::Result<std::process::Command> {
76+
use colored::Colorize;
77+
use std::process::Command;
78+
7779
let check_pwsh = Command::new("pwsh")
7880
.arg("/?")
7981
.stdout(std::process::Stdio::null())

src/main.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,6 @@ struct CompileArgs {
264264
allow_hyphen_values = true
265265
)]
266266
pass_through: Vec<String>,
267-
268-
#[arg(
269-
short = 'c',
270-
long = "count-line",
271-
help = "Count the number of lines of code",
272-
default_value = "false",
273-
action = ArgAction::SetTrue
274-
)]
275-
count_line: bool,
276267
}
277268

278269
#[derive(Parser, Debug)]
@@ -451,7 +442,7 @@ fn compile(args: &CompileArgs) -> Result<(), DynError> {
451442
release: !args.debug,
452443
disasm: args.disasm,
453444
pass_through: args.pass_through.clone(),
454-
count_line: args.count_line,
445+
count_line: false,
455446
};
456447

457448
verus::exec_compile(&targets, &imports, &options)

src/verus.rs

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,8 @@ pub mod install {
12681268
pub branch: Option<String>,
12691269
}
12701270

1271-
pub const VERUS_REPO: &str = "https://[email protected]/asterinas/verus.git";
1271+
pub const VERUS_REPO_HTTPS: &str = "https://github.com/asterinas/verus.git";
1272+
pub const VERUS_REPO_SSH: &str = "[email protected]:asterinas/verus.git";
12721273

12731274
#[memoize]
12741275
pub fn tools_dir() -> PathBuf {
@@ -1291,15 +1292,27 @@ pub mod install {
12911292
}
12921293

12931294
pub fn clone_repo(verus_dir: &Path) -> Result<(), DynError> {
1294-
info!(
1295-
"Cloning Verus repo {} to {} ...",
1296-
VERUS_REPO,
1297-
verus_dir.display()
1298-
);
1295+
info!("Cloning Verus repo to {} ...", verus_dir.display());
12991296

1300-
Repository::clone(VERUS_REPO, verus_dir).unwrap_or_else(|e| {
1301-
error!("Failed to clone verus repo: {}", e);
1297+
let mut builder = git2::build::RepoBuilder::new();
1298+
let mut callbacks = git2::RemoteCallbacks::new();
1299+
1300+
callbacks.credentials(|_url, username_from_url, _allowed_types| {
1301+
git2::Cred::ssh_key_from_agent(username_from_url.unwrap_or("git"))
13021302
});
1303+
1304+
let mut fetch_opts = git2::FetchOptions::new();
1305+
fetch_opts.remote_callbacks(callbacks);
1306+
builder.fetch_options(fetch_opts);
1307+
1308+
let ssh_result = builder.clone(VERUS_REPO_SSH, verus_dir);
1309+
if ssh_result.is_ok() {
1310+
return Ok(());
1311+
}
1312+
1313+
Repository::clone(VERUS_REPO_HTTPS, verus_dir)
1314+
.map_err(|e| format!("Failed to clone verus repo: {}", e))?;
1315+
13031316
Ok(())
13041317
}
13051318

@@ -1440,17 +1453,6 @@ pub mod install {
14401453
// Download Z3
14411454
install_z3()?;
14421455

1443-
// Apply patches
1444-
/*let verus_patch = tools_patch_dir().join("verus-fixes.patch");
1445-
if verus_patch.exists() && !commands::is_patch_applied(&verus_dir, &verus_patch) {
1446-
status!(
1447-
"Applying patch {} to {} ...",
1448-
verus_patch.display(),
1449-
verus_dir.display()
1450-
);
1451-
commands::apply_patch(&verus_dir, &verus_patch);
1452-
}*/
1453-
14541456
// Build Verus
14551457
build_verus(options.release)?;
14561458

@@ -1481,10 +1483,19 @@ pub mod install {
14811483
// Determine target branch (default to "main")
14821484
let target_branch = branch.unwrap_or("main");
14831485

1484-
// Find the remote and fetch the target branch
1486+
// Find the remote and check its URL to determine authentication method
14851487
let mut remote = repo.find_remote("origin")?;
1488+
let remote_url = remote.url().unwrap_or("");
1489+
let is_ssh = remote_url.starts_with("git@") || remote_url.contains("ssh://");
1490+
14861491
let mut callbacks = git2::RemoteCallbacks::new();
1487-
callbacks.credentials(|_url, username_from_url, _allowed_types| { git2::Cred::ssh_key_from_agent(username_from_url.unwrap_or("git")) });
1492+
1493+
if is_ssh {
1494+
// SSH repository - use SSH key authentication
1495+
callbacks.credentials(|_url, username_from_url, _allowed_types| {
1496+
git2::Cred::ssh_key_from_agent(username_from_url.unwrap_or("git"))
1497+
});
1498+
}
14881499
let mut fetch_opts = git2::FetchOptions::new();
14891500
fetch_opts.remote_callbacks(callbacks);
14901501
remote.fetch(&[target_branch], Some(&mut fetch_opts), None)?;

0 commit comments

Comments
 (0)