From 9502bf5b44f4fe1ebf10355f13ebbb89f8dc1a28 Mon Sep 17 00:00:00 2001 From: Matheus Cardoso Date: Mon, 12 Jun 2023 21:06:10 -0300 Subject: [PATCH] Ignore files in deps dir when resolving wit packages (#1061) * fix: ignore files in deps dir * run cargo fmt * improve comment and revert .gitignore * test: files in deps folder are ignored --- .gitignore | 1 + crates/wit-parser/src/resolve.rs | 8 ++++++++ .../tests/ui/ignore-files-deps/deps/bar/types.wit | 2 ++ .../tests/ui/ignore-files-deps/deps/ignore-me.txt | 1 + crates/wit-parser/tests/ui/ignore-files-deps/world.wit | 5 +++++ 5 files changed, 17 insertions(+) create mode 100644 crates/wit-parser/tests/ui/ignore-files-deps/deps/bar/types.wit create mode 100644 crates/wit-parser/tests/ui/ignore-files-deps/deps/ignore-me.txt create mode 100644 crates/wit-parser/tests/ui/ignore-files-deps/world.wit diff --git a/.gitignore b/.gitignore index 14d925d6d6..6e309e0876 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ publish *.wasm *.wat test.config + diff --git a/crates/wit-parser/src/resolve.rs b/crates/wit-parser/src/resolve.rs index 6a98273008..33b43ec681 100644 --- a/crates/wit-parser/src/resolve.rs +++ b/crates/wit-parser/src/resolve.rs @@ -112,6 +112,14 @@ impl Resolve { for dep in path.read_dir().context("failed to read directory")? { let dep = dep.context("failed to read directory iterator")?; let path = dep.path(); + + // Files in deps dir are ignored for now to avoid accidentally + // including things like `.DS_Store` files in the call below to + // `parse_dir`. + if path.is_file() { + continue; + } + let pkg = UnresolvedPackage::parse_dir(&path) .with_context(|| format!("failed to parse package: {}", path.display()))?; let prev = ret.insert(pkg.name.clone(), pkg); diff --git a/crates/wit-parser/tests/ui/ignore-files-deps/deps/bar/types.wit b/crates/wit-parser/tests/ui/ignore-files-deps/deps/bar/types.wit new file mode 100644 index 0000000000..22d08739c2 --- /dev/null +++ b/crates/wit-parser/tests/ui/ignore-files-deps/deps/bar/types.wit @@ -0,0 +1,2 @@ +package foo:bar +interface types {} diff --git a/crates/wit-parser/tests/ui/ignore-files-deps/deps/ignore-me.txt b/crates/wit-parser/tests/ui/ignore-files-deps/deps/ignore-me.txt new file mode 100644 index 0000000000..48a897f5f1 --- /dev/null +++ b/crates/wit-parser/tests/ui/ignore-files-deps/deps/ignore-me.txt @@ -0,0 +1 @@ +this file should be ignored by the parser \ No newline at end of file diff --git a/crates/wit-parser/tests/ui/ignore-files-deps/world.wit b/crates/wit-parser/tests/ui/ignore-files-deps/world.wit new file mode 100644 index 0000000000..8b51988f33 --- /dev/null +++ b/crates/wit-parser/tests/ui/ignore-files-deps/world.wit @@ -0,0 +1,5 @@ +package foo:foo + +world foo { + import foo:bar/types +}