diff --git a/.github/generated/ast_changes_watch_list.yml b/.github/generated/ast_changes_watch_list.yml index 4c10d00385b0d..3392d57e2f03a 100644 --- a/.github/generated/ast_changes_watch_list.yml +++ b/.github/generated/ast_changes_watch_list.yml @@ -12,66 +12,27 @@ src: - 'apps/oxlint/src-js/generated/visitor.d.ts' - 'apps/oxlint/src-js/generated/walk.js' - 'apps/oxlint/src/generated/raw_transfer_constants.rs' - - 'crates/oxc_allocator/src/generated/assert_layouts.rs' - - 'crates/oxc_allocator/src/generated/fixed_size_constants.rs' - - 'crates/oxc_allocator/src/pool/fixed_size.rs' - - 'crates/oxc_ast/src/ast/comment.rs' - - 'crates/oxc_ast/src/ast/js.rs' - - 'crates/oxc_ast/src/ast/jsx.rs' - - 'crates/oxc_ast/src/ast/literal.rs' - - 'crates/oxc_ast/src/ast/ts.rs' - - 'crates/oxc_ast/src/generated/assert_layouts.rs' - - 'crates/oxc_ast/src/generated/ast_builder.rs' - - 'crates/oxc_ast/src/generated/ast_kind.rs' - - 'crates/oxc_ast/src/generated/derive_clone_in.rs' - - 'crates/oxc_ast/src/generated/derive_content_eq.rs' - - 'crates/oxc_ast/src/generated/derive_dummy.rs' - - 'crates/oxc_ast/src/generated/derive_estree.rs' - - 'crates/oxc_ast/src/generated/derive_get_address.rs' - - 'crates/oxc_ast/src/generated/derive_get_span.rs' - - 'crates/oxc_ast/src/generated/derive_get_span_mut.rs' - - 'crates/oxc_ast/src/generated/derive_take_in.rs' - - 'crates/oxc_ast/src/generated/get_id.rs' - - 'crates/oxc_ast/src/serialize/basic.rs' - - 'crates/oxc_ast/src/serialize/js.rs' - - 'crates/oxc_ast/src/serialize/jsx.rs' - - 'crates/oxc_ast/src/serialize/literal.rs' - - 'crates/oxc_ast/src/serialize/mod.rs' - - 'crates/oxc_ast/src/serialize/ts.rs' + - 'crates/oxc_allocator/src/**' + - 'crates/oxc_ast/src/**' - 'crates/oxc_ast_macros/src/generated/derived_traits.rs' - 'crates/oxc_ast_macros/src/generated/structs.rs' - 'crates/oxc_ast_macros/src/lib.rs' - - 'crates/oxc_ast_visit/src/generated/utf8_to_utf16_converter.rs' - - 'crates/oxc_ast_visit/src/generated/visit.rs' - - 'crates/oxc_ast_visit/src/generated/visit_mut.rs' + - 'crates/oxc_ast_visit/src/**' + - 'crates/oxc_codegen/src/**' + - 'crates/oxc_data_structures/src/**' - 'crates/oxc_formatter/src/ast_nodes/generated/ast_nodes.rs' - 'crates/oxc_formatter/src/ast_nodes/generated/format.rs' - 'crates/oxc_linter/src/generated/assert_layouts.rs' - 'crates/oxc_linter/src/lib.rs' + - 'crates/oxc_minifier/src/**' + - 'crates/oxc_parser/src/**' - 'crates/oxc_regular_expression/src/ast.rs' - 'crates/oxc_regular_expression/src/generated/assert_layouts.rs' - 'crates/oxc_regular_expression/src/generated/derive_clone_in.rs' - 'crates/oxc_regular_expression/src/generated/derive_content_eq.rs' - 'crates/oxc_regular_expression/src/generated/derive_get_address.rs' - - 'crates/oxc_span/src/generated/assert_layouts.rs' - - 'crates/oxc_span/src/generated/derive_dummy.rs' - - 'crates/oxc_span/src/generated/derive_estree.rs' - - 'crates/oxc_span/src/source_type.rs' - - 'crates/oxc_span/src/span.rs' - - 'crates/oxc_syntax/src/comment_node.rs' - - 'crates/oxc_syntax/src/generated/assert_layouts.rs' - - 'crates/oxc_syntax/src/generated/derive_clone_in.rs' - - 'crates/oxc_syntax/src/generated/derive_content_eq.rs' - - 'crates/oxc_syntax/src/generated/derive_dummy.rs' - - 'crates/oxc_syntax/src/generated/derive_estree.rs' - - 'crates/oxc_syntax/src/lib.rs' - - 'crates/oxc_syntax/src/module_record.rs' - - 'crates/oxc_syntax/src/number.rs' - - 'crates/oxc_syntax/src/operator.rs' - - 'crates/oxc_syntax/src/reference.rs' - - 'crates/oxc_syntax/src/scope.rs' - - 'crates/oxc_syntax/src/serialize.rs' - - 'crates/oxc_syntax/src/symbol.rs' + - 'crates/oxc_span/src/**' + - 'crates/oxc_syntax/src/**' - 'crates/oxc_traverse/src/generated/scopes_collector.rs' - 'napi/parser/generated/constants.js' - 'napi/parser/generated/deserialize/js.js' diff --git a/Cargo.lock b/Cargo.lock index d353e84a0f519..1abafdd6a5066 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -691,7 +691,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -1536,7 +1536,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -1769,6 +1769,7 @@ dependencies = [ "serde", "serde_json", "syn", + "toml", ] [[package]] @@ -2930,7 +2931,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -3025,7 +3026,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b55fb86dfd3a2f5f76ea78310a88f96c4ea21a3031f8d212443d56123fd0521" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -3112,6 +3113,15 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_spanned" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e24345aa0fe688594e73770a5f6d1b216508b4f93484c0026d521acd30134392" +dependencies = [ + "serde_core", +] + [[package]] name = "sha1" version = "0.10.6" @@ -3304,7 +3314,7 @@ dependencies = [ "getrandom 0.3.4", "once_cell", "rustix", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -3423,6 +3433,45 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0dc8b1fb61449e27716ec0e1bdf0f6b8f3e8f6b05391e8497b8b6d7804ea6d8" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow", +] + +[[package]] +name = "toml_datetime" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2cdb639ebbc97961c51720f858597f7f24c4fc295327923af55b74c3c724533" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_parser" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0cbe268d35bdb4bb5a56a2de88d0ad0eb70af5384a99d648cd4b3d04039800e" +dependencies = [ + "winnow", +] + +[[package]] +name = "toml_writer" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df8b2b54733674ad286d16267dcfc7a71ed5c776e4ac7aa3c3e2561f7c637bf2" + [[package]] name = "tower" version = "0.5.2" @@ -3796,7 +3845,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -4000,6 +4049,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "winnow" +version = "0.7.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21a0236b59786fed61e2a80582dd500fe61f18b5dca67a4a067d0bc9039339cf" + [[package]] name = "wit-bindgen" version = "0.46.0" diff --git a/Cargo.toml b/Cargo.toml index 53f4f7481fb04..a9206002b96fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -225,6 +225,7 @@ similar-asserts = "1.7.0" # Test diff assertions smallvec = { version = "1.15.1", features = ["union"] } # Stack-allocated vectors tempfile = "3.23.0" # Temporary files tokio = { version = "1.48.0", default-features = false } # Async runtime +toml = { version = "0.9.8" } tower-lsp-server = "0.22.1" # LSP server framework tracing-subscriber = "0.3.20" # Tracing implementation ureq = { version = "3.1.4", default-features = false } # HTTP client diff --git a/tasks/ast_tools/Cargo.toml b/tasks/ast_tools/Cargo.toml index 95c039d5e6389..500fab36a865d 100644 --- a/tasks/ast_tools/Cargo.toml +++ b/tasks/ast_tools/Cargo.toml @@ -48,6 +48,7 @@ rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } syn = { workspace = true, features = ["clone-impls", "derive", "extra-traits", "full", "parsing", "printing", "proc-macro"] } +toml = { workspace = true } [features] default = ["generate-js"] diff --git a/tasks/ast_tools/src/main.rs b/tasks/ast_tools/src/main.rs index 7d0a5d74fad99..c678dde94868c 100644 --- a/tasks/ast_tools/src/main.rs +++ b/tasks/ast_tools/src/main.rs @@ -367,7 +367,7 @@ fn main() { // Add CI filter file to outputs. // Skip this step if JS generators are disabled, because not all files are generated. #[cfg(feature = "generate-js")] - outputs.push(generate_ci_filter(&outputs)); + outputs.push(generate_ci_filter(&outputs, &codegen)); // Write outputs to disk if !options.dry_run { @@ -383,12 +383,12 @@ fn main() { /// unless relevant files have changed. /// /// List includes source files, generated files, and all files in `oxc_ast_tools` itself. -fn generate_ci_filter(outputs: &[RawOutput]) -> RawOutput { +fn generate_ci_filter(outputs: &[RawOutput], codegen: &Codegen) -> RawOutput { log!("Generate CI filter... "); let paths = SOURCE_PATHS.iter().copied().chain(outputs.iter().map(|output| output.path.as_str())); - let output = Output::yaml_watch_list(AST_CHANGES_WATCH_LIST_PATH, paths); + let output = Output::yaml_watch_list(AST_CHANGES_WATCH_LIST_PATH, paths, codegen); log_success!(); diff --git a/tasks/ast_tools/src/output/yaml.rs b/tasks/ast_tools/src/output/yaml.rs index 6679af7c0cb72..446719377a1f0 100644 --- a/tasks/ast_tools/src/output/yaml.rs +++ b/tasks/ast_tools/src/output/yaml.rs @@ -1,4 +1,8 @@ -use std::fmt::Write; +use std::{fmt::Write, fs}; + +use rustc_hash::FxHashSet; + +use crate::Codegen; use super::{Output, add_header}; @@ -10,11 +14,52 @@ pub fn print_yaml(code: &str, generator_path: &str) -> String { impl Output { /// Generate a watch list YAML file. /// - /// The path of the watch list itself, `tasks/ast_tools/src/**`, and the CI workflow file are added to the list. + /// The following are added to the list: + /// * The watch list file itself + /// * `ast_tools` crate + /// * `oxc_*` dependencies of `ast_tools` + /// * CI workflow file pub fn yaml_watch_list<'s>( watch_list_path: &'s str, paths: impl IntoIterator, + codegen: &Codegen, ) -> Self { + let mut paths = paths.into_iter().collect::>(); + + // Get `oxc_*` dependencies of `ast_tools`. + // `ast_tools` uses these crates, so generated code may change if these crates are changed. + let cargo_toml = parse_toml("tasks/ast_tools/Cargo.toml", codegen); + let dependency_crates = cargo_toml + .get("dependencies") + .and_then(|v| v.as_table()) + .unwrap() + .keys() + .map(String::as_str) + .filter(|krate| { + // Exclude crates which are not in this monorepo e.g. `oxc_index` + krate.starts_with("oxc_") && codegen.root_path().join("crates").join(krate).is_dir() + }) + .collect::>(); + + // Remove paths from `paths` which are in `src` dir of a dependency crate + // (as `crate/{krate}/src/**` pattern will cover them anyway) + paths.retain(|path| { + if let Some(path) = path.strip_prefix("crates/") + && let Some((krate, path)) = path.split_once('/') + && path.starts_with("src/") + { + return !dependency_crates.contains(krate); + } + true + }); + + // Get paths for dependency crates + let dependency_crate_paths = dependency_crates + .into_iter() + .map(|krate| format!("crates/{krate}/src/**")) + .collect::>(); + + // Additional paths let additional_paths = [ // This watch list file watch_list_path, @@ -24,9 +69,13 @@ impl Output { ".github/workflows/ci.yml", ]; - let mut paths = paths.into_iter().chain(additional_paths).collect::>(); + // Add additional paths and dependency crate paths to `paths`, and sort + paths.extend( + additional_paths.into_iter().chain(dependency_crate_paths.iter().map(String::as_str)), + ); paths.sort_unstable(); + // Generate YAML let mut code = "src:\n".to_string(); for path in paths { writeln!(code, " - '{path}'").unwrap(); @@ -35,3 +84,9 @@ impl Output { Self::Yaml { path: watch_list_path.to_string(), code } } } + +/// Parse TOML file. +fn parse_toml(path: &str, codegen: &Codegen) -> toml::Table { + let toml_content = fs::read_to_string(codegen.root_path().join(path)).unwrap(); + toml::from_str(&toml_content).unwrap() +}