Fix template global.json under Windows (#4357)

# Description of Changes

Make the `global.json` files under `templates` into literal copies of
the root one, instead of symlinks. The symlinks were causing template
breakage when the CLI was built under windows.

# API and ABI breaking changes

None

# Expected complexity level and risk

1

# Testing

<!-- Describe any testing you've done, and any testing you'd like your
reviewers to do,
so that you're confident that all the changes work as expected! -->

- [x] Changing a template's global.json causes `cargo ci
global-json-policy` to fail
- [x] Making a template's global.json into a symlink also causes `cargo
ci global-json-policy` to fail

---------

Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
This commit is contained in:
Zeke Foppa
2026-02-19 15:33:51 -08:00
committed by GitHub
parent 2c8f62e019
commit dd3f7666bc
3 changed files with 27 additions and 18 deletions
@@ -1 +0,0 @@
../../../global.json
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "8.0.100",
"rollForward": "latestMinor"
}
}
@@ -1 +0,0 @@
../../../global.json
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "8.0.100",
"rollForward": "latestMinor"
}
}
+15 -16
View File
@@ -46,7 +46,7 @@ fn check_global_json_policy() -> Result<()> {
ensure_repo_root()?;
let root_json = Path::new("global.json");
let root_real = fs::canonicalize(root_json)?;
let root_contents = fs::read_to_string(root_json)?;
fn find_all_global_json(dir: &Path) -> Result<Vec<PathBuf>> {
let mut out = Vec::new();
@@ -67,25 +67,24 @@ fn check_global_json_policy() -> Result<()> {
let mut ok = true;
for p in globals {
let resolved = fs::canonicalize(&p)?;
// The root global.json itself is allowed.
if resolved == root_real {
println!("OK: {}", p.display());
continue;
}
let meta = fs::symlink_metadata(&p)?;
if !meta.file_type().is_symlink() {
eprintln!("Error: {} is not a symlink to root global.json", p.display());
let is_symlink = meta.file_type().is_symlink();
let is_template_global_json = p.strip_prefix(".").unwrap_or(&p).starts_with(Path::new("templates"));
if is_template_global_json && is_symlink {
eprintln!(
"Error: {} is a symlink. Template files must not be symlinks; they are copied literally and this will break if the CLI is built under Windows where symlinks are not supported.",
p.display()
);
ok = false;
continue;
}
eprintln!("Error: {} does not resolve to root global.json", p.display());
eprintln!(" resolved: {}", resolved.display());
eprintln!(" expected: {}", root_real.display());
ok = false;
let contents = fs::read_to_string(&p)?;
if contents != root_contents {
eprintln!("Error: {} does not match the root global.json contents", p.display());
ok = false;
} else if !is_template_global_json || !is_symlink {
println!("OK: {}", p.display());
}
}
if !ok {