Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xz_utils: patch in build() instead of source() + remove msys2 dependency if Visual Studio + split build and install #3228

Merged
merged 5 commits into from
Oct 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 48 additions & 54 deletions recipes/xz_utils/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import glob
import os
from conans import ConanFile, tools, AutoToolsBuildEnvironment, MSBuild
from conans.tools import Version
Expand All @@ -16,19 +17,12 @@ class XZUtils(ConanFile):
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}

_autotools = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _use_winbash(self):
return tools.os_info.is_windows

def build_requirements(self):
if self._use_winbash and "CONAN_BASH_PATH" not in os.environ and \
tools.os_info.detect_windows_subsystem() != "msys2":
self.build_requires("msys2/20200517")

def _effective_msbuild_type(self):
# treat "RelWithDebInfo" and "MinSizeRel" as "Release"
return "Debug" if self.settings.build_type == "Debug" else "Release"
Expand All @@ -38,42 +32,42 @@ def config_options(self):
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.cppstd
del self.settings.compiler.libcxx

def _apply_patches(self):
if tools.Version(self.version) == "5.2.4":
# Relax Windows SDK restriction
tools.replace_in_file(os.path.join(self._source_subfolder, "windows", "vs2017", "liblzma.vcxproj"),
"<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>",
"<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>")

tools.replace_in_file(os.path.join(self._source_subfolder, "windows", "vs2017", "liblzma_dll.vcxproj"),
"<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>",
"<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>")
def build_requirements(self):
if tools.os_info.is_windows and self.settings.compiler != "Visual Studio" and \
not tools.get_env("CONAN_BASH_PATH") and tools.os_info.detect_windows_subsystem() != "msys2":
self.build_requires("msys2/20200517")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
os.rename("xz-" + self.version, self._source_subfolder)
self._apply_patches()

def _build_msvc(self):
# windows\INSTALL-MSVC.txt

if self.settings.compiler.version == 15 and tools.Version(self.version) == "5.2.4":
def _apply_patches(self):
if tools.Version(self.version) == "5.2.4" and self.settings.compiler == "Visual Studio":
# Relax Windows SDK restriction
# Workaround is required only for 5.2.4 because since 5.2.5 WindowsTargetPlatformVersion is dropped from vcproj file
#
# emulate VS2019+ meaning of WindowsTargetPlatformVersion == "10.0"
# undocumented method, but officially recommended workaround by microsoft at at
# https://developercommunity.visualstudio.com/content/problem/140294/windowstargetplatformversion-makes-it-impossible-t.html
windows_target_platform_version_old = "<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>"
if self.settings.compiler.version == 15:
windows_target_platform_version_new = "<WindowsTargetPlatformVersion>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))</WindowsTargetPlatformVersion>"
else:
windows_target_platform_version_new = "<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>"
tools.replace_in_file(os.path.join(self._source_subfolder, "windows", "vs2017", "liblzma.vcxproj"),
"<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>",
"<WindowsTargetPlatformVersion>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))</WindowsTargetPlatformVersion>")

windows_target_platform_version_old,
windows_target_platform_version_new)
tools.replace_in_file(os.path.join(self._source_subfolder, "windows", "vs2017", "liblzma_dll.vcxproj"),
"<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>",
"<WindowsTargetPlatformVersion>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))</WindowsTargetPlatformVersion>")
windows_target_platform_version_old,
windows_target_platform_version_new)

def _build_msvc(self):
# windows\INSTALL-MSVC.txt
msvc_version = "vs2017" if Version(self.settings.compiler.version) >= "15" else "vs2013"
with tools.chdir(os.path.join(self._source_subfolder, "windows", msvc_version)):
target = "liblzma_dll" if self.options.shared else "liblzma"
Expand All @@ -86,28 +80,29 @@ def _build_msvc(self):
use_env=False,
upgrade_project=False)

def _build_configure(self):
with tools.chdir(self._source_subfolder):
args = []
env_build = AutoToolsBuildEnvironment(self, win_bash=self._use_winbash)
args = ["--disable-doc"]
if self.settings.os != "Windows" and self.options.fPIC:
args.append("--with-pic")
if self.options.shared:
args.extend(["--disable-static", "--enable-shared"])
else:
args.extend(["--enable-static", "--disable-shared"])
if self.settings.build_type == "Debug":
args.append("--enable-debug")
env_build.configure(args=args, build=False)
env_build.make()
env_build.install()
def _configure_autotools(self):
if self._autotools:
return self._autotools
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
args = ["--disable-doc"]
if self.settings.os != "Windows" and self.options.get_safe("fPIC", True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since fPIC is deleted on windows is get_safe no enough? This flag enables so we need to limit that there's no else my mistake

args.append("--with-pic")
if self.options.shared:
args.extend(["--disable-static", "--enable-shared"])
else:
args.extend(["--enable-static", "--disable-shared"])
if self.settings.build_type == "Debug":
args.append("--enable-debug")
self._autotools.configure(configure_dir=self._source_subfolder, args=args, build=False)
return self._autotools

def build(self):
self._apply_patches()
if self.settings.compiler == "Visual Studio":
self._build_msvc()
else:
self._build_configure()
autotools = self._configure_autotools()
autotools.make()

def package(self):
self.copy(pattern="COPYING", dst="licenses", src=self._source_subfolder)
Expand All @@ -124,14 +119,13 @@ def package(self):
self.copy(pattern="*.dll", dst="bin", src=bin_dir, keep_path=False)
os.rename(os.path.join(self.package_folder, "lib", "liblzma.lib"),
os.path.join(self.package_folder, "lib", "lzma.lib"))

# Remove/rename forbidden files/folders in central repository
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "share"))
try:
os.remove(os.path.join(self.package_folder, "lib", "liblzma.la"))
except:
pass
else:
autotools = self._configure_autotools()
autotools.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "share"))
for la_file in glob.glob(os.path.join(self.package_folder, "lib", "*.la")):
os.remove(la_file)

def package_info(self):
if not self.options.shared:
Expand Down