From cfd95150e2efce0b2798c307314f3d9832ea20a0 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 9 Oct 2024 17:22:59 +0200 Subject: [PATCH] csharpcomp: Avoid error on Windows. Reported by Michele Locati . * build-aux/csharpcomp.sh.in: Don't produce -reference options for DLLs whose name starts with a lowercase letter or contains '.Native.'. * lib/csharpcomp.c (name_is_dll): Filter our file names that start with a lowercase letter or contain '.Native.'. --- ChangeLog | 9 +++++++++ build-aux/csharpcomp.sh.in | 7 +++++-- lib/csharpcomp.c | 7 ++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4403490f81..2ea73565ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2024-10-09 Bruno Haible + + csharpcomp: Avoid error on Windows. + Reported by Michele Locati . + * build-aux/csharpcomp.sh.in: Don't produce -reference options for DLLs + whose name starts with a lowercase letter or contains '.Native.'. + * lib/csharpcomp.c (name_is_dll): Filter our file names that start with + a lowercase letter or contain '.Native.'. + 2024-10-08 Bruno Haible csharpcomp: Add support for dotnet. diff --git a/build-aux/csharpcomp.sh.in b/build-aux/csharpcomp.sh.in index 85ea5aaf22..fcfc32cd7f 100644 --- a/build-aux/csharpcomp.sh.in +++ b/build-aux/csharpcomp.sh.in @@ -180,8 +180,11 @@ else ;; esac options_csc="$options_csc -lib:"`echo "$arg" | sed -e "$sed_quote_subst"` - for file in `cd "$dotnet_runtime_dir" && echo *.dll`; do - options_csc="$options_csc -reference:"`echo "$file" | sed -e "$sed_quote_subst"` + for file in `cd "$dotnet_runtime_dir" && echo [ABCDEFGHIJKLMNOPQRSTUVWXYZ]*.dll`; do + case "$file" in + *.Native.*) ;; + *) options_csc="$options_csc -reference:"`echo "$file" | sed -e "$sed_quote_subst"` ;; + esac done csc="$dotnet_sdk_dir/Roslyn/bincore/csc.dll" case "@build_os@" in diff --git a/lib/csharpcomp.c b/lib/csharpcomp.c index 4caed49533..4874061e60 100644 --- a/lib/csharpcomp.c +++ b/lib/csharpcomp.c @@ -68,7 +68,12 @@ name_is_dll (const struct dirent *d) { size_t d_name_len = strlen (d->d_name); if (d_name_len > 4 && memcmp (d->d_name + d_name_len - 4, ".dll", 4) == 0) - return 1; + /* Filter out files that start with a lowercase letter and files that + contain the substring ".Native.", since on Windows these files + produce an error "PE image doesn't contain managed metadata". */ + if (d->d_name[0] >= 'A' && d->d_name[0] <= 'Z' + && strstr (d->d_name, ".Native.") == NULL) + return 1; } return 0; } -- 2.39.5