Skip to content

Commit 37cd16b

Browse files
committed
Simplify FreeType Windows build.
- Make FREETYPE_BUILD_CMD a raw string to avoid doubling all backslashes. - Line-wrap two overly long lines in FREETYPE_BUILD_CMD. - Move the `rd /S /Q %FREETYPE%\objs` to python (`shutil.rmtree`). - Move the `copy %FREETYPE\objs\...` to python (`shutil.copy2`). - Get rid of the Py27 part (`if errorlevel 1 ...`). - Run the FREETYPE_BUILD_CMD script with `src_path` as cwd, which avoids the need to define the %FREETYPE% environment variable.
1 parent 126113f commit 37cd16b

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

setupext.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,8 @@ def add_flags(self, ext):
10291029
ext.define_macros.append(('FREETYPE_BUILD_TYPE', 'system'))
10301030

10311031
def do_custom_build(self):
1032+
from pathlib import Path
1033+
10321034
# We're using a system freetype
10331035
if not options.get('local_freetype'):
10341036
return
@@ -1122,21 +1124,13 @@ def do_custom_build(self):
11221124
[cflags + 'make'], shell=True, cwd=src_path)
11231125
else:
11241126
# compilation on windows
1125-
FREETYPE_BUILD_CMD = """\
1126-
call "%ProgramFiles%\\Microsoft SDKs\\Windows\\v7.0\\Bin\\SetEnv.Cmd" /Release /{xXX} /xp
1127+
FREETYPE_BUILD_CMD = r"""
1128+
call "%ProgramFiles%\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.Cmd" ^
1129+
/Release /{xXX} /xp
11271130
call "{vcvarsall}" {xXX}
1128-
set MSBUILD=C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe
1129-
rd /S /Q %FREETYPE%\\objs
1130-
%MSBUILD% %FREETYPE%\\builds\\windows\\{vc20xx}\\freetype.sln /t:Clean;Build /p:Configuration="{config}";Platform={WinXX}
1131-
echo Build completed, moving result"
1132-
:: move to the "normal" path for the unix builds...
1133-
mkdir %FREETYPE%\\objs\\.libs
1134-
:: REMINDER: fix when changing the version
1135-
copy %FREETYPE%\\objs\\{vc20xx}\\{xXX}\\freetype261.lib %FREETYPE%\\objs\\.libs\\libfreetype.lib
1136-
if errorlevel 1 (
1137-
rem This is a py27 version, which has a different location for the lib file :-/
1138-
copy %FREETYPE%\\objs\\win32\\{vc20xx}\\freetype261.lib %FREETYPE%\\objs\\.libs\\libfreetype.lib
1139-
)
1131+
set MSBUILD=C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
1132+
%MSBUILD% "builds\windows\{vc20xx}\freetype.sln" ^
1133+
/t:Clean;Build /p:Configuration="{config}";Platform={WinXX}
11401134
"""
11411135
from setup_external_compile import fixproj, prepare_build_cmd, VS2010, X64, tar_extract
11421136
# Note: freetype has no build profile for 2014, so we don't bother...
@@ -1148,13 +1142,20 @@ def do_custom_build(self):
11481142
fixproj(os.path.join(src_path, 'builds', 'windows', vc, 'freetype.sln'), WinXX)
11491143
fixproj(os.path.join(src_path, 'builds', 'windows', vc, 'freetype.vcproj'), WinXX)
11501144

1151-
cmdfile = os.path.join("build", 'build_freetype.cmd')
1152-
with open(cmdfile, 'w') as cmd:
1145+
cmdfile = "build_freetype.cmd"
1146+
with open(os.path.join("build", cmdfile), 'w') as cmd:
11531147
cmd.write(prepare_build_cmd(FREETYPE_BUILD_CMD, vc20xx=vc, WinXX=WinXX,
11541148
config='Release' if VS2010 else 'LIB Release'))
11551149

1156-
os.environ['FREETYPE'] = src_path
1157-
subprocess.check_call([cmdfile], shell=True)
1150+
shutil.rmtree(str(Path(src_path, "objs")), ignore_errors=True)
1151+
subprocess.check_call([cmdfile], shell=True, cwd=src_path)
1152+
# Move to the corresponding Unix build path.
1153+
Path(src_path, "objs/.libs").mkdir()
1154+
# Be robust against change of FreeType version.
1155+
lib_path, = (Path(src_path, "objs", vc20xx, xXX)
1156+
.glob("freetype*.lib"))
1157+
shutil.copy2(str(lib_path),
1158+
str(Path(src_path, "objs/.libs/libfreetype.lib")))
11581159

11591160

11601161
class FT2Font(SetupPackage):

0 commit comments

Comments
 (0)