Skip to content

Migrate Rewatch to Rust 2024 edition #7602

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
254 changes: 133 additions & 121 deletions rewatch/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rewatch/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "rewatch"
version = "12.0.0-alpha.15"
edition = "2021"
edition = "2024"

[dependencies]
ahash = "0.8.3"
Expand Down
4 changes: 2 additions & 2 deletions rewatch/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::build::compile::{mark_modules_with_deleted_deps_dirty, mark_modules_w
use crate::helpers::emojis::*;
use crate::helpers::{self, get_workspace_root};
use crate::sourcedirs;
use anyhow::{anyhow, Result};
use anyhow::{Result, anyhow};
use build_types::*;
use console::style;
use indicatif::{ProgressBar, ProgressStyle};
Expand All @@ -21,7 +21,7 @@ use serde::Serialize;
use std::ffi::OsString;
use std::fmt;
use std::fs::File;
use std::io::{stdout, Write};
use std::io::{Write, stdout};
use std::path::{Path, PathBuf};
use std::process::Stdio;
use std::time::{Duration, Instant};
Expand Down
2 changes: 1 addition & 1 deletion rewatch/src/build/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ fn compile_file(
let ocaml_build_path_abs = package.get_ocaml_build_path();
let build_path_abs = package.get_build_path();
let implementation_file_path = match &module.source_type {
SourceType::SourceFile(ref source_file) => Ok(&source_file.implementation.path),
SourceType::SourceFile(source_file) => Ok(&source_file.implementation.path),
sourcetype => Err(format!(
"Tried to compile a file that is not a source file ({}). Path to AST: {}. ",
sourcetype,
Expand Down
29 changes: 16 additions & 13 deletions rewatch/src/build/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@ fn get_dep_modules(
) -> AHashSet<String> {
let mut deps = AHashSet::new();
let ast_file = package.get_build_path().join(ast_file);
if let Ok(lines) = helpers::read_lines(&ast_file) {
// we skip the first line with is some null characters
// the following lines in the AST are the dependency modules
// we stop when we hit a line that starts with a "/", this is the path of the file.
// this is the point where the dependencies end and the actual AST starts
for line in lines.skip(1).flatten() {
let line = line.trim().to_string();
if line.starts_with('/') {
break;
} else if !line.is_empty() {
deps.insert(line);
match helpers::read_lines(&ast_file) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo fix made this change due to how drop order changed in Rust 2024.

See https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html#details

Ok(lines) => {
// we skip the first line with is some null characters
// the following lines in the AST are the dependency modules
// we stop when we hit a line that starts with a "/", this is the path of the file.
// this is the point where the dependencies end and the actual AST starts
for line in lines.skip(1).flatten() {
let line = line.trim().to_string();
if line.starts_with('/') {
break;
} else if !line.is_empty() {
deps.insert(line);
}
}
}
} else {
panic!("Could not read file {}", ast_file.to_string_lossy());
_ => {
panic!("Could not read file {}", ast_file.to_string_lossy());
}
}

return deps
Expand Down
29 changes: 17 additions & 12 deletions rewatch/src/build/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use super::namespaces;
use super::packages;
use crate::config;
use crate::helpers;
use crate::helpers::emojis::*;
use crate::helpers::StrippedVerbatimPath;
use crate::helpers::emojis::*;
use ahash::{AHashMap, AHashSet};
use anyhow::{anyhow, Result};
use anyhow::{Result, anyhow};
use console::style;
use log::{debug, error};
use rayon::prelude::*;
Expand Down Expand Up @@ -266,16 +266,17 @@ pub fn read_dependency(
)),
}?;

let canonical_path = match path.canonicalize().map(StrippedVerbatimPath::to_stripped_verbatim_path) {
let canonical_path = match path
.canonicalize()
.map(StrippedVerbatimPath::to_stripped_verbatim_path)
{
Ok(canonical_path) => Ok(canonical_path),
Err(e) => {
Err(format!(
"Failed canonicalizing the package \"{}\" path \"{}\" (are node_modules up-to-date?)...\nMore details: {}",
package_name,
path.to_string_lossy(),
e
))
}
Err(e) => Err(format!(
"Failed canonicalizing the package \"{}\" path \"{}\" (are node_modules up-to-date?)...\nMore details: {}",
package_name,
path.to_string_lossy(),
e
)),
}?;

Ok(canonical_path)
Expand Down Expand Up @@ -414,7 +415,11 @@ fn make_package(config: config::Config, package_path: &Path, is_pinned_dep: bool
None => {
if !is_root {
let package_path_str = package_path.to_string_lossy();
log::warn!("Package '{}' has not defined any sources, but is not the root package. This is likely a mistake. It is located: {}", config.name, package_path_str);
log::warn!(
"Package '{}' has not defined any sources, but is not the root package. This is likely a mistake. It is located: {}",
config.name,
package_path_str
);
}

AHashSet::new()
Expand Down
39 changes: 19 additions & 20 deletions rewatch/src/build/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,7 @@ pub fn generate_asts(
}
});

if has_failure {
Err(stderr)
} else {
Ok(stderr)
}
if has_failure { Err(stderr) } else { Ok(stderr) }
}

pub fn parser_args(
Expand Down Expand Up @@ -328,31 +324,34 @@ fn generate_ast(
helpers::create_path(&ast_parent_path);

/* Create .ast */
let result = if let Some(res_to_ast) = Some(
let result = match Some(
Command::new(bsc_path)
.current_dir(&build_path_abs)
.args(parser_args)
.output()
.expect("Error converting .res to .ast"),
) {
let stderr = std::str::from_utf8(&res_to_ast.stderr).expect("Expect StdErr to be non-null");
if helpers::contains_ascii_characters(stderr) {
if res_to_ast.status.success() {
Ok((ast_path, Some(stderr.to_string())))
Some(res_to_ast) => {
let stderr = std::str::from_utf8(&res_to_ast.stderr).expect("Expect StdErr to be non-null");
if helpers::contains_ascii_characters(stderr) {
if res_to_ast.status.success() {
Ok((ast_path, Some(stderr.to_string())))
} else {
Err(format!("Error in {}:\n{}", package.name, stderr))
}
} else {
Err(format!("Error in {}:\n{}", package.name, stderr))
Ok((ast_path, None))
}
} else {
Ok((ast_path, None))
}
} else {
log::info!("Parsing file {}...", filename.display());
_ => {
log::info!("Parsing file {}...", filename.display());

Err(format!(
"Could not find canonicalize_string_path for file {} in package {}",
filename.display(),
package.name
))
Err(format!(
"Could not find canonicalize_string_path for file {} in package {}",
filename.display(),
package.name
))
}
};
if let Ok((ast_path, _)) = &result {
let _ = std::fs::copy(
Expand Down
5 changes: 4 additions & 1 deletion rewatch/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,10 @@ impl Config {
},
Ok(false) => vec![],
Err(_) => {
eprintln!("Could not establish Rescript Version number for uncurried mode. Defaulting to Rescript < 11, disabling uncurried mode. Please specify an exact version if you need > 11 and default uncurried mode. Version: {}", version);
eprintln!(
"Could not establish Rescript Version number for uncurried mode. Defaulting to Rescript < 11, disabling uncurried mode. Please specify an exact version if you need > 11 and default uncurried mode. Version: {}",
version
);
vec![]
}
}
Expand Down
6 changes: 1 addition & 5 deletions rewatch/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,7 @@ pub fn string_ends_with_any(s: &Path, suffixes: &[&str]) -> bool {

fn path_to_ast_extension(path: &Path) -> &str {
let extension = path.extension().unwrap().to_str().unwrap();
if extension.ends_with("i") {
".iast"
} else {
".ast"
}
if extension.ends_with("i") { ".iast" } else { ".ast" }
}

pub fn get_ast_path(source_file: &Path) -> PathBuf {
Expand Down
2 changes: 1 addition & 1 deletion rewatch/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::build::build_types::SourceType;
use crate::build::clean;
use crate::cmd;
use crate::helpers;
use crate::helpers::emojis::*;
use crate::helpers::StrippedVerbatimPath;
use crate::helpers::emojis::*;
use crate::queue::FifoQueue;
use crate::queue::*;
use futures_timer::Delay;
Expand Down