[libcxx-commits] [libcxx] [libcxx][test] Create feature host-can-create-symlinks (PR #82204)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 8 06:53:43 PST 2024


================
@@ -474,6 +476,39 @@ def _getAndroidDeviceApi(cfg):
     ),
 ]
 
+
+# Creation of symlinks require elevated privileges on Windows unless
+# Windows developer mode is enabled.
+def check_unprivileged_symlinks(cfg):
+    if not platform.system().lower().startswith("windows"):
+        return True
+
+    temp_file = tempfile.NamedTemporaryFile(delete=False)
+    temp_file_path = temp_file.name
+
+    # Close the file to ensure it can be linked.
+    temp_file.close()
+
+    symlink_file_path = temp_file_path + "_symlink"
+    try:
+        os.symlink(temp_file_path, symlink_file_path)
+        return True
+    except OSError as e:
+        return False
+    finally:
+        os.remove(temp_file_path)
+        if os.path.exists(symlink_file_path):
+            os.remove(symlink_file_path)
+
+
+DEFAULT_FEATURES += [
+    Feature(
+        name="host-can-create-symlinks",
----------------
ldionne wrote:

I think the name `host-can-create-symlinks` is somewhat misleading, since "host" generally means the build host we're building the code on, not the target we're running on. Those may not be the same if you're cross-compiling. In this case, you're interested in whether you're able to create symlinks on the target you're running on.

So I would probably just use `can-create-symlinks` as the feature name.

https://github.com/llvm/llvm-project/pull/82204


More information about the libcxx-commits mailing list