Skip to content

Commit 47ac2b9

Browse files
authored
Fix #3687 (#3692)
# Description of Changes Apparently, when `spacetime generate` passes files to a linter, the files are passed in as relative paths, which did not play properly with `dotnet format` (so we effectively borked it). # API and ABI breaking changes None. # Expected complexity level and risk 1 # Testing - [x] Unity testsuite no longer fails on expected diffs --------- Co-authored-by: Zeke Foppa <[email protected]>
1 parent ce54385 commit 47ac2b9

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

crates/cli/src/subcommands/generate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl clap::ValueEnum for Language {
285285
}
286286

287287
impl Language {
288-
fn format_files(&self, project_dir: &PathBuf, generated_files: BTreeSet<PathBuf>) -> anyhow::Result<()> {
288+
fn format_files(&self, project_dir: &Path, generated_files: BTreeSet<PathBuf>) -> anyhow::Result<()> {
289289
match self {
290290
Language::Rust => rustfmt(generated_files)?,
291291
Language::Csharp => dotnet_format(project_dir, generated_files)?,

crates/cli/src/tasks/csharp.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ pub(crate) fn build_csharp(project_path: &Path, build_debug: bool) -> anyhow::Re
108108
anyhow::bail!("Built project successfully but couldn't find the output file.");
109109
}
110110

111-
pub(crate) fn dotnet_format(project_dir: &PathBuf, files: impl IntoIterator<Item = PathBuf>) -> anyhow::Result<()> {
111+
pub(crate) fn dotnet_format(project_dir: &Path, files: impl IntoIterator<Item = PathBuf>) -> anyhow::Result<()> {
112+
let cwd = std::env::current_dir().expect("Failed to retrieve current directory");
112113
duct::cmd(
113114
"dotnet",
114115
itertools::chain(
@@ -119,17 +120,24 @@ pub(crate) fn dotnet_format(project_dir: &PathBuf, files: impl IntoIterator<Item
119120
// of a full style-aware formatter. Still better than nothing though.
120121
"whitespace",
121122
"--folder",
123+
project_dir.to_str().unwrap(),
122124
// Our files are marked with <auto-generated /> and will be skipped without this option.
123125
"--include-generated",
124126
"--include",
125127
]
126128
.into_iter()
127129
.map_into::<OsString>(),
128-
files.into_iter().map_into(),
130+
// Resolve absolute paths for all of the files, because we receive them as relative paths to cwd, but
131+
// `dotnet format` will interpret those paths relative to `project_dir`.
132+
files
133+
.into_iter()
134+
.map(|f| {
135+
let f = if f.is_absolute() { f } else { cwd.join(f) };
136+
f.canonicalize().expect("Failed to canonicalize path: {f}")
137+
})
138+
.map_into(),
129139
),
130140
)
131-
// This is important because we're running with `--folder`. We want to format the right folder!
132-
.dir(project_dir)
133141
.run()?;
134142
Ok(())
135143
}

0 commit comments

Comments
 (0)