Skip to content

Commit

Permalink
sassc: migrate to Conan v2
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Nov 14, 2023
1 parent 5337371 commit de4ddfd
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 61 deletions.
3 changes: 0 additions & 3 deletions recipes/sassc/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
130 changes: 79 additions & 51 deletions recipes/sassc/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,98 +1,126 @@
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'<Import Project="{props_path}" />'
for vcxproj_file in vcxproj_files:
for exiting_toolset in ["v120", "v140", "v141", "v142", "v143"]:
replace_in_file(self, vcxproj_file,
f"<PlatformToolset>{exiting_toolset}</PlatformToolset>",
f"<PlatformToolset>{platform_toolset}</PlatformToolset>")
if props_path:
replace_in_file(self, vcxproj_file,
'<Import Project="$(VCTargetsPath)\\Microsoft.Cpp.targets" />',
f'{import_conan_generators}<Import Project="$(VCTargetsPath)\\Microsoft.Cpp.targets" />')

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 = []
self.cpp_info.libdirs = []
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)
14 changes: 9 additions & 5 deletions recipes/sassc/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
9 changes: 9 additions & 0 deletions recipes/sassc/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 0 additions & 2 deletions recipes/sassc/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
versions:
"3.6.2":
folder: all
"3.6.1":
folder: all

0 comments on commit de4ddfd

Please sign in to comment.