From 0cc1cfb0cc5971d22c4f6294e2b510d74c46afda Mon Sep 17 00:00:00 2001
From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Date: Thu, 29 Feb 2024 15:31:24 +0200
Subject: [PATCH 1/9] Move global into main() to avoid shadowing
---
winbuild/build_prepare.py | 50 ++++++++++++++++++++++++---------------
1 file changed, 31 insertions(+), 19 deletions(-)
diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py
index 2ee9872e6..ede161c44 100644
--- a/winbuild/build_prepare.py
+++ b/winbuild/build_prepare.py
@@ -456,11 +456,14 @@ def download_dep(url: str, file: str) -> None:
raise RuntimeError(ex)
-def extract_dep(url: str, filename: str) -> None:
+def extract_dep(url: str, filename: str, prefs: dict[str, str]) -> None:
import tarfile
import zipfile
- file = os.path.join(args.depends_dir, filename)
+ depends_dir = prefs["depends_dir"]
+ sources_dir = prefs["src_dir"]
+
+ file = os.path.join(depends_dir, filename)
if not os.path.exists(file):
# First try our mirror
mirror_url = (
@@ -499,13 +502,15 @@ def extract_dep(url: str, filename: str) -> None:
raise RuntimeError(msg)
-def write_script(name: str, lines: list[str]) -> None:
- name = os.path.join(args.build_dir, name)
+def write_script(
+ name: str, lines: list[str], prefs: dict[str, str], verbose: bool
+) -> None:
+ name = os.path.join(prefs["build_dir"], name)
lines = [line.format(**prefs) for line in lines]
print("Writing " + name)
with open(name, "w", newline="") as f:
f.write(os.linesep.join(lines))
- if args.verbose:
+ if verbose:
for line in lines:
print(" " + line)
@@ -521,7 +526,7 @@ def get_footer(dep: dict) -> list[str]:
return lines
-def build_env() -> None:
+def build_env(prefs: dict[str, str], verbose: bool) -> None:
lines = [
"if defined DISTUTILS_USE_SDK goto end",
cmd_set("INCLUDE", "{inc_dir}"),
@@ -534,15 +539,17 @@ def build_env() -> None:
":end",
"@echo on",
]
- write_script("build_env.cmd", lines)
+ write_script("build_env.cmd", lines, prefs, verbose)
-def build_dep(name: str) -> str:
+def build_dep(name: str, prefs: dict[str, str], verbose: bool) -> str:
dep = DEPS[name]
dir = dep["dir"]
file = f"build_dep_{name}.cmd"
+ license_dir = prefs["license_dir"]
+ sources_dir = prefs["src_dir"]
- extract_dep(dep["url"], dep["filename"])
+ extract_dep(dep["url"], dep["filename"], prefs)
licenses = dep["license"]
if isinstance(licenses, str):
@@ -583,11 +590,11 @@ def build_dep(name: str) -> str:
*get_footer(dep),
]
- write_script(file, lines)
+ write_script(file, lines, prefs, verbose)
return file
-def build_dep_all() -> None:
+def build_dep_all(disabled: list[str], prefs: dict[str, str], verbose: bool) -> None:
lines = [r'call "{build_dir}\build_env.cmd"']
gha_groups = "GITHUB_ACTIONS" in os.environ
for dep_name in DEPS:
@@ -595,7 +602,7 @@ def build_dep_all() -> None:
if dep_name in disabled:
print(f"Skipping disabled dependency {dep_name}")
continue
- script = build_dep(dep_name)
+ script = build_dep(dep_name, prefs, verbose)
if gha_groups:
lines.append(f"@echo ::group::Running {script}")
lines.append(rf'cmd.exe /c "{{build_dir}}\{script}"')
@@ -604,10 +611,10 @@ def build_dep_all() -> None:
lines.append("@echo ::endgroup::")
print()
lines.append("@echo All Pillow dependencies built successfully!")
- write_script("build_dep_all.cmd", lines)
+ write_script("build_dep_all.cmd", lines, prefs, verbose)
-if __name__ == "__main__":
+def main() -> None:
winbuild_dir = os.path.dirname(os.path.realpath(__file__))
pillow_dir = os.path.realpath(os.path.join(winbuild_dir, ".."))
@@ -718,12 +725,13 @@ if __name__ == "__main__":
"pillow_dir": pillow_dir,
"winbuild_dir": winbuild_dir,
# Build paths
+ "bin_dir": bin_dir,
"build_dir": args.build_dir,
+ "depends_dir": args.depends_dir,
"inc_dir": inc_dir,
"lib_dir": lib_dir,
- "bin_dir": bin_dir,
- "src_dir": sources_dir,
"license_dir": license_dir,
+ "src_dir": sources_dir,
# Compilers / Tools
**msvs,
"cmake": "cmake.exe", # TODO find CMAKE automatically
@@ -736,6 +744,10 @@ if __name__ == "__main__":
print()
- write_script(".gitignore", ["*"])
- build_env()
- build_dep_all()
+ write_script(".gitignore", ["*"], prefs, args.verbose)
+ build_env(prefs, args.verbose)
+ build_dep_all(disabled, prefs, args.verbose)
+
+
+if __name__ == "__main__":
+ main()
From fb3cb60c4c2c9919aef0f1d9ee95dedf2c2533ff Mon Sep 17 00:00:00 2001
From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Date: Thu, 29 Feb 2024 17:09:51 +0200
Subject: [PATCH 2/9] Refactor version numbers into constants
---
winbuild/build_prepare.py | 107 +++++++++++++++++++++++---------------
1 file changed, 64 insertions(+), 43 deletions(-)
diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py
index ede161c44..fbd0276ed 100644
--- a/winbuild/build_prepare.py
+++ b/winbuild/build_prepare.py
@@ -109,13 +109,30 @@ ARCHITECTURES = {
"ARM64": {"vcvars_arch": "x86_arm64", "msbuild_arch": "ARM64"},
}
+BROTLI_VERSION = "1.1.0"
+FREETYPE_VERSION = "2.13.2"
+FRIBIDI_VERSION = "1.0.13"
+HARFBUZZ_VERSION = "8.3.0"
+JPEGTURBO_VERSION = "3.0.1"
+LCMS2_VERSION = "2.16"
+LIBPNG_VERSION = "1.6.39"
+LIBPNG_DOTLESS = LIBPNG_VERSION.replace(".", "")
+LIBPNG_XY = "".join(LIBPNG_VERSION.split(".")[:2])
+LIBWEBP_VERSION = "1.3.2"
+LIBXCB_VERSION = "1.16"
+OPENJPEG_VERSION = "2.5.2"
+TIFF_VERSION = "4.6.0"
+XZ_VERSION = "5.4.5"
+ZLIB_VERSION = "1.3"
+ZLIB_DOTLESS = ZLIB_VERSION.replace(".", "")
+
# dependencies, listed in order of compilation
DEPS = {
"libjpeg": {
- "url": SF_PROJECTS
- + "/libjpeg-turbo/files/3.0.1/libjpeg-turbo-3.0.1.tar.gz/download",
- "filename": "libjpeg-turbo-3.0.1.tar.gz",
- "dir": "libjpeg-turbo-3.0.1",
+ "url": SF_PROJECTS + f"/libjpeg-turbo/files/{JPEGTURBO_VERSION}/"
+ f"libjpeg-turbo-{JPEGTURBO_VERSION}.tar.gz/download",
+ "filename": f"libjpeg-turbo-{JPEGTURBO_VERSION}.tar.gz",
+ "dir": f"libjpeg-turbo-{JPEGTURBO_VERSION}",
"license": ["README.ijg", "LICENSE.md"],
"license_pattern": (
"(LEGAL ISSUES\n============\n\n.+?)\n\nREFERENCES\n=========="
@@ -143,9 +160,9 @@ DEPS = {
"bins": ["cjpeg.exe", "djpeg.exe"],
},
"zlib": {
- "url": "https://zlib.net/zlib13.zip",
- "filename": "zlib13.zip",
- "dir": "zlib-1.3",
+ "url": f"https://zlib.net/zlib{ZLIB_DOTLESS}.zip",
+ "filename": f"zlib{ZLIB_DOTLESS}.zip",
+ "dir": f"zlib-{ZLIB_VERSION}",
"license": "README",
"license_pattern": "Copyright notice:\n\n(.+)$",
"build": [
@@ -157,9 +174,9 @@ DEPS = {
"libs": [r"*.lib"],
},
"xz": {
- "url": SF_PROJECTS + "/lzmautils/files/xz-5.4.5.tar.gz/download",
- "filename": "xz-5.4.5.tar.gz",
- "dir": "xz-5.4.5",
+ "url": SF_PROJECTS + f"/lzmautils/files/xz-{XZ_VERSION}.tar.gz/download",
+ "filename": f"xz-{XZ_VERSION}.tar.gz",
+ "dir": f"xz-{XZ_VERSION}",
"license": "COPYING",
"build": [
*cmds_cmake("liblzma", "-DBUILD_SHARED_LIBS:BOOL=OFF"),
@@ -170,9 +187,9 @@ DEPS = {
"libs": [r"liblzma.lib"],
},
"libwebp": {
- "url": "http://downloads.webmproject.org/releases/webp/libwebp-1.3.2.tar.gz",
- "filename": "libwebp-1.3.2.tar.gz",
- "dir": "libwebp-1.3.2",
+ "url": f"http://downloads.webmproject.org/releases/webp/libwebp-{LIBWEBP_VERSION}.tar.gz",
+ "filename": f"libwebp-{LIBWEBP_VERSION}.tar.gz",
+ "dir": f"libwebp-{LIBWEBP_VERSION}",
"license": "COPYING",
"patch": {
r"src\enc\picture_csp_enc.c": {
@@ -192,9 +209,9 @@ DEPS = {
"libs": [r"libsharpyuv.lib", r"libwebp*.lib"],
},
"libtiff": {
- "url": "https://download.osgeo.org/libtiff/tiff-4.6.0.tar.gz",
- "filename": "tiff-4.6.0.tar.gz",
- "dir": "tiff-4.6.0",
+ "url": f"https://download.osgeo.org/libtiff/tiff-{TIFF_VERSION}.tar.gz",
+ "filename": f"tiff-{TIFF_VERSION}.tar.gz",
+ "dir": f"tiff-{TIFF_VERSION}",
"license": "LICENSE.md",
"patch": {
r"libtiff\tif_lzma.c": {
@@ -224,21 +241,22 @@ DEPS = {
"libs": [r"libtiff\*.lib"],
},
"libpng": {
- "url": SF_PROJECTS + "/libpng/files/libpng16/1.6.39/lpng1639.zip/download",
- "filename": "lpng1639.zip",
- "dir": "lpng1639",
+ "url": SF_PROJECTS + f"/libpng/files/libpng{LIBPNG_XY}/{LIBPNG_VERSION}/"
+ f"lpng{LIBPNG_DOTLESS}.zip/download",
+ "filename": f"lpng{LIBPNG_DOTLESS}.zip",
+ "dir": f"lpng{LIBPNG_DOTLESS}",
"license": "LICENSE",
"build": [
*cmds_cmake("png_static", "-DPNG_SHARED:BOOL=OFF", "-DPNG_TESTS:BOOL=OFF"),
- cmd_copy("libpng16_static.lib", "libpng16.lib"),
+ cmd_copy(f"libpng{LIBPNG_XY}_static.lib", f"libpng{LIBPNG_XY}.lib"),
],
"headers": [r"png*.h"],
- "libs": [r"libpng16.lib"],
+ "libs": [rf"libpng{LIBPNG_XY}.lib"],
},
"brotli": {
- "url": "https://github.com/google/brotli/archive/refs/tags/v1.1.0.tar.gz",
- "filename": "brotli-1.1.0.tar.gz",
- "dir": "brotli-1.1.0",
+ "url": f"https://github.com/google/brotli/archive/refs/tags/v{BROTLI_VERSION}.tar.gz",
+ "filename": f"brotli-{BROTLI_VERSION}.tar.gz",
+ "dir": f"brotli-{BROTLI_VERSION}",
"license": "LICENSE",
"build": [
*cmds_cmake(("brotlicommon", "brotlidec"), "-DBUILD_SHARED_LIBS:BOOL=OFF"),
@@ -247,9 +265,9 @@ DEPS = {
"libs": ["*.lib"],
},
"freetype": {
- "url": "https://download.savannah.gnu.org/releases/freetype/freetype-2.13.2.tar.gz",
- "filename": "freetype-2.13.2.tar.gz",
- "dir": "freetype-2.13.2",
+ "url": f"https://download.savannah.gnu.org/releases/freetype/freetype-{FREETYPE_VERSION}.tar.gz",
+ "filename": f"freetype-{FREETYPE_VERSION}.tar.gz",
+ "dir": f"freetype-{FREETYPE_VERSION}",
"license": ["LICENSE.TXT", r"docs\FTL.TXT", r"docs\GPLv2.TXT"],
"patch": {
r"builds\windows\vc2010\freetype.vcxproj": {
@@ -262,7 +280,7 @@ DEPS = {
"": "FT_CONFIG_OPTION_SYSTEM_ZLIB;FT_CONFIG_OPTION_USE_PNG;FT_CONFIG_OPTION_USE_HARFBUZZ;FT_CONFIG_OPTION_USE_BROTLI", # noqa: E501
"": r"{dir_harfbuzz}\src;{inc_dir}", # noqa: E501
"": "{lib_dir}", # noqa: E501
- "": "zlib.lib;libpng16.lib;brotlicommon.lib;brotlidec.lib", # noqa: E501
+ "": f"zlib.lib;libpng{LIBPNG_XY}.lib;brotlicommon.lib;brotlidec.lib", # noqa: E501
},
r"src/autofit/afshaper.c": {
# link against harfbuzz.lib
@@ -282,9 +300,10 @@ DEPS = {
"libs": [r"objs\{msbuild_arch}\Release Static\freetype.lib"],
},
"lcms2": {
- "url": SF_PROJECTS + "/lcms/files/lcms/2.16/lcms2-2.16.tar.gz/download",
- "filename": "lcms2-2.16.tar.gz",
- "dir": "lcms2-2.16",
+ "url": SF_PROJECTS
+ + f"/lcms/files/lcms/{LCMS2_VERSION}/lcms2-{LCMS2_VERSION}.tar.gz/download",
+ "filename": f"lcms2-{LCMS2_VERSION}.tar.gz",
+ "dir": f"lcms2-{LCMS2_VERSION}",
"license": "LICENSE",
"patch": {
r"Projects\VC2022\lcms2_static\lcms2_static.vcxproj": {
@@ -308,16 +327,18 @@ DEPS = {
"libs": [r"Lib\MS\*.lib"],
},
"openjpeg": {
- "url": "https://github.com/uclouvain/openjpeg/archive/v2.5.2.tar.gz",
- "filename": "openjpeg-2.5.2.tar.gz",
- "dir": "openjpeg-2.5.2",
+ "url": f"https://github.com/uclouvain/openjpeg/archive/v{OPENJPEG_VERSION}.tar.gz",
+ "filename": f"openjpeg-{OPENJPEG_VERSION}.tar.gz",
+ "dir": f"openjpeg-{OPENJPEG_VERSION}",
"license": "LICENSE",
"build": [
*cmds_cmake(
"openjp2", "-DBUILD_CODEC:BOOL=OFF", "-DBUILD_SHARED_LIBS:BOOL=OFF"
),
- cmd_mkdir(r"{inc_dir}\openjpeg-2.5.2"),
- cmd_copy(r"src\lib\openjp2\*.h", r"{inc_dir}\openjpeg-2.5.2"),
+ cmd_mkdir(rf"{{inc_dir}}\openjpeg-{OPENJPEG_VERSION}"),
+ cmd_copy(
+ r"src\lib\openjp2\*.h", rf"{{inc_dir}}\openjpeg-{OPENJPEG_VERSION}"
+ ),
],
"libs": [r"bin\*.lib"],
},
@@ -343,9 +364,9 @@ DEPS = {
"libs": [r"imagequant.lib"],
},
"harfbuzz": {
- "url": "https://github.com/harfbuzz/harfbuzz/archive/8.3.0.zip",
- "filename": "harfbuzz-8.3.0.zip",
- "dir": "harfbuzz-8.3.0",
+ "url": f"https://github.com/harfbuzz/harfbuzz/archive/{HARFBUZZ_VERSION}.zip",
+ "filename": f"harfbuzz-{HARFBUZZ_VERSION}.zip",
+ "dir": f"harfbuzz-{HARFBUZZ_VERSION}",
"license": "COPYING",
"build": [
*cmds_cmake(
@@ -358,12 +379,12 @@ DEPS = {
"libs": [r"*.lib"],
},
"fribidi": {
- "url": "https://github.com/fribidi/fribidi/archive/v1.0.13.zip",
- "filename": "fribidi-1.0.13.zip",
- "dir": "fribidi-1.0.13",
+ "url": f"https://github.com/fribidi/fribidi/archive/v{FRIBIDI_VERSION}.zip",
+ "filename": f"fribidi-{FRIBIDI_VERSION}.zip",
+ "dir": f"fribidi-{FRIBIDI_VERSION}",
"license": "COPYING",
"build": [
- cmd_copy(r"COPYING", r"{bin_dir}\fribidi-1.0.13-COPYING"),
+ cmd_copy(r"COPYING", rf"{{bin_dir}}\fribidi-{FRIBIDI_VERSION}-COPYING"),
cmd_copy(r"{winbuild_dir}\fribidi.cmake", r"CMakeLists.txt"),
# generated tab.i files cannot be cross-compiled
" ^&^& ".join(
From 0b546765b8b12280eaf78807173ebf99be73c306 Mon Sep 17 00:00:00 2001
From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Date: Thu, 29 Feb 2024 17:22:22 +0200
Subject: [PATCH 3/9] Refactor constants into dict
---
winbuild/build_prepare.py | 127 +++++++++++++++++++-------------------
1 file changed, 65 insertions(+), 62 deletions(-)
diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py
index fbd0276ed..efffbf5ac 100644
--- a/winbuild/build_prepare.py
+++ b/winbuild/build_prepare.py
@@ -109,30 +109,33 @@ ARCHITECTURES = {
"ARM64": {"vcvars_arch": "x86_arm64", "msbuild_arch": "ARM64"},
}
-BROTLI_VERSION = "1.1.0"
-FREETYPE_VERSION = "2.13.2"
-FRIBIDI_VERSION = "1.0.13"
-HARFBUZZ_VERSION = "8.3.0"
-JPEGTURBO_VERSION = "3.0.1"
-LCMS2_VERSION = "2.16"
-LIBPNG_VERSION = "1.6.39"
-LIBPNG_DOTLESS = LIBPNG_VERSION.replace(".", "")
-LIBPNG_XY = "".join(LIBPNG_VERSION.split(".")[:2])
-LIBWEBP_VERSION = "1.3.2"
-LIBXCB_VERSION = "1.16"
-OPENJPEG_VERSION = "2.5.2"
-TIFF_VERSION = "4.6.0"
-XZ_VERSION = "5.4.5"
-ZLIB_VERSION = "1.3"
-ZLIB_DOTLESS = ZLIB_VERSION.replace(".", "")
+V = {
+ "BROTLI": "1.1.0",
+ "FREETYPE": "2.13.2",
+ "FRIBIDI": "1.0.13",
+ "HARFBUZZ": "8.3.0",
+ "JPEGTURBO": "3.0.1",
+ "LCMS2": "2.16",
+ "LIBPNG": "1.6.39",
+ "LIBWEBP": "1.3.2",
+ "LIBXCB": "1.16",
+ "OPENJPEG": "2.5.2",
+ "TIFF": "4.6.0",
+ "XZ": "5.4.5",
+ "ZLIB": "1.3",
+}
+V["LIBPNG_DOTLESS"] = V["LIBPNG"].replace(".", "")
+V["LIBPNG_XY"] = "".join(V["LIBPNG"].split(".")[:2])
+V["ZLIB_DOTLESS"] = V["ZLIB"].replace(".", "")
+
# dependencies, listed in order of compilation
DEPS = {
"libjpeg": {
- "url": SF_PROJECTS + f"/libjpeg-turbo/files/{JPEGTURBO_VERSION}/"
- f"libjpeg-turbo-{JPEGTURBO_VERSION}.tar.gz/download",
- "filename": f"libjpeg-turbo-{JPEGTURBO_VERSION}.tar.gz",
- "dir": f"libjpeg-turbo-{JPEGTURBO_VERSION}",
+ "url": SF_PROJECTS + f"/libjpeg-turbo/files/{V['JPEGTURBO']}/"
+ f"libjpeg-turbo-{V['JPEGTURBO']}.tar.gz/download",
+ "filename": f"libjpeg-turbo-{V['JPEGTURBO']}.tar.gz",
+ "dir": f"libjpeg-turbo-{V['JPEGTURBO']}",
"license": ["README.ijg", "LICENSE.md"],
"license_pattern": (
"(LEGAL ISSUES\n============\n\n.+?)\n\nREFERENCES\n=========="
@@ -160,9 +163,9 @@ DEPS = {
"bins": ["cjpeg.exe", "djpeg.exe"],
},
"zlib": {
- "url": f"https://zlib.net/zlib{ZLIB_DOTLESS}.zip",
- "filename": f"zlib{ZLIB_DOTLESS}.zip",
- "dir": f"zlib-{ZLIB_VERSION}",
+ "url": f"https://zlib.net/zlib{V['ZLIB_DOTLESS']}.zip",
+ "filename": f"zlib{V['ZLIB_DOTLESS']}.zip",
+ "dir": f"zlib-{V['ZLIB']}",
"license": "README",
"license_pattern": "Copyright notice:\n\n(.+)$",
"build": [
@@ -174,9 +177,9 @@ DEPS = {
"libs": [r"*.lib"],
},
"xz": {
- "url": SF_PROJECTS + f"/lzmautils/files/xz-{XZ_VERSION}.tar.gz/download",
- "filename": f"xz-{XZ_VERSION}.tar.gz",
- "dir": f"xz-{XZ_VERSION}",
+ "url": SF_PROJECTS + f"/lzmautils/files/xz-{V['XZ']}.tar.gz/download",
+ "filename": f"xz-{V['XZ']}.tar.gz",
+ "dir": f"xz-{V['XZ']}",
"license": "COPYING",
"build": [
*cmds_cmake("liblzma", "-DBUILD_SHARED_LIBS:BOOL=OFF"),
@@ -187,9 +190,9 @@ DEPS = {
"libs": [r"liblzma.lib"],
},
"libwebp": {
- "url": f"http://downloads.webmproject.org/releases/webp/libwebp-{LIBWEBP_VERSION}.tar.gz",
- "filename": f"libwebp-{LIBWEBP_VERSION}.tar.gz",
- "dir": f"libwebp-{LIBWEBP_VERSION}",
+ "url": f"http://downloads.webmproject.org/releases/webp/libwebp-{V['LIBWEBP']}.tar.gz",
+ "filename": f"libwebp-{V['LIBWEBP']}.tar.gz",
+ "dir": f"libwebp-{V['LIBWEBP']}",
"license": "COPYING",
"patch": {
r"src\enc\picture_csp_enc.c": {
@@ -209,9 +212,9 @@ DEPS = {
"libs": [r"libsharpyuv.lib", r"libwebp*.lib"],
},
"libtiff": {
- "url": f"https://download.osgeo.org/libtiff/tiff-{TIFF_VERSION}.tar.gz",
- "filename": f"tiff-{TIFF_VERSION}.tar.gz",
- "dir": f"tiff-{TIFF_VERSION}",
+ "url": f"https://download.osgeo.org/libtiff/tiff-{V['TIFF']}.tar.gz",
+ "filename": f"tiff-{V['TIFF']}.tar.gz",
+ "dir": f"tiff-{V['TIFF']}",
"license": "LICENSE.md",
"patch": {
r"libtiff\tif_lzma.c": {
@@ -241,22 +244,24 @@ DEPS = {
"libs": [r"libtiff\*.lib"],
},
"libpng": {
- "url": SF_PROJECTS + f"/libpng/files/libpng{LIBPNG_XY}/{LIBPNG_VERSION}/"
- f"lpng{LIBPNG_DOTLESS}.zip/download",
- "filename": f"lpng{LIBPNG_DOTLESS}.zip",
- "dir": f"lpng{LIBPNG_DOTLESS}",
+ "url": SF_PROJECTS + f"/libpng/files/libpng{V['LIBPNG_XY']}/{V['LIBPNG']}/"
+ f"lpng{V['LIBPNG_DOTLESS']}.zip/download",
+ "filename": f"lpng{V['LIBPNG_DOTLESS']}.zip",
+ "dir": f"lpng{V['LIBPNG_DOTLESS']}",
"license": "LICENSE",
"build": [
*cmds_cmake("png_static", "-DPNG_SHARED:BOOL=OFF", "-DPNG_TESTS:BOOL=OFF"),
- cmd_copy(f"libpng{LIBPNG_XY}_static.lib", f"libpng{LIBPNG_XY}.lib"),
+ cmd_copy(
+ f"libpng{V['LIBPNG_XY']}_static.lib", f"libpng{V['LIBPNG_XY']}.lib"
+ ),
],
"headers": [r"png*.h"],
- "libs": [rf"libpng{LIBPNG_XY}.lib"],
+ "libs": [rf"libpng{V['LIBPNG_XY']}.lib"],
},
"brotli": {
- "url": f"https://github.com/google/brotli/archive/refs/tags/v{BROTLI_VERSION}.tar.gz",
- "filename": f"brotli-{BROTLI_VERSION}.tar.gz",
- "dir": f"brotli-{BROTLI_VERSION}",
+ "url": f"https://github.com/google/brotli/archive/refs/tags/v{V['BROTLI']}.tar.gz",
+ "filename": f"brotli-{V['BROTLI']}.tar.gz",
+ "dir": f"brotli-{V['BROTLI']}",
"license": "LICENSE",
"build": [
*cmds_cmake(("brotlicommon", "brotlidec"), "-DBUILD_SHARED_LIBS:BOOL=OFF"),
@@ -265,9 +270,9 @@ DEPS = {
"libs": ["*.lib"],
},
"freetype": {
- "url": f"https://download.savannah.gnu.org/releases/freetype/freetype-{FREETYPE_VERSION}.tar.gz",
- "filename": f"freetype-{FREETYPE_VERSION}.tar.gz",
- "dir": f"freetype-{FREETYPE_VERSION}",
+ "url": f"https://download.savannah.gnu.org/releases/freetype/freetype-{V['FREETYPE']}.tar.gz",
+ "filename": f"freetype-{V['FREETYPE']}.tar.gz",
+ "dir": f"freetype-{V['FREETYPE']}",
"license": ["LICENSE.TXT", r"docs\FTL.TXT", r"docs\GPLv2.TXT"],
"patch": {
r"builds\windows\vc2010\freetype.vcxproj": {
@@ -280,7 +285,7 @@ DEPS = {
"": "FT_CONFIG_OPTION_SYSTEM_ZLIB;FT_CONFIG_OPTION_USE_PNG;FT_CONFIG_OPTION_USE_HARFBUZZ;FT_CONFIG_OPTION_USE_BROTLI", # noqa: E501
"": r"{dir_harfbuzz}\src;{inc_dir}", # noqa: E501
"": "{lib_dir}", # noqa: E501
- "": f"zlib.lib;libpng{LIBPNG_XY}.lib;brotlicommon.lib;brotlidec.lib", # noqa: E501
+ "": f"zlib.lib;libpng{V['LIBPNG_XY']}.lib;brotlicommon.lib;brotlidec.lib", # noqa: E501
},
r"src/autofit/afshaper.c": {
# link against harfbuzz.lib
@@ -301,9 +306,9 @@ DEPS = {
},
"lcms2": {
"url": SF_PROJECTS
- + f"/lcms/files/lcms/{LCMS2_VERSION}/lcms2-{LCMS2_VERSION}.tar.gz/download",
- "filename": f"lcms2-{LCMS2_VERSION}.tar.gz",
- "dir": f"lcms2-{LCMS2_VERSION}",
+ + f"/lcms/files/lcms/{V['LCMS2']}/lcms2-{V['LCMS2']}.tar.gz/download",
+ "filename": f"lcms2-{V['LCMS2']}.tar.gz",
+ "dir": f"lcms2-{V['LCMS2']}",
"license": "LICENSE",
"patch": {
r"Projects\VC2022\lcms2_static\lcms2_static.vcxproj": {
@@ -327,18 +332,16 @@ DEPS = {
"libs": [r"Lib\MS\*.lib"],
},
"openjpeg": {
- "url": f"https://github.com/uclouvain/openjpeg/archive/v{OPENJPEG_VERSION}.tar.gz",
- "filename": f"openjpeg-{OPENJPEG_VERSION}.tar.gz",
- "dir": f"openjpeg-{OPENJPEG_VERSION}",
+ "url": f"https://github.com/uclouvain/openjpeg/archive/v{V['OPENJPEG']}.tar.gz",
+ "filename": f"openjpeg-{V['OPENJPEG']}.tar.gz",
+ "dir": f"openjpeg-{V['OPENJPEG']}",
"license": "LICENSE",
"build": [
*cmds_cmake(
"openjp2", "-DBUILD_CODEC:BOOL=OFF", "-DBUILD_SHARED_LIBS:BOOL=OFF"
),
- cmd_mkdir(rf"{{inc_dir}}\openjpeg-{OPENJPEG_VERSION}"),
- cmd_copy(
- r"src\lib\openjp2\*.h", rf"{{inc_dir}}\openjpeg-{OPENJPEG_VERSION}"
- ),
+ cmd_mkdir(rf"{{inc_dir}}\openjpeg-{V['OPENJPEG']}"),
+ cmd_copy(r"src\lib\openjp2\*.h", rf"{{inc_dir}}\openjpeg-{V['OPENJPEG']}"),
],
"libs": [r"bin\*.lib"],
},
@@ -364,9 +367,9 @@ DEPS = {
"libs": [r"imagequant.lib"],
},
"harfbuzz": {
- "url": f"https://github.com/harfbuzz/harfbuzz/archive/{HARFBUZZ_VERSION}.zip",
- "filename": f"harfbuzz-{HARFBUZZ_VERSION}.zip",
- "dir": f"harfbuzz-{HARFBUZZ_VERSION}",
+ "url": f"https://github.com/harfbuzz/harfbuzz/archive/{V['HARFBUZZ']}.zip",
+ "filename": f"harfbuzz-{V['HARFBUZZ']}.zip",
+ "dir": f"harfbuzz-{V['HARFBUZZ']}",
"license": "COPYING",
"build": [
*cmds_cmake(
@@ -379,12 +382,12 @@ DEPS = {
"libs": [r"*.lib"],
},
"fribidi": {
- "url": f"https://github.com/fribidi/fribidi/archive/v{FRIBIDI_VERSION}.zip",
- "filename": f"fribidi-{FRIBIDI_VERSION}.zip",
- "dir": f"fribidi-{FRIBIDI_VERSION}",
+ "url": f"https://github.com/fribidi/fribidi/archive/v{V['FRIBIDI']}.zip",
+ "filename": f"fribidi-{V['FRIBIDI']}.zip",
+ "dir": f"fribidi-{V['FRIBIDI']}",
"license": "COPYING",
"build": [
- cmd_copy(r"COPYING", rf"{{bin_dir}}\fribidi-{FRIBIDI_VERSION}-COPYING"),
+ cmd_copy(r"COPYING", rf"{{bin_dir}}\fribidi-{V['FRIBIDI']}-COPYING"),
cmd_copy(r"{winbuild_dir}\fribidi.cmake", r"CMakeLists.txt"),
# generated tab.i files cannot be cross-compiled
" ^&^& ".join(
From 33d92819ef9e6327ec8e3fc2b2b68e9f05d65fc0 Mon Sep 17 00:00:00 2001
From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Date: Sun, 3 Mar 2024 07:59:36 -0700
Subject: [PATCH 4/9] Include SF_PROJECTS in f-strings
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Ondrej Baranovič
---
winbuild/build_prepare.py | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py
index efffbf5ac..865e08c22 100644
--- a/winbuild/build_prepare.py
+++ b/winbuild/build_prepare.py
@@ -132,7 +132,7 @@ V["ZLIB_DOTLESS"] = V["ZLIB"].replace(".", "")
# dependencies, listed in order of compilation
DEPS = {
"libjpeg": {
- "url": SF_PROJECTS + f"/libjpeg-turbo/files/{V['JPEGTURBO']}/"
+ "url": f"{SF_PROJECTS}/libjpeg-turbo/files/{V['JPEGTURBO']}/"
f"libjpeg-turbo-{V['JPEGTURBO']}.tar.gz/download",
"filename": f"libjpeg-turbo-{V['JPEGTURBO']}.tar.gz",
"dir": f"libjpeg-turbo-{V['JPEGTURBO']}",
@@ -177,7 +177,7 @@ DEPS = {
"libs": [r"*.lib"],
},
"xz": {
- "url": SF_PROJECTS + f"/lzmautils/files/xz-{V['XZ']}.tar.gz/download",
+ "url": f"{SF_PROJECTS}/lzmautils/files/xz-{V['XZ']}.tar.gz/download",
"filename": f"xz-{V['XZ']}.tar.gz",
"dir": f"xz-{V['XZ']}",
"license": "COPYING",
@@ -244,7 +244,7 @@ DEPS = {
"libs": [r"libtiff\*.lib"],
},
"libpng": {
- "url": SF_PROJECTS + f"/libpng/files/libpng{V['LIBPNG_XY']}/{V['LIBPNG']}/"
+ "url": f"{SF_PROJECTS}/libpng/files/libpng{V['LIBPNG_XY']}/{V['LIBPNG']}/"
f"lpng{V['LIBPNG_DOTLESS']}.zip/download",
"filename": f"lpng{V['LIBPNG_DOTLESS']}.zip",
"dir": f"lpng{V['LIBPNG_DOTLESS']}",
@@ -305,8 +305,7 @@ DEPS = {
"libs": [r"objs\{msbuild_arch}\Release Static\freetype.lib"],
},
"lcms2": {
- "url": SF_PROJECTS
- + f"/lcms/files/lcms/{V['LCMS2']}/lcms2-{V['LCMS2']}.tar.gz/download",
+ "url": f"{SF_PROJECTS}/lcms/files/lcms/{V['LCMS2']}/lcms2-{V['LCMS2']}.tar.gz/download", # noqa: E501
"filename": f"lcms2-{V['LCMS2']}.tar.gz",
"dir": f"lcms2-{V['LCMS2']}",
"license": "LICENSE",
From b3fa754e971722f31c4c75271d58062f3b15997b Mon Sep 17 00:00:00 2001
From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Date: Sun, 3 Mar 2024 17:11:30 +0200
Subject: [PATCH 5/9] Don't shadow stdlib names
---
winbuild/build_prepare.py | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py
index 865e08c22..657e2f6ec 100644
--- a/winbuild/build_prepare.py
+++ b/winbuild/build_prepare.py
@@ -87,7 +87,7 @@ def cmd_msbuild(
file: str,
configuration: str = "Release",
target: str = "Build",
- platform: str = "{msbuild_arch}",
+ plat: str = "{msbuild_arch}",
) -> str:
return " ".join(
[
@@ -95,7 +95,7 @@ def cmd_msbuild(
f"{file}",
f'/t:"{target}"',
f'/p:Configuration="{configuration}"',
- f"/p:Platform={platform}",
+ f"/p:Platform={plat}",
"/m",
]
)
@@ -567,7 +567,7 @@ def build_env(prefs: dict[str, str], verbose: bool) -> None:
def build_dep(name: str, prefs: dict[str, str], verbose: bool) -> str:
dep = DEPS[name]
- dir = dep["dir"]
+ directory = dep["dir"]
file = f"build_dep_{name}.cmd"
license_dir = prefs["license_dir"]
sources_dir = prefs["src_dir"]
@@ -579,18 +579,18 @@ def build_dep(name: str, prefs: dict[str, str], verbose: bool) -> str:
licenses = [licenses]
license_text = ""
for license_file in licenses:
- with open(os.path.join(sources_dir, dir, license_file)) as f:
+ with open(os.path.join(sources_dir, directory, license_file)) as f:
license_text += f.read()
if "license_pattern" in dep:
match = re.search(dep["license_pattern"], license_text, re.DOTALL)
license_text = "\n".join(match.groups())
assert len(license_text) > 50
- with open(os.path.join(license_dir, f"{dir}.txt"), "w") as f:
- print(f"Writing license {dir}.txt")
+ with open(os.path.join(license_dir, f"{directory}.txt"), "w") as f:
+ print(f"Writing license {directory}.txt")
f.write(license_text)
for patch_file, patch_list in dep.get("patch", {}).items():
- patch_file = os.path.join(sources_dir, dir, patch_file.format(**prefs))
+ patch_file = os.path.join(sources_dir, directory, patch_file.format(**prefs))
with open(patch_file) as f:
text = f.read()
for patch_from, patch_to in patch_list.items():
@@ -602,13 +602,13 @@ def build_dep(name: str, prefs: dict[str, str], verbose: bool) -> str:
print(f"Patching {patch_file}")
f.write(text)
- banner = f"Building {name} ({dir})"
+ banner = f"Building {name} ({directory})"
lines = [
r'call "{build_dir}\build_env.cmd"',
"@echo " + ("=" * 70),
f"@echo ==== {banner:<60} ====",
"@echo " + ("=" * 70),
- cmd_cd(os.path.join(sources_dir, dir)),
+ cmd_cd(os.path.join(sources_dir, directory)),
*dep.get("build", []),
*get_footer(dep),
]
From e2c267f0484d81f10b636ffeb810676db31448b8 Mon Sep 17 00:00:00 2001
From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Date: Sun, 3 Mar 2024 17:11:59 +0200
Subject: [PATCH 6/9] Explicitly import urllib.error to avoid IDE warning
---
winbuild/build_prepare.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py
index 657e2f6ec..b9df8be63 100644
--- a/winbuild/build_prepare.py
+++ b/winbuild/build_prepare.py
@@ -463,6 +463,7 @@ def find_msvs(architecture: str) -> dict[str, str] | None:
def download_dep(url: str, file: str) -> None:
+ import urllib.error
import urllib.request
ex = None
From 71018badc0d88cb972c04f8eec4af274820c438a Mon Sep 17 00:00:00 2001
From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Date: Mon, 4 Mar 2024 23:35:10 -0700
Subject: [PATCH 7/9] Remove unused LIBXCB constant
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
---
winbuild/build_prepare.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py
index b9df8be63..0abf624b7 100644
--- a/winbuild/build_prepare.py
+++ b/winbuild/build_prepare.py
@@ -118,7 +118,6 @@ V = {
"LCMS2": "2.16",
"LIBPNG": "1.6.39",
"LIBWEBP": "1.3.2",
- "LIBXCB": "1.16",
"OPENJPEG": "2.5.2",
"TIFF": "4.6.0",
"XZ": "5.4.5",
From 35b803091bb84ed920f26b9d51c2b97f89363400 Mon Sep 17 00:00:00 2001
From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Date: Thu, 7 Mar 2024 13:39:27 +0200
Subject: [PATCH 8/9] Simplify rf to f-string
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
---
winbuild/build_prepare.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py
index 0abf624b7..b87b828bf 100644
--- a/winbuild/build_prepare.py
+++ b/winbuild/build_prepare.py
@@ -255,7 +255,7 @@ DEPS = {
),
],
"headers": [r"png*.h"],
- "libs": [rf"libpng{V['LIBPNG_XY']}.lib"],
+ "libs": [f"libpng{V['LIBPNG_XY']}.lib"],
},
"brotli": {
"url": f"https://github.com/google/brotli/archive/refs/tags/v{V['BROTLI']}.tar.gz",
From 984893576f9038cbaa2932c3ef493b870438137c Mon Sep 17 00:00:00 2001
From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Date: Fri, 8 Mar 2024 15:12:47 -0700
Subject: [PATCH 9/9] Remove unused pillow_dir
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
---
winbuild/build_prepare.py | 2 --
1 file changed, 2 deletions(-)
diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py
index b87b828bf..99c7228fa 100644
--- a/winbuild/build_prepare.py
+++ b/winbuild/build_prepare.py
@@ -639,7 +639,6 @@ def build_dep_all(disabled: list[str], prefs: dict[str, str], verbose: bool) ->
def main() -> None:
winbuild_dir = os.path.dirname(os.path.realpath(__file__))
- pillow_dir = os.path.realpath(os.path.join(winbuild_dir, ".."))
parser = argparse.ArgumentParser(
prog="winbuild\\build_prepare.py",
@@ -745,7 +744,6 @@ def main() -> None:
"architecture": args.architecture,
**arch_prefs,
# Pillow paths
- "pillow_dir": pillow_dir,
"winbuild_dir": winbuild_dir,
# Build paths
"bin_dir": bin_dir,