Skip to content

Commit 3c30cf2

Browse files
Copy licenses to the .dist-info/licenses/ziglang/<...> folder
1 parent 447fc15 commit 3c30cf2

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

make_wheels.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,24 @@ def write_wheel_file(filename, contents):
7070
def write_wheel(out_dir, *, name, version, tag, metadata, description, contents):
7171
wheel_name = f'{name}-{version}-{tag}.whl'
7272
dist_info = f'{name}-{version}.dist-info'
73+
license_files = {}
74+
filtered_metadata = []
75+
for header, value in metadata:
76+
if header == 'License-File':
77+
license_dest = f'{dist_info}/licenses/{value}'
78+
if value in contents:
79+
license_files[license_dest] = contents[value]
80+
filtered_metadata.append((header, value))
81+
filtered_metadata.append((header, value))
82+
7383
return write_wheel_file(os.path.join(out_dir, wheel_name), {
7484
**contents,
85+
**license_files,
7586
f'{dist_info}/METADATA': make_message([
7687
('Metadata-Version', '2.4'),
7788
('Name', name),
7889
('Version', version),
79-
*metadata,
90+
*filtered_metadata,
8091
], description),
8192
f'{dist_info}/WHEEL': make_message([
8293
('Wheel-Version', '1.0'),
@@ -107,13 +118,53 @@ def write_ziglang_wheel(out_dir, *, version, platform, archive):
107118
contents = {}
108119
contents['ziglang/__init__.py'] = b''
109120

121+
license_files = {}
122+
123+
# The paths to these licenses MUST match both the actual files
124+
# in the Zig source tarballs and the License-File entries listed
125+
# below in the metadata. These are not prefixed with "ziglang/"
126+
# since these are the actual paths in the Zig source tarballs.
127+
license_paths = [
128+
'LICENSE',
129+
'lib/libc/glibc/LICENSES',
130+
'lib/libc/mingw/COPYING',
131+
'lib/libc/musl/COPYRIGHT',
132+
'lib/libc/wasi/LICENSE',
133+
'lib/libc/wasi/LICENSE-APACHE',
134+
'lib/libc/wasi/LICENSE-APACHE-LLVM',
135+
'lib/libc/wasi/LICENSE-MIT',
136+
'lib/libcxx/LICENSE.TXT',
137+
'lib/libcxxabi/LICENSE.TXT',
138+
'lib/libunwind/LICENSE.TXT'
139+
]
140+
141+
found_license_files = set()
142+
110143
for entry_name, entry_mode, entry_data in iter_archive_contents(archive):
111144
entry_name = '/'.join(entry_name.split('/')[1:])
112145
if not entry_name:
113146
continue
114147
if entry_name.startswith('doc/'):
115148
continue
116149

150+
# The license files and their paths MUST remain in sync with
151+
# the paths in the official Zig tarballs and with the ones
152+
# defined below in the metadata.
153+
if any(entry_name == license_path for license_path in [
154+
'LICENSE',
155+
'lib/libc/glibc/LICENSES',
156+
'lib/libc/mingw/COPYING',
157+
'lib/libc/musl/COPYRIGHT',
158+
'lib/libc/wasi/LICENSE',
159+
'lib/libc/wasi/LICENSE-APACHE',
160+
'lib/libc/wasi/LICENSE-APACHE-LLVM',
161+
'lib/libc/wasi/LICENSE-MIT',
162+
'lib/libcxx/LICENSE.TXT',
163+
'lib/libcxxabi/LICENSE.TXT',
164+
'lib/libunwind/LICENSE.TXT'
165+
]):
166+
license_contents[entry_name] = entry_data
167+
117168
zip_info = ZipInfo(f'ziglang/{entry_name}')
118169
zip_info.external_attr = (entry_mode & 0xFFFF) << 16
119170
contents[zip_info] = entry_data
@@ -131,13 +182,22 @@ def write_ziglang_wheel(out_dir, *, version, platform, archive):
131182
with open('README.pypi.md') as f:
132183
description = f.read()
133184

185+
dist_info = f'ziglang-{version}.dist-info'
186+
for license_path, license_data in license_files.items():
187+
contents[f"{dist_info}/licenses/ziglang/{license_path}"] = license_data
188+
134189
return write_wheel(out_dir,
135190
name='ziglang',
136191
version=version,
137192
tag=f'py3-none-{platform}',
138193
metadata=[
139194
('Summary', 'Zig is a general-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.'),
140195
('Description-Content-Type', "'text/markdown'; charset=UTF-8; variant=GFM"),
196+
# The license expression and the file paths MUST remain in sync
197+
# with the paths in the official Zig tarballs and with the ones
198+
# defined above in the contents. The difference is that these
199+
# are prefixed with "ziglang/" to match the paths in the wheel
200+
# for metadata compliance.
141201
('License-Expression', 'MIT'),
142202
('License-File', 'LICENSE'),
143203
('License-File', 'ziglang/lib/libc/glibc/LICENSES'),

0 commit comments

Comments
 (0)