Skip to content

Commit 0d97f40

Browse files
authored
Change Verus source to asterinas\verus (#3)
* A little more robust * Remove patch-apply * Change verus source
1 parent 84a34a7 commit 0d97f40

File tree

2 files changed

+48
-21
lines changed

2 files changed

+48
-21
lines changed

src/main.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ struct BootstrapArgs {
9999
action = ArgAction::SetTrue
100100
)]
101101
debug: bool,
102+
103+
#[arg(long = "test_branch",
104+
help = "Use the test branch of our Verus fork for testing",
105+
default_value = "false",
106+
action = ArgAction::SetTrue)]
107+
test_branch: bool,
102108
}
103109

104110
#[derive(Parser, Debug)]
@@ -396,6 +402,11 @@ fn bootstrap(args: &BootstrapArgs) -> Result<(), DynError> {
396402
let options = verus::install::VerusInstallOpts {
397403
release: !args.debug,
398404
restart: args.restart,
405+
branch: if args.test_branch {
406+
Some("update-test".into())
407+
} else {
408+
None
409+
},
399410
};
400411

401412
if args.upgrade {

src/verus.rs

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ pub fn get_target_dir() -> PathBuf {
139139

140140
#[memoize]
141141
pub fn get_verus_target_dir() -> PathBuf {
142-
let root = get_root();
143-
let verus_dir = root.join("tools").join("verus");
142+
let verus_dir = install::verus_dir();
144143
verus_dir
145144
.join("source")
146145
.join("target-verus")
@@ -1007,8 +1006,7 @@ pub fn exec_verify(
10071006
}
10081007

10091008
if options.count_line {
1010-
let root = get_root();
1011-
let verus_root = root.join("tools").join("verus");
1009+
let verus_root = install::verus_dir();
10121010
let line_count_dir = verus_root.join("source/tools/line_count");
10131011
let dependency_file = env::current_dir()?.join("lib.d");
10141012
env::set_current_dir(&line_count_dir)?;
@@ -1098,9 +1096,10 @@ pub mod install {
10981096
pub struct VerusInstallOpts {
10991097
pub restart: bool,
11001098
pub release: bool,
1099+
pub branch: Option<String>,
11011100
}
11021101

1103-
pub const VERUS_REPO: &str = "https://github.com/verus-lang/verus.git";
1102+
pub const VERUS_REPO: &str = "https://github.com/asterinas/verus.git";
11041103

11051104
#[memoize]
11061105
pub fn tools_dir() -> PathBuf {
@@ -1122,11 +1121,6 @@ pub mod install {
11221121
tools_dir().join("patches")
11231122
}
11241123

1125-
#[memoize]
1126-
pub fn verus_analyzer_dir() -> PathBuf {
1127-
tools_dir().join("verus-analyzer")
1128-
}
1129-
11301124
pub fn clone_repo(verus_dir: &Path) -> Result<(), DynError> {
11311125
info!(
11321126
"Cloning Verus repo {} to {} ...",
@@ -1260,6 +1254,10 @@ pub mod install {
12601254
pub fn exec_bootstrap(options: &VerusInstallOpts) -> Result<(), DynError> {
12611255
let verus_dir = verus_dir();
12621256

1257+
if options.branch.is_some() {
1258+
error!("Specifying a branch is only supported during upgrade.");
1259+
}
1260+
12631261
if options.restart && verus_dir.exists() {
12641262
info!("Removing old verus installation...");
12651263
std::fs::remove_dir_all(&verus_dir)?;
@@ -1274,15 +1272,15 @@ pub mod install {
12741272
install_z3()?;
12751273

12761274
// Apply patches
1277-
let verus_patch = tools_patch_dir().join("verus-fixes.patch");
1275+
/*let verus_patch = tools_patch_dir().join("verus-fixes.patch");
12781276
if verus_patch.exists() && !commands::is_patch_applied(&verus_dir, &verus_patch) {
12791277
status!(
12801278
"Applying patch {} to {} ...",
12811279
verus_patch.display(),
12821280
verus_dir.display()
12831281
);
12841282
commands::apply_patch(&verus_dir, &verus_patch);
1285-
}
1283+
}*/
12861284

12871285
// Build Verus
12881286
build_verus(options.release)?;
@@ -1302,7 +1300,7 @@ pub mod install {
13021300
Ok(())
13031301
}
13041302

1305-
pub fn git_pull(dir: &Path) -> Result<(), DynError> {
1303+
pub fn git_pull(dir: &Path, branch: Option<&str>) -> Result<(), DynError> {
13061304
let repo = Repository::open(dir).unwrap_or_else(|e| {
13071305
error!(
13081306
"Unable to find the git repo of verus under {}: {}",
@@ -1311,9 +1309,12 @@ pub mod install {
13111309
);
13121310
});
13131311

1314-
// Find the remote and fetch all branches
1312+
// Determine target branch (default to "main")
1313+
let target_branch = branch.unwrap_or("main");
1314+
1315+
// Find the remote and fetch the target branch
13151316
let mut remote = repo.find_remote("origin")?;
1316-
remote.fetch(&["main"], None, None)?; // Fetch all branches
1317+
remote.fetch(&[target_branch], None, None)?;
13171318

13181319
// Get the current branch
13191320
let head = repo.head()?;
@@ -1325,7 +1326,7 @@ pub mod install {
13251326
let local_commit = head.peel_to_commit()?;
13261327

13271328
// Find the matching remote branch
1328-
let upstream_branch = format!("refs/remotes/origin/{}", branch_name);
1329+
let upstream_branch = format!("refs/remotes/origin/{}", target_branch);
13291330
let upstream_ref = repo.find_reference(&upstream_branch)?;
13301331
let upstream_commit = upstream_ref.peel_to_commit()?;
13311332

@@ -1337,7 +1338,18 @@ pub mod install {
13371338
status!("Already up to date");
13381339
} else if analysis.is_fast_forward() {
13391340
// Fast-forward
1340-
let refname = format!("refs/heads/{}", branch_name);
1341+
let refname = format!("refs/heads/{}", target_branch);
1342+
1343+
// Create local branch if it doesn't exist
1344+
if repo.find_reference(&refname).is_err() {
1345+
repo.reference(
1346+
&refname,
1347+
upstream_commit.id(),
1348+
false,
1349+
&format!("Create branch {}", target_branch),
1350+
)?;
1351+
}
1352+
13411353
let mut reference = repo.find_reference(&refname)?;
13421354
reference.set_target(upstream_commit.id(), "Fast-forward")?;
13431355
repo.set_head(&refname)?;
@@ -1347,7 +1359,11 @@ pub mod install {
13471359
checkout_opts.force();
13481360
repo.checkout_head(Some(&mut checkout_opts))?;
13491361

1350-
status!("Fast-forwarded {} to {}", branch_name, upstream_commit.id());
1362+
status!(
1363+
"Fast-forwarded {} to {}",
1364+
target_branch,
1365+
upstream_commit.id()
1366+
);
13511367
} else {
13521368
// Need to perform a merge
13531369
let mut merge_opts = git2::MergeOptions::new();
@@ -1374,15 +1390,15 @@ pub mod install {
13741390
Some("HEAD"),
13751391
&sig,
13761392
&sig,
1377-
&format!("Merge remote-tracking branch 'origin/{}'", branch_name),
1393+
&format!("Merge remote-tracking branch 'origin/{}'", target_branch),
13781394
&tree,
13791395
&[&local_commit, &upstream_commit],
13801396
)?;
13811397

13821398
// Clean up merge state
13831399
repo.cleanup_state()?;
13841400

1385-
status!("Merged origin/{} into {}", branch_name, branch_name);
1401+
status!("Merged origin/{} into {}", target_branch, target_branch);
13861402
}
13871403

13881404
status!(
@@ -1401,7 +1417,7 @@ pub mod install {
14011417

14021418
// git pull the Verus repo
14031419
let verus_dir = verus_dir();
1404-
git_pull(&verus_dir)?;
1420+
git_pull(&verus_dir, options.branch.as_ref().map(|s| s.as_str()))?;
14051421
status!("Verus repo updated to the latest version");
14061422

14071423
// Build Verus

0 commit comments

Comments
 (0)