Skip to content

Commit 95a02cb

Browse files
authored
Check all nested KCL samples (#6880)
1 parent a049768 commit 95a02cb

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ endif
4444
# BUILD
4545

4646
CARGO_SOURCES := rust/.cargo/config.toml $(wildcard rust/Cargo.*) $(wildcard rust/**/Cargo.*)
47+
KCL_SOURCES := $(wildcard public/kcl-samples/**/*.kcl)
4748
RUST_SOURCES := $(wildcard rust/**/*.rs)
4849

4950
REACT_SOURCES := $(wildcard src/*.tsx) $(wildcard src/**/*.tsx)
5051
TYPESCRIPT_SOURCES := tsconfig.* $(wildcard src/*.ts) $(wildcard src/**/*.ts)
5152
VITE_SOURCES := $(wildcard vite.*) $(wildcard vite/**/*.tsx)
5253

53-
5454
.PHONY: build
55-
build: install public/kcl_wasm_lib_bg.wasm .vite/build/main.js
55+
build: install public/kcl_wasm_lib_bg.wasm public/kcl-samples/manifest.json .vite/build/main.js
5656

5757
public/kcl_wasm_lib_bg.wasm: $(CARGO_SOURCES) $(RUST_SOURCES)
5858
ifdef WINDOWS
@@ -61,6 +61,9 @@ else
6161
npm run build:wasm:dev
6262
endif
6363

64+
public/kcl-samples/manifest.json: $(KCL_SOURCES)
65+
cd rust/kcl-lib && EXPECTORATE=overwrite cargo test generate_manifest
66+
6467
.vite/build/main.js: $(REACT_SOURCES) $(TYPESCRIPT_SOURCES) $(VITE_SOURCES)
6568
npm run tronb:vite:dev
6669

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@
122122
"files:invalidate-bucket:nightly": "./scripts/invalidate-files-bucket.sh --nightly",
123123
"postinstall": "electron-rebuild",
124124
"generate:machine-api": "npx openapi-typescript ./openapi/machine-api.json -o src/lib/machine-api.d.ts",
125-
"generate:samples-manifest": "cd public/kcl-samples && node generate-manifest.js",
126125
"tron:start": "electron-forge start",
127126
"chrome:test": "PLATFORM=web NODE_ENV=development playwright test --config=playwright.config.ts --project='Google Chrome' --grep-invert=@snapshot",
128127
"tronb:vite:dev": "vite build -c vite.main.config.ts -m development && vite build -c vite.preload.config.ts -m development && vite build -c vite.renderer.config.ts -m development",

rust/Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/kcl-lib/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ tynm = "0.1.10"
8585
url = { version = "2.5.4", features = ["serde"] }
8686
uuid = { workspace = true, features = ["v4", "v5", "js", "serde"] }
8787
validator = { version = "0.20.0", features = ["derive"] }
88+
walkdir = "2.5.0"
8889
web-time = "1.1"
8990
winnow = "=0.6.24"
9091
zip = { workspace = true }

rust/kcl-lib/src/simulation_tests/kcl_samples.rs

+18-22
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::{
88
use anyhow::Result;
99
use fnv::FnvHashSet;
1010
use serde::{Deserialize, Serialize};
11+
use walkdir::WalkDir;
1112

1213
use super::Test;
1314

@@ -250,19 +251,12 @@ fn get_kcl_metadata(project_path: &Path, files: &[String]) -> Option<KclMetadata
250251
let title = lines[0].trim_start_matches(COMMENT_PREFIX).trim().to_string();
251252
let description = lines[1].trim_start_matches(COMMENT_PREFIX).trim().to_string();
252253

253-
// Get the path components
254-
let path_components: Vec<String> = full_path_to_primary_kcl
255-
.components()
256-
.map(|comp| comp.as_os_str().to_string_lossy().to_string())
257-
.collect();
258-
259-
// Get the last two path components
260-
let len = path_components.len();
261-
let path_from_project_dir = if len >= 2 {
262-
format!("{}/{}", path_components[len - 2], path_components[len - 1])
263-
} else {
264-
primary_kcl_file.clone()
265-
};
254+
// Get the relative path from the project directory to the primary KCL file
255+
let path_from_project_dir = full_path_to_primary_kcl
256+
.strip_prefix(INPUTS_DIR.as_path())
257+
.unwrap_or(&full_path_to_primary_kcl)
258+
.to_string_lossy()
259+
.to_string();
266260

267261
let mut files = files.to_vec();
268262
files.sort();
@@ -281,21 +275,23 @@ fn get_kcl_metadata(project_path: &Path, files: &[String]) -> Option<KclMetadata
281275
fn generate_kcl_manifest(dir: &Path) -> Result<()> {
282276
let mut manifest = Vec::new();
283277

284-
// Collect all directory entries first and sort them by name for consistent ordering
285-
let mut entries: Vec<_> = fs::read_dir(dir)?
286-
.filter_map(Result::ok)
287-
.filter(|e| e.path().is_dir())
278+
// Collect all directory entries first
279+
let mut entries: Vec<_> = WalkDir::new(dir)
280+
.follow_links(true)
281+
.into_iter()
282+
.filter_map(|e| e.ok())
288283
.collect();
289284

290285
// Sort directories by name for consistent ordering
291-
entries.sort_by_key(|a| a.file_name());
286+
entries.sort_by_key(|a| a.file_name().to_string_lossy().to_string());
292287

288+
// Loop through all directories and add to manifest if KCL sample
293289
for entry in entries {
294-
let project_path = entry.path();
290+
let path = entry.path();
295291

296-
if project_path.is_dir() {
292+
if path.is_dir() {
297293
// Get all .kcl files in the directory
298-
let files: Vec<String> = fs::read_dir(&project_path)?
294+
let files: Vec<String> = fs::read_dir(path)?
299295
.filter_map(Result::ok)
300296
.filter(|e| {
301297
if let Some(ext) = e.path().extension() {
@@ -311,7 +307,7 @@ fn generate_kcl_manifest(dir: &Path) -> Result<()> {
311307
continue;
312308
}
313309

314-
if let Some(metadata) = get_kcl_metadata(&project_path, &files) {
310+
if let Some(metadata) = get_kcl_metadata(path, &files) {
315311
manifest.push(metadata);
316312
}
317313
}

0 commit comments

Comments
 (0)