From afea0ccadb4aa90bad85707a70287d1fb397121e Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 3 Nov 2025 19:13:32 +0100 Subject: [PATCH] Remove the dependency on git-files from cli/build.rs We technically don't need to `git ls-files` when getting the CLI templates because when we compile the release builds we work with a clean git clone, thus it's unlikely any untracked files will be created in the templates directory. --- crates/cli/build.rs | 51 ++++----------------------------------------- 1 file changed, 4 insertions(+), 47 deletions(-) diff --git a/crates/cli/build.rs b/crates/cli/build.rs index 45b2b7da86f..b1ea8b2d115 100644 --- a/crates/cli/build.rs +++ b/crates/cli/build.rs @@ -160,10 +160,10 @@ fn generate_template_files() { } fn generate_template_entry(code: &mut String, template_path: &Path, source: &str, manifest_dir: &Path) { - let (git_files, resolved_base) = get_git_tracked_files(template_path, manifest_dir); + let (template_files, resolved_base) = list_all_files(template_path, manifest_dir); - if git_files.is_empty() { - panic!("Template '{}' has no git-tracked files! Check that the directory exists and contains files tracked by git.", source); + if template_files.is_empty() { + panic!("Template '{}' has no files, check if the path is correct", source); } // Example: /Users/user/SpacetimeDB @@ -196,7 +196,7 @@ fn generate_template_entry(code: &mut String, template_path: &Path, source: &str code.push_str(" {\n"); code.push_str(" let mut files = HashMap::new();\n"); - for file_path in git_files { + for file_path in template_files { // Example file_path: modules/quickstart-chat/src/lib.rs (relative to repo root) // Example resolved_base: modules/quickstart-chat // Example relative_path: src/lib.rs @@ -259,18 +259,6 @@ fn generate_template_entry(code: &mut String, template_path: &Path, source: &str code.push_str(" }\n\n"); } -/// Get a list of files tracked by git from a given directory -fn get_git_tracked_files(path: &Path, manifest_dir: &Path) -> (Vec, PathBuf) { - if is_nix_build() { - // When building in Nix, we already know that there are no untracked files in our source tree, - // so we just list all of the files. - list_all_files(path, manifest_dir) - } else { - // When building outside of Nix, we invoke `git` to list all the tracked files. - get_git_tracked_files_via_cli(path, manifest_dir) - } -} - fn list_all_files(path: &Path, manifest_dir: &Path) -> (Vec, PathBuf) { let manifest_dir = manifest_dir.canonicalize().unwrap_or_else(|err| { panic!( @@ -346,37 +334,6 @@ fn make_repo_root_relative(full_path: &Path, repo_root: &Path) -> PathBuf { }) } -fn get_git_tracked_files_via_cli(path: &Path, manifest_dir: &Path) -> (Vec, PathBuf) { - let repo_root = get_repo_root(); - let repo_root = repo_root.canonicalize().unwrap_or_else(|err| { - panic!( - "Failed to canonicalize repo_root path {}: {err:#?}", - repo_root.display(), - ) - }); - - let resolved_path = make_repo_root_relative(&get_full_path_within_manifest_dir(path, manifest_dir), &repo_root); - - let output = Command::new("git") - .args(["ls-files", resolved_path.to_str().unwrap()]) - .current_dir(repo_root) - .output() - .expect("Failed to execute git ls-files"); - - if !output.status.success() { - return (Vec::new(), resolved_path); - } - - let stdout = String::from_utf8(output.stdout).unwrap(); - let files: Vec = stdout - .lines() - .filter(|line| !line.is_empty()) - .map(PathBuf::from) - .collect(); - - (files, resolved_path) -} - fn get_repo_root() -> PathBuf { let manifest_dir = get_manifest_dir(); // Cargo doesn't expose a way to get the workspace root, AFAICT (pgoldman 2025-10-31).