From dbd8a0cb897fde53ef3a4c6f4e0d0910bab94367 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Fri, 4 Aug 2023 09:46:23 +0300 Subject: [PATCH] sassc: fix MSVC build, add VS 2022 support --- recipes/sassc/all/conanfile.py | 47 ++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/recipes/sassc/all/conanfile.py b/recipes/sassc/all/conanfile.py index 15d848f49f6d9..4aed7995e790a 100644 --- a/recipes/sassc/all/conanfile.py +++ b/recipes/sassc/all/conanfile.py @@ -53,10 +53,17 @@ def source(self): def _msbuild_configuration(self): return "Debug" if self.settings.build_type == "Debug" else "Release" + @property + def _msbuild_platform(self): + return "Win32" if self.settings.arch == "x86" else "Win64" + def generate(self): if is_msvc(self): tc = MSBuildToolchain(self) tc.configuration = self._msbuild_configuration + tc.platform = self._msbuild_platform + # FIXME: setting this property does not work, applied as a patch instead + # tc.properties["LIBSASS_DIR"] = self.dependencies["libsass"].package_folder tc.generate() deps = MSBuildDeps(self) deps.configuration = self._msbuild_configuration @@ -71,28 +78,40 @@ def generate(self): deps.generate() def _patch_sources(self): - vcxproj_files = [os.path.join(self.build_folder, self.source_folder, "win", "sassc.vcxproj")] platform_toolset = MSBuildToolchain(self).toolset import_conan_generators = "" for props_file in ["conantoolchain.props", "conandeps.props"]: props_path = os.path.join(self.generators_folder, props_file) if os.path.exists(props_path): import_conan_generators += f'' - for vcxproj_file in vcxproj_files: - for exiting_toolset in ["v120", "v140", "v141", "v142", "v143"]: - replace_in_file(self, vcxproj_file, - f"{exiting_toolset}", - f"{platform_toolset}") - if props_path: - replace_in_file(self, vcxproj_file, - '', - f'{import_conan_generators}') + vcxproj_file = os.path.join(self.source_folder, "win", "sassc.vcxproj") + for existing_toolset in ["v120", "v140", "v141", "v142", "v143"]: + replace_in_file(self, vcxproj_file, + f"{existing_toolset}", + f"{platform_toolset}", strict=False) + # Inject VS 2022 support + replace_in_file(self, vcxproj_file, + '\n' + f' {platform_toolset}\n' + '\n' + '..\\..', + f"{self.dependencies['libsass'].package_folder}") + replace_in_file(self, vcxproj_file, r'', "") + if props_path: + replace_in_file(self, vcxproj_file, + r'', + rf'{import_conan_generators}') def build(self): self._patch_sources() with chdir(self, self.source_folder): if is_msvc(self): msbuild = MSBuild(self) + msbuild.build_type = self._msbuild_configuration + msbuild.platform = self._msbuild_platform msbuild.build(sln=os.path.join("win", "sassc.sln")) else: save(self, path="VERSION", content=f"{self.version}") @@ -104,10 +123,10 @@ def build(self): def package(self): with chdir(self, self.source_folder): if is_msvc(self): - copy(self,"*.exe", - dst=os.path.join(self.package_folder, "bin"), - src=os.path.join(self.source_folder, "bin"), - keep_path=False) + copy(self, "*.exe", + dst=os.path.join(self.package_folder, "bin"), + src=os.path.join(self.source_folder, "bin"), + keep_path=False) else: autotools = Autotools(self) autotools.install()