contrib: rename gen-sdk to gen-sdk.py
What changed, and why it matters
This commit simply renames a helper script from gen-sdk to gen-sdk.py and updates the documentation link. The file contents are identical. It is a routine tooling change with no security relevance.
No action required; this is a non-functional rename.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is a pure rename of contrib/macdeploy/gen-sdk to contrib/macdeploy/gen-sdk.py so that the project’s Python linters recognize it. The README.md reference is updated accordingly. The script’s logic, permissions, and behavior are unchanged.
Changed components
contrib/macdeploy/gen-sdk.pycontrib/macdeploy/README.mdInspect captured patch +95 / −95
diff --git a/contrib/macdeploy/README.md b/contrib/macdeploy/README.md
index a4723861..1763c6cb 100644
--- a/contrib/macdeploy/README.md
+++ b/contrib/macdeploy/README.md
@@ -44,11 +44,11 @@ xip -x Xcode_15.xip
### Step 2: Generating the SDK tarball from `Xcode.app`
-To generate the SDK, run the script [`gen-sdk`](./gen-sdk) with the
+To generate the SDK, run the script [`gen-sdk.py`](./gen-sdk.py) with the
path to `Xcode.app` (extracted in the previous stage) as the first argument.
```bash
-./contrib/macdeploy/gen-sdk '/path/to/Xcode.app'
+./contrib/macdeploy/gen-sdk.py '/path/to/Xcode.app'
```
The generated archive should be: `Xcode-15.0-15A240d-extracted-SDK-with-libcxx-headers.tar`.
diff --git a/contrib/macdeploy/gen-sdk b/contrib/macdeploy/gen-sdk
deleted file mode 100755
index cf379292..00000000
--- a/contrib/macdeploy/gen-sdk
+++ /dev/null
@@ -1,93 +0,0 @@
-#!/usr/bin/env python3
-import argparse
-import plistlib
-import pathlib
-import tarfile
-import os
-import contextlib
-
-@contextlib.contextmanager
-def cd(path):
- """Context manager that restores PWD even if an exception was raised."""
- old_pwd = os.getcwd()
- os.chdir(str(path))
- try:
- yield
- finally:
- os.chdir(old_pwd)
-
-def run():
- parser = argparse.ArgumentParser(
- description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
-
- parser.add_argument('xcode_app', metavar='XCODEAPP', type=pathlib.Path)
- parser.add_argument("-o", metavar='OUTSDKTAR', dest='out_sdkt', type=pathlib.Path, required=False)
-
- args = parser.parse_args()
-
- xcode_app = args.xcode_app.resolve()
- assert xcode_app.is_dir(), "The supplied Xcode.app path '{}' either does not exist or is not a directory".format(xcode_app)
-
- xcode_app_plist = xcode_app.joinpath("Contents/version.plist")
- with xcode_app_plist.open('rb') as fp:
- pl = plistlib.load(fp)
- xcode_version = pl['CFBundleShortVersionString']
- xcode_build_id = pl['ProductBuildVersion']
- print("Found Xcode (version: {xcode_version}, build id: {xcode_build_id})".format(xcode_version=xcode_version, xcode_build_id=xcode_build_id))
-
- sdk_dir = xcode_app.joinpath("Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk")
- sdk_plist = sdk_dir.joinpath("System/Library/CoreServices/SystemVersion.plist")
- with sdk_plist.open('rb') as fp:
- pl = plistlib.load(fp)
- sdk_version = pl['ProductVersion']
- sdk_build_id = pl['ProductBuildVersion']
- print("Found MacOSX SDK (version: {sdk_version}, build id: {sdk_build_id})".format(sdk_version=sdk_version, sdk_build_id=sdk_build_id))
-
- out_name = "Xcode-{xcode_version}-{xcode_build_id}-extracted-SDK-with-libcxx-headers".format(xcode_version=xcode_version, xcode_build_id=xcode_build_id)
-
- out_sdkt_path = args.out_sdkt or pathlib.Path("./{}.tar".format(out_name))
-
- def tarfp_add_with_base_change(tarfp, dir_to_add, alt_base_dir):
- """Add all files in dir_to_add to tarfp, but prepend alt_base_dir to the files'
- names
-
- e.g. if the only file under /root/bazdir is /root/bazdir/qux, invoking:
-
- tarfp_add_with_base_change(tarfp, "foo/bar", "/root/bazdir")
-
- would result in the following members being added to tarfp:
-
- foo/bar/ -> corresponding to /root/bazdir
- foo/bar/qux -> corresponding to /root/bazdir/qux
-
- """
- def change_tarinfo_base(tarinfo):
- if tarinfo.name and tarinfo.name.endswith((".swiftmodule", ".modulemap")):
- return None
- if tarinfo.name and tarinfo.name.startswith("./"):
- tarinfo.name = str(pathlib.Path(alt_base_dir, tarinfo.name))
- if tarinfo.linkname and tarinfo.linkname.startswith("./"):
- tarinfo.linkname = str(pathlib.Path(alt_base_dir, tarinfo.linkname))
- # make metadata deterministic
- tarinfo.mtime = 0
- tarinfo.uid, tarinfo.uname = 0, ''
- tarinfo.gid, tarinfo.gname = 0, ''
- # don't use isdir() as there are also executable files present
- tarinfo.mode = 0o0755 if tarinfo.mode & 0o0100 else 0o0644
- return tarinfo
- with cd(dir_to_add):
- # recursion already adds entries in sorted order
- tarfp.add("./usr/include", recursive=True, filter=change_tarinfo_base)
- tarfp.add("./usr/lib", recursive=True, filter=change_tarinfo_base)
- tarfp.add("./System/Library/Frameworks", recursive=True, filter=change_tarinfo_base)
-
- print("Creating output .tar file...")
- with out_sdkt_path.open("wb") as fp:
- with tarfile.open(mode="w", fileobj=fp, format=tarfile.PAX_FORMAT) as tarfp:
- print("Adding MacOSX SDK {} files...".format(sdk_version))
- tarfp_add_with_base_change(tarfp, sdk_dir, out_name)
- print("Done! Find the resulting tarball at:")
- print(out_sdkt_path.resolve())
-
-if __name__ == '__main__':
- run()
diff --git a/contrib/macdeploy/gen-sdk.py b/contrib/macdeploy/gen-sdk.py
new file mode 100755
index 00000000..cf379292
--- /dev/null
+++ b/contrib/macdeploy/gen-sdk.py
@@ -0,0 +1,93 @@
+#!/usr/bin/env python3
+import argparse
+import plistlib
+import pathlib
+import tarfile
+import os
+import contextlib
+
+@contextlib.contextmanager
+def cd(path):
+ """Context manager that restores PWD even if an exception was raised."""
+ old_pwd = os.getcwd()
+ os.chdir(str(path))
+ try:
+ yield
+ finally:
+ os.chdir(old_pwd)
+
+def run():
+ parser = argparse.ArgumentParser(
+ description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
+
+ parser.add_argument('xcode_app', metavar='XCODEAPP', type=pathlib.Path)
+ parser.add_argument("-o", metavar='OUTSDKTAR', dest='out_sdkt', type=pathlib.Path, required=False)
+
+ args = parser.parse_args()
+
+ xcode_app = args.xcode_app.resolve()
+ assert xcode_app.is_dir(), "The supplied Xcode.app path '{}' either does not exist or is not a directory".format(xcode_app)
+
+ xcode_app_plist = xcode_app.joinpath("Contents/version.plist")
+ with xcode_app_plist.open('rb') as fp:
+ pl = plistlib.load(fp)
+ xcode_version = pl['CFBundleShortVersionString']
+ xcode_build_id = pl['ProductBuildVersion']
+ print("Found Xcode (version: {xcode_version}, build id: {xcode_build_id})".format(xcode_version=xcode_version, xcode_build_id=xcode_build_id))
+
+ sdk_dir = xcode_app.joinpath("Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk")
+ sdk_plist = sdk_dir.joinpath("System/Library/CoreServices/SystemVersion.plist")
+ with sdk_plist.open('rb') as fp:
+ pl = plistlib.load(fp)
+ sdk_version = pl['ProductVersion']
+ sdk_build_id = pl['ProductBuildVersion']
+ print("Found MacOSX SDK (version: {sdk_version}, build id: {sdk_build_id})".format(sdk_version=sdk_version, sdk_build_id=sdk_build_id))
+
+ out_name = "Xcode-{xcode_version}-{xcode_build_id}-extracted-SDK-with-libcxx-headers".format(xcode_version=xcode_version, xcode_build_id=xcode_build_id)
+
+ out_sdkt_path = args.out_sdkt or pathlib.Path("./{}.tar".format(out_name))
+
+ def tarfp_add_with_base_change(tarfp, dir_to_add, alt_base_dir):
+ """Add all files in dir_to_add to tarfp, but prepend alt_base_dir to the files'
+ names
+
+ e.g. if the only file under /root/bazdir is /root/bazdir/qux, invoking:
+
+ tarfp_add_with_base_change(tarfp, "foo/bar", "/root/bazdir")
+
+ would result in the following members being added to tarfp:
+
+ foo/bar/ -> corresponding to /root/bazdir
+ foo/bar/qux -> corresponding to /root/bazdir/qux
+
+ """
+ def change_tarinfo_base(tarinfo):
+ if tarinfo.name and tarinfo.name.endswith((".swiftmodule", ".modulemap")):
+ return None
+ if tarinfo.name and tarinfo.name.startswith("./"):
+ tarinfo.name = str(pathlib.Path(alt_base_dir, tarinfo.name))
+ if tarinfo.linkname and tarinfo.linkname.startswith("./"):
+ tarinfo.linkname = str(pathlib.Path(alt_base_dir, tarinfo.linkname))
+ # make metadata deterministic
+ tarinfo.mtime = 0
+ tarinfo.uid, tarinfo.uname = 0, ''
+ tarinfo.gid, tarinfo.gname = 0, ''
+ # don't use isdir() as there are also executable files present
+ tarinfo.mode = 0o0755 if tarinfo.mode & 0o0100 else 0o0644
+ return tarinfo
+ with cd(dir_to_add):
+ # recursion already adds entries in sorted order
+ tarfp.add("./usr/include", recursive=True, filter=change_tarinfo_base)
+ tarfp.add("./usr/lib", recursive=True, filter=change_tarinfo_base)
+ tarfp.add("./System/Library/Frameworks", recursive=True, filter=change_tarinfo_base)
+
+ print("Creating output .tar file...")
+ with out_sdkt_path.open("wb") as fp:
+ with tarfile.open(mode="w", fileobj=fp, format=tarfile.PAX_FORMAT) as tarfp:
+ print("Adding MacOSX SDK {} files...".format(sdk_version))
+ tarfp_add_with_base_change(tarfp, sdk_dir, out_name)
+ print("Done! Find the resulting tarball at:")
+ print(out_sdkt_path.resolve())
+
+if __name__ == '__main__':
+ run()
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.