-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
97 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |