Skip to content

Commit ab03078

Browse files
authored
Improve publish script in a few ways (#12164)
* Allow double quotes when parsing `package = ...` in `Cargo.toml` in our publish script * Use the `Crate::publish` field in publish script Instead of sometimes using that and sometimes using `CRATES_TO_PUBLISH`. * Update the lockfile via `cargo fetch --offline` in the publish script
1 parent 17fbd3c commit ab03078

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

scripts/publish.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ fn main() {
175175
// update C API version in wasmtime.h
176176
update_capi_version();
177177
// update the lock file
178-
run_cmd(Command::new("cargo").arg("fetch"));
178+
run_cmd(Command::new("cargo").arg("fetch").arg("--offline"));
179179
}
180180

181181
"publish" => {
@@ -248,11 +248,7 @@ fn run_cmd(cmd: &mut Command) {
248248
fn find_crates(dir: &Path, ws: &Workspace, dst: &mut Vec<Crate>) {
249249
if dir.join("Cargo.toml").exists() {
250250
let krate = read_crate(Some(ws), &dir.join("Cargo.toml"));
251-
if !krate.publish || CRATES_TO_PUBLISH.iter().any(|c| krate.name == *c) {
252-
dst.push(krate);
253-
} else {
254-
panic!("failed to find {:?} in whitelist or blacklist", krate.name);
255-
}
251+
dst.push(krate);
256252
}
257253

258254
for entry in dir.read_dir().unwrap() {
@@ -295,6 +291,11 @@ fn read_crate(ws: Option<&Workspace>, manifest: &Path) -> Crate {
295291
}
296292
let name = name.unwrap();
297293
let version = version.unwrap();
294+
assert!(
295+
!publish || CRATES_TO_PUBLISH.contains(&&name[..]),
296+
"a crate must either be listed in `CRATES_TO_PUBLISH` or have `publish = false` \
297+
in its `Cargo.toml`"
298+
);
298299
Crate {
299300
manifest: manifest.to_path_buf(),
300301
name,
@@ -304,9 +305,10 @@ fn read_crate(ws: Option<&Workspace>, manifest: &Path) -> Crate {
304305
}
305306

306307
fn bump_version(krate: &Crate, crates: &[Crate], patch: bool) {
308+
println!("bumping `{}`...", krate.name);
307309
let contents = fs::read_to_string(&krate.manifest).unwrap();
308310
let next_version = |krate: &Crate| -> String {
309-
if CRATES_TO_PUBLISH.contains(&&krate.name[..]) {
311+
if krate.publish {
310312
bump(&krate.version, patch)
311313
} else {
312314
krate.version.clone()
@@ -318,13 +320,8 @@ fn bump_version(krate: &Crate, crates: &[Crate], patch: bool) {
318320
for line in contents.lines() {
319321
let mut rewritten = false;
320322
if !is_deps && line.starts_with("version =") {
321-
if CRATES_TO_PUBLISH.contains(&&krate.name[..]) {
322-
println!(
323-
"bump `{}` {} => {}",
324-
krate.name,
325-
krate.version,
326-
next_version(krate),
327-
);
323+
if krate.publish {
324+
println!(" {} => {}", krate.version, next_version(krate));
328325
new_manifest.push_str(&line.replace(&krate.version, &next_version(krate)));
329326
rewritten = true;
330327
}
@@ -345,7 +342,8 @@ fn bump_version(krate: &Crate, crates: &[Crate], patch: bool) {
345342
}
346343
if !is_deps
347344
|| (!line.starts_with(&format!("{} ", other.name))
348-
&& !line.contains(&format!("package = '{}'", other.name)))
345+
&& !(line.contains(&format!("package = '{}'", other.name))
346+
|| line.contains(&format!("package = \"{}\"", other.name))))
349347
{
350348
continue;
351349
}
@@ -441,7 +439,7 @@ fn bump(version: &str, patch_bump: bool) -> String {
441439
}
442440

443441
fn publish(krate: &Crate) -> bool {
444-
if !CRATES_TO_PUBLISH.iter().any(|s| *s == krate.name) {
442+
if !krate.publish {
445443
return true;
446444
}
447445

0 commit comments

Comments
 (0)