Skip to content

Commit

Permalink
Windows installer: Collect information on dependencies & licenses
Browse files Browse the repository at this point in the history
  • Loading branch information
martinling committed Jul 6, 2024
1 parent f2839aa commit 150999d
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ jobs:
with:
run: cargo test

- name: List dependencies (Windows)
run: |
python wix/rust_licenses.py > wix/LICENSE-static-libraries.txt
python wix/vcpkg_licenses.py > wix/LICENSE-dynamic-libraries.txt
- name: Build installer (Windows)
run: cargo wix --no-build --nocapture -v
if: matrix.os == 'windows-latest'
Expand Down
10 changes: 10 additions & 0 deletions wix/main.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@
</Component>
-->

<Component Id='LICENSE_Packetry' Guid='25f09134-ab56-4028-ad5c-461edf5a850a'>
<File Id='LICENSE_Packetry' Name='LICENSE-Packetry.txt' DiskId='1' Source='LICENSE'/>
</Component>
<Component Id='LICENSE_static' Guid='3ba11a89-de46-40c8-b2ca-68d4ea7257b1'>
<File Id='LICENSE_static' Name='LICENSE-static-libraries.txt' DiskId='1' Source='wix/LICENSE-static-libraries.txt'/>
</Component>
<Component Id='LICENSE_dynamic' Guid='40f0f16e-e70f-4f16-af2a-d3e19413375c'>
<File Id='LICENSE_dynamic' Name='LICENSE-dynamic-libraries.txt' DiskId='1' Source='wix/LICENSE-dynamic-libraries.txt'/>
</Component>

<Directory Id='Bin' Name='bin'>
<Component Id='Path' Guid='11E1B3A0-F153-41F2-8080-7225FB20816F' KeyPath='yes'>
<Environment
Expand Down
28 changes: 28 additions & 0 deletions wix/rust_licenses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import subprocess

cargo_result = subprocess.run(
['cargo', 'license', '--authors', '--do-not-bundle', '--color=never'],
capture_output=True)

cargo_result.check_returncode()

print("The following Rust packages are statically linked into Packetry:")

for line in cargo_result.stdout.decode().rstrip().split("\n"):
package, remainder = line.split(": ")
version, licenses, by, authors = remainder.split(", ")
licenses = licenses[1:-1] \
.replace(' OR ', ' or ') \
.replace(' WITH ', ' with ') \
.replace(' AND ', ' and ')
authors = authors[1:-1].split("|")
print()
print(f"{package} version {version}")
if len(authors) == 1:
print(f"Author: {str.join(', ', authors)}")
else:
print("Authors:")
for author in authors:
print(f" {author}")
print(f"License: {licenses}")
print(f"Link: https://crates.io/crates/{package}")
81 changes: 81 additions & 0 deletions wix/vcpkg_licenses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import subprocess
import json
import re

vcpkg_result = subprocess.run(
['./vcpkg/vcpkg', 'depend-info', 'gtk'],
capture_output=True)

vcpkg_result.check_returncode()

cargo_result = subprocess.run(
['cargo', 'license', '--authors', '--do-not-bundle', '--color=never'],
capture_output=True)

cargo_result.check_returncode()

packages = set()

# Find all packages we depend on.
for line in vcpkg_result.stderr.decode().rstrip().split('\n'):
header, remainder = line.split(': ')
package = header.split('[')[0]
packages.add(package)
dependencies = remainder.split(', ')
packages |= set(dependencies)

# Discard empty package names.
packages.discard('')

# Discard vcpkg build tools.
packages = set(p for p in packages if not p.startswith('vcpkg-'))

# gperf is needed to build fontconfig, but is not linked to.
packages.discard('gperf')

# gettext is needed to build many dependencies, but is not linked to.
packages.discard('gettext')

# getopt, pthread and pthreads are virtual packages.
packages.discard('getopt')
packages.discard('pthread')
packages.discard('pthreads')

# sassc is used to build GTK, but is not linked to.
packages.discard('sassc')

versions = {}

# These packages are missing license information in vcpkg.
licenses = {
'libiconv': ['LGPL-2.1-or-later'],
'egl-registry': ['Apache-2.0', 'MIT'],
'liblzma': ['BSD-0-Clause'],
'libsass': ['MIT'],
}

# These packages are missing homepage information in vcpkg.
homepages = {
'fribidi': 'https://github.com/fribidi/fribidi',
}

for package in packages:
metadata = json.load(open(f'vcpkg/ports/{package}/vcpkg.json'))
version = metadata.get('version-semver',
metadata.get('version',
metadata.get('version-date')))
if version is None:
raise KeyError(f"Couldn't find a version for package {package}")
versions[package] = version
if metadata.get('homepage') is not None:
homepages[package] = metadata['homepage']
if metadata.get('license') is not None:
licenses[package] = metadata['license'].split(' OR ')

print("The following libraries are dynamically linked into Packetry:")

for package in sorted(packages):
print()
print(f"{package} version {versions[package]}")
print(f"Homepage: {homepages[package]}")
print(f"License: {str.join(' or ', licenses[package])}")

0 comments on commit 150999d

Please sign in to comment.