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

re2c: migrate to Conan v2 #18635

Merged
merged 10 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
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
18 changes: 3 additions & 15 deletions recipes/re2c/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"3.1":
url: "https://github.com/skvadrik/re2c/releases/download/3.1/re2c-3.1.tar.xz"
sha256: "0ac299ad359e3f512b06a99397d025cfff81d3be34464ded0656f8a96676c029"
"3.0":
url: "https://github.com/skvadrik/re2c/releases/download/3.0/re2c-3.0.tar.xz"
sha256: "b3babbbb1461e13fe22c630a40c43885efcfbbbb585830c6f4c0d791cf82ba0b"
Expand All @@ -15,20 +18,5 @@
url: "https://github.com/skvadrik/re2c/releases/download/1.3/re2c-1.3.tar.xz"
sha256: "f37f25ff760e90088e7d03d1232002c2c2672646d5844fdf8e0d51a5cd75a503"
patches:
"3.0":
- patch_file: "patches/0001-add-msvc_cl-sh.patch"
base_path: ""
"2.2":
- patch_file: "patches/0001-add-msvc_cl-sh.patch"
base_path: ""
"2.1.1":
- patch_file: "patches/0001-add-msvc_cl-sh.patch"
base_path: ""
"2.0.3":
- patch_file: "patches/0001-add-msvc_cl-sh.patch"
base_path: ""
- patch_file: "patches/2.0.3-0001-add-missing-include.patch"

Check warning on line 22 in recipes/re2c/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/2.0.3-00 ... ^ (line: 22)
base_path: "source_subfolder"
"1.3":
- patch_file: "patches/0001-add-msvc_cl-sh.patch"
base_path: ""
138 changes: 75 additions & 63 deletions recipes/re2c/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,95 +1,107 @@
from conans import AutoToolsBuildEnvironment, ConanFile, tools
from contextlib import contextmanager
import os

required_conan_version = ">=1.33.0"
from conan import ConanFile
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import apply_conandata_patches, chdir, copy, export_conandata_patches, get, rmdir, replace_in_file
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import is_msvc

required_conan_version = ">=1.53.0"


class Re2CConan(ConanFile):
name = "re2c"
description = "re2c is a free and open-source lexer generator for C, C++ and Go."
topics = ("re2c", "lexer", "language", "tokenizer", "flex")
description = "re2c is a free and open-source lexer generator for C/C++, Go and Rust."
license = "LicenseRef-re2c"
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://re2c.org/"
license = "Unlicense"
settings = "os", "arch", "build_type", "compiler"

_autotools = None
topics = ("lexer", "language", "tokenizer", "flex")

@property
def _source_subfolder(self):
return "source_subfolder"
package_type = "application"
settings = "os", "arch", "compiler", "build_type"

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

def export_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
export_conandata_patches(self)

def configure(self):
del self.settings.compiler.cppstd
del self.settings.compiler.libcxx
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")

def layout(self):
basic_layout(self, src_folder="src")

def package_id(self):
del self.info.settings.compiler

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)

def build_requirements(self):
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
self.build_requires("msys2/cci.latest")

@contextmanager
def _build_context(self):
if self.settings.compiler == "Visual Studio":
with tools.vcvars(self):
env = {
"CC": "{} -nologo".format(tools.unix_path(os.path.join(self.build_folder, "msvc_cl.sh"))),
"CXX": "{} -nologo".format(tools.unix_path(os.path.join(self.build_folder, "msvc_cl.sh"))),
"LD": "{} -nologo".format(tools.unix_path(os.path.join(self.build_folder, "msvc_cl.sh"))),
"CXXLD": "{} -nologo".format(tools.unix_path(os.path.join(self.build_folder, "msvc_cl.sh"))),
"AR": "lib",
}
with tools.environment_append(env):
yield
else:
yield

def _configure_autotools(self):
if self._autotools:
return self._autotools
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
if self.settings.compiler == "Visual Studio":
self._autotools.flags.append("-FS")
self._autotools.cxx_flags.append("-EHsc")
self._autotools.configure(configure_dir=self._source_subfolder)
return self._autotools
if self._settings_build.os == "Windows":
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
self.tool_requires("msys2/cci.latest")
self.tool_requires("winflexbison/2.5.24")
if is_msvc(self):
self.tool_requires("cccl/1.3")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
VirtualBuildEnv(self).generate()
tc = AutotoolsToolchain(self)
tc.configure_args.append("--disable-benchmarks")
env = tc.environment()
if is_msvc(self):
tc.extra_cxxflags.append("-EHsc")
env.define("CC", "cccl -FS")
env.define("CXX", "cccl -FS")
env.define("LD", "cccl")
env.define("CXXLD", "cccl")
tc.generate(env)

def _patch_sources(self):
apply_conandata_patches(self)
# Don't copy benchmark files, which cause the build to fail on Windows
replace_in_file(self, os.path.join(self.source_folder, "configure"),
'"$ac_config_files Makefile ',
'"$ac_config_files Makefile" #',
strict=False)
replace_in_file(self, os.path.join(self.source_folder, "configure"),
'"$ac_config_links ',
'"$ac_config_links" #',
strict=False)

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
with self._build_context():
autotools = self._configure_autotools()
self._patch_sources()
with chdir(self, self.source_folder):
autotools = Autotools(self)
autotools.configure()
autotools.make(args=["V=1"])

def package(self):
self.copy("LICENSE", src=self._source_subfolder, dst="licenses", keep_path=False)
self.copy("NO_WARRANTY", src=self._source_subfolder, dst="licenses", keep_path=False)
with self._build_context():
autotools = self._configure_autotools()
copy(self, "LICENSE",
src=self.source_folder,
dst=os.path.join(self.package_folder, "licenses"),
keep_path=False)
copy(self, "NO_WARRANTY",
src=self.source_folder,
dst=os.path.join(self.package_folder, "licenses"),
keep_path=False)
with chdir(self, self.source_folder):
autotools = Autotools(self)
autotools.install()

tools.rmdir(os.path.join(self.package_folder, "share"))
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.frameworkdirs = []
self.cpp_info.libdirs = []
self.cpp_info.resdirs = []
self.cpp_info.includedirs = []

# TODO: to remove in conan v2
bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bin_path))
self.env_info.PATH.append(bin_path)
94 changes: 0 additions & 94 deletions recipes/re2c/all/patches/0001-add-msvc_cl-sh.patch

This file was deleted.

7 changes: 2 additions & 5 deletions recipes/re2c/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_custom_command(OUTPUT test_package.c
COMMAND re2c -W "${PROJECT_SOURCE_DIR}/syntax.re" -o test_package.c
COMMAND re2c -W "${CMAKE_CURRENT_LIST_DIR}/syntax.re" -o test_package.c
)

add_executable(${PROJECT_NAME} test_package.c)
23 changes: 16 additions & 7 deletions recipes/re2c/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def build_requirements(self):
self.tool_requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
if not tools.cross_building(self, skip_x64_x86=True):
if can_run(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self, skip_x64_x86=True):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
2 changes: 2 additions & 0 deletions recipes/re2c/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"3.1":
folder: "all"
"3.0":
folder: "all"
"2.2":
Expand Down