From de4ddfd4649b11944d61b84ce4ab2f27113f535a Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Tue, 18 Jul 2023 22:00:53 +0300 Subject: [PATCH 1/2] sassc: migrate to Conan v2 --- recipes/sassc/all/conandata.yml | 3 - recipes/sassc/all/conanfile.py | 130 +++++++++++------- recipes/sassc/all/test_package/conanfile.py | 14 +- .../sassc/all/test_v1_package/conanfile.py | 9 ++ recipes/sassc/config.yml | 2 - 5 files changed, 97 insertions(+), 61 deletions(-) create mode 100644 recipes/sassc/all/test_v1_package/conanfile.py diff --git a/recipes/sassc/all/conandata.yml b/recipes/sassc/all/conandata.yml index 5119b677bea74..23ccaaba2c88a 100644 --- a/recipes/sassc/all/conandata.yml +++ b/recipes/sassc/all/conandata.yml @@ -2,6 +2,3 @@ sources: "3.6.2": url: "https://github.com/sass/sassc/archive/3.6.2.tar.gz" sha256: "608dc9002b45a91d11ed59e352469ecc05e4f58fc1259fc9a9f5b8f0f8348a03" - "3.6.1": - sha256: 8cee391c49a102b4464f86fc40c4ceac3a2ada52a89c4c933d8348e3e4542a60 - url: https://github.com/sass/sassc/archive/3.6.1.tar.gz diff --git a/recipes/sassc/all/conanfile.py b/recipes/sassc/all/conanfile.py index b9452a96ffc40..15d848f49f6d9 100644 --- a/recipes/sassc/all/conanfile.py +++ b/recipes/sassc/all/conanfile.py @@ -1,91 +1,119 @@ +import os + from conan import ConanFile from conan.errors import ConanInvalidConfiguration -from conan.tools.files import get, replace_in_file, chdir, save -from conan.tools.microsoft import is_msvc -from conans import AutoToolsBuildEnvironment, tools, MSBuild -import os +from conan.tools.env import VirtualBuildEnv +from conan.tools.files import chdir, copy, get, replace_in_file, save +from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps +from conan.tools.layout import basic_layout +from conan.tools.microsoft import MSBuild, is_msvc, MSBuildToolchain, MSBuildDeps -required_conan_version = ">=1.47.0" +required_conan_version = ">=1.53.0" class SasscConan(ConanFile): name = "sassc" + description = "libsass command line driver" license = "MIT" - homepage = "https://sass-lang.com/libsass" url = "https://github.com/conan-io/conan-center-index" - description = "libsass command line driver" - topics = ("Sass", "sassc", "compiler") - settings = "os", "compiler", "build_type", "arch" - generators = "visual_studio" + homepage = "https://sass-lang.com/libsass" + topics = ("Sass", "compiler") - _autotools = None - - @property - def _source_subfolder(self): - return "source_subfolder" + package_type = "application" + settings = "os", "arch", "compiler", "build_type" def config_options(self): - del self.settings.compiler.libcxx - del self.settings.compiler.cppstd + self.settings.rm_safe("compiler.libcxx") + self.settings.rm_safe("compiler.cppstd") + + def layout(self): + basic_layout(self, src_folder="src") + + def requirements(self): + self.requires("libsass/3.6.5") def package_id(self): del self.info.settings.compiler def validate(self): if not is_msvc(self) and self.info.settings.os not in ["Linux", "FreeBSD", "Macos"]: - raise ConanInvalidConfiguration("sassc supports only Linux, FreeBSD, Macos and Windows Visual Studio at this time, contributions are welcomed") - - def requirements(self): - self.requires("libsass/3.6.5") + raise ConanInvalidConfiguration( + "sassc supports only Linux, FreeBSD, Macos and Windows Visual Studio at this time," + " contributions are welcomed" + ) def build_requirements(self): if not is_msvc(self): self.tool_requires("libtool/2.4.7") def source(self): - get(self, **self.conan_data["sources"][self.version], - destination=self._source_subfolder, strip_root=True) + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + @property + def _msbuild_configuration(self): + return "Debug" if self.settings.build_type == "Debug" else "Release" + + def generate(self): + if is_msvc(self): + tc = MSBuildToolchain(self) + tc.configuration = self._msbuild_configuration + tc.generate() + deps = MSBuildDeps(self) + deps.configuration = self._msbuild_configuration + deps.generate() + else: + env = VirtualBuildEnv(self) + env.generate() + tc = AutotoolsToolchain(self) + tc.configure_args += ["--disable-tests"] + tc.generate() + deps = AutotoolsDeps(self) + deps.generate() def _patch_sources(self): - replace_in_file(self, - os.path.join(self.build_folder, self._source_subfolder, "win", "sassc.vcxproj"), - "$(LIBSASS_DIR)\\win\\libsass.targets", - os.path.join(self.build_folder, "conanbuildinfo.props")) - - def _configure_autotools(self): - if self._autotools: - return self._autotools - self._autotools = AutoToolsBuildEnvironment(self) - self._autotools.configure(args=["--disable-tests"]) - return self._autotools - - def _build_msbuild(self): - msbuild = MSBuild(self) - platforms = { - "x86": "Win32", - "x86_64": "Win64" - } - msbuild.build("win/sassc.sln", platforms=platforms) + 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}') def build(self): self._patch_sources() - with chdir(self, self._source_subfolder): + with chdir(self, self.source_folder): if is_msvc(self): - self._build_msbuild() + msbuild = MSBuild(self) + msbuild.build(sln=os.path.join("win", "sassc.sln")) else: - self.run("{} -fiv".format(tools.get_env("AUTORECONF")), run_environment=True) save(self, path="VERSION", content=f"{self.version}") - autotools = self._configure_autotools() + autotools = Autotools(self) + autotools.autoreconf() + autotools.configure() autotools.make() def package(self): - with chdir(self, self._source_subfolder): + with chdir(self, self.source_folder): if is_msvc(self): - self.copy("*.exe", dst="bin", src=os.path.join(self._source_subfolder, "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 = self._configure_autotools() + autotools = Autotools(self) autotools.install() - self.copy("LICENSE", src=self._source_subfolder, dst="licenses") + copy(self, "LICENSE", + src=self.source_folder, + dst=os.path.join(self.package_folder, "licenses")) def package_info(self): self.cpp_info.frameworkdirs = [] @@ -93,6 +121,6 @@ def package_info(self): self.cpp_info.resdirs = [] self.cpp_info.includedirs = [] - bin_folder = os.path.join(self.package_folder, "bin") # TODO: Legacy, to be removed on Conan 2.0 + bin_folder = os.path.join(self.package_folder, "bin") self.env_info.PATH.append(bin_folder) diff --git a/recipes/sassc/all/test_package/conanfile.py b/recipes/sassc/all/test_package/conanfile.py index 70d62ab9bfc61..cad02af78d9e1 100644 --- a/recipes/sassc/all/test_package/conanfile.py +++ b/recipes/sassc/all/test_package/conanfile.py @@ -1,9 +1,13 @@ -from conans import ConanFile, tools +from conan import ConanFile -class LibsassTestConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "VirtualBuildEnv" + test_type = "explicit" + + def build_requirements(self): + self.tool_requires(self.tested_reference_str) def test(self): - if not tools.cross_building(self): - self.run("sassc --version", run_environment=True) + self.run("sassc --version") diff --git a/recipes/sassc/all/test_v1_package/conanfile.py b/recipes/sassc/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..70d62ab9bfc61 --- /dev/null +++ b/recipes/sassc/all/test_v1_package/conanfile.py @@ -0,0 +1,9 @@ +from conans import ConanFile, tools + + +class LibsassTestConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + + def test(self): + if not tools.cross_building(self): + self.run("sassc --version", run_environment=True) diff --git a/recipes/sassc/config.yml b/recipes/sassc/config.yml index bfe5b909d834d..4c410b4e03fe2 100644 --- a/recipes/sassc/config.yml +++ b/recipes/sassc/config.yml @@ -1,5 +1,3 @@ versions: "3.6.2": folder: all - "3.6.1": - folder: all From dbd8a0cb897fde53ef3a4c6f4e0d0910bab94367 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Fri, 4 Aug 2023 09:46:23 +0300 Subject: [PATCH 2/2] 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()