diff mbox series

[meta-mingw] meta-mingw: support generating Windows SDK with no symlink

Message ID 20251031080447.2751414-1-Qi.Chen@windriver.com
State New
Headers show
Series [meta-mingw] meta-mingw: support generating Windows SDK with no symlink | expand

Commit Message

ChenQi Oct. 31, 2025, 8:04 a.m. UTC
From: Chen Qi <Qi.Chen@windriver.com>

On some Windows systems, symlinks are now allowed due to IT policy.
We need to be able to generate Windows SDK without symlinks.

To do this, a new variable, WINSDK_NO_SYMLINK, and a new bbclass,
mingw_sdk_handle_symlink.bbclass, are introduced to achieve this.

By default, things work as before; when setting WINSDK_NO_SYMLINK
to "1", SDK will replace all symlinks with the actual contents.

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
 classes/mingw_sdk_handle_symlink.bbclass    | 25 +++++++++++++++++++++
 conf/machine-sdk/include/mingw32-common.inc |  3 +++
 2 files changed, 28 insertions(+)
 create mode 100644 classes/mingw_sdk_handle_symlink.bbclass

Comments

Paul Barker Nov. 1, 2025, 2:27 p.m. UTC | #1
On Fri, 2025-10-31 at 16:04 +0800, Qi.Chen@windriver.com wrote:
> From: Chen Qi <Qi.Chen@windriver.com>
> 
> On some Windows systems, symlinks are now allowed due to IT policy.

Do you mean "not allowed" here?

Thanks,
Joshua Watt Nov. 2, 2025, 5:59 p.m. UTC | #2
On Sat, Nov 1, 2025, 8:27 AM Paul Barker <paul@pbarker.dev> wrote:

> On Fri, 2025-10-31 at 16:04 +0800, Qi.Chen@windriver.com wrote:
> > From: Chen Qi <Qi.Chen@windriver.com>
> >
> > On some Windows systems, symlinks are now allowed due to IT policy.
>
> Do you mean "not allowed" here?
>

IIRC,  Symlinks on windows have to be enabled by group policy, which can be
restricted by the domain admins. Unfortunately I think it is (or was)
disabled by default, so depending on how strict your IT department is, it
might not be possible to enable it yourself

>
> Thanks,
>
> --
> Paul Barker
>
ChenQi Nov. 3, 2025, 2:17 a.m. UTC | #3
On 11/3/25 01:59, Joshua Watt wrote:
>
>
> On Sat, Nov 1, 2025, 8:27 AM Paul Barker <paul@pbarker.dev> wrote:
>
>     On Fri, 2025-10-31 at 16:04 +0800, Qi.Chen@windriver.com wrote:
>     > From: Chen Qi <Qi.Chen@windriver.com>
>     >
>     > On some Windows systems, symlinks are now allowed due to IT policy.
>
>     Do you mean "not allowed" here?
>
Hi Paul,

Yes, I mean 'not allowed'. Thanks for spotting this.

>
> IIRC,  Symlinks on windows have to be enabled by group policy, which 
> can be restricted by the domain admins. Unfortunately I think it is 
> (or was) disabled by default, so depending on how strict your IT 
> department is, it might not be possible to enable it yourself

Hi Joshua,

I mean 'not allowed'. Sorry about the typo. I'll fix the commit message 
and send out V2.

A little more additional explanation on this patch:
By default, the Win SDK is still generated as before, which depends on 
symlinks to ensure things work; when WINSDK_NO_SYMLINK is set to "1", 
Win SDK is generated with no symlinks, which mean normal user can also 
use the SDK.

Regards,
Qi

>
>     Thanks,
>
>     -- 
>     Paul Barker
>
diff mbox series

Patch

diff --git a/classes/mingw_sdk_handle_symlink.bbclass b/classes/mingw_sdk_handle_symlink.bbclass
new file mode 100644
index 0000000..2f6dbe6
--- /dev/null
+++ b/classes/mingw_sdk_handle_symlink.bbclass
@@ -0,0 +1,25 @@ 
+WINSDK_NO_SYMLINK ?= "0"
+
+archive_sdk:prepend:sdkmingw32 () {
+	if [ "${WINSDK_NO_SYMLINK}" = "1" ]; then
+		for parse_type in "file" "directory"; do
+			find "${SDK_OUTPUT}/${SDKPATH}" -type l -print0 | while IFS= read -r -d '' symlink; do
+				target=$(readlink -f "$symlink" || echo "NOTVALID")
+				if [ "$target" = "NOTVALID" ]; then
+					continue
+				fi
+				if [ ! -e "$target" ]; then
+					continue
+				elif [ -d "$target" ]; then
+					if [ "$parse_type" = "directory" ]; then
+						rm "$symlink" && cp -r "$target" "$symlink"
+					fi
+				else
+					if [ "$parse_type" = "file" ]; then
+						rm "$symlink" && cp "$target" "$symlink"
+					fi
+				fi
+			done
+		done
+	fi
+}
diff --git a/conf/machine-sdk/include/mingw32-common.inc b/conf/machine-sdk/include/mingw32-common.inc
index 56b8052..bf3f14e 100644
--- a/conf/machine-sdk/include/mingw32-common.inc
+++ b/conf/machine-sdk/include/mingw32-common.inc
@@ -59,3 +59,6 @@  GCCPIE:mingw32 = ""
 
 # wine and wineserver are required to test MinGW SDKs
 HOSTTOOLS_NONFATAL += "wine wineserver"
+
+# handle symlinks
+INHERIT += "mingw_sdk_handle_symlink"