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

Add btyacc/3.0 #8947

Merged
merged 7 commits into from
Mar 10, 2022
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
8 changes: 8 additions & 0 deletions recipes/btyacc/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.2)

project(btyacc_wrapper C)

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

add_subdirectory(source_subfolder)
4 changes: 4 additions & 0 deletions recipes/btyacc/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"3.0":
sha256: "ce89b9121895aa29e9fd609f23eb8e0727912745a4d41aa7ad42984ef83f05c7"
url: https://github.com/ChrisDodd/btyacc/archive/0256b69f36f01877f1f4e76f80a5f561beabcfef.zip
80 changes: 80 additions & 0 deletions recipes/btyacc/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import functools
import os
import textwrap

from conans import CMake, ConanFile, tools

required_conan_version = ">=1.43.0"


class BtyaccConan(ConanFile):
name = "btyacc"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/ChrisDodd/btyacc"
description = "Backtracking yacc"
topics = "yacc", "parser"
license = "Unlicense"
settings = "os", "arch", "compiler", "build_type"
options = {
"fPIC": [True, False],
}
default_options = {
"fPIC": True,
}
generators = "cmake"
exports_sources = "CMakeLists.txt"
no_copy_source = True

@property
def _source_subfolder(self):
return "source_subfolder"

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

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

def source(self):
root = self._source_subfolder
get_args = self.conan_data["sources"][self.version]
tools.get(**get_args, destination=root, strip_root=True)
SSE4 marked this conversation as resolved.
Show resolved Hide resolved

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.configure()
return cmake

def build(self):
self._configure_cmake().build()

@property
def _variables(self):
return os.path.join("bin", "conan-official-btyacc-variables.cmake")

def package(self):
self.copy("README", "licenses", self._source_subfolder)
self.copy("README.BYACC", "licenses", self._source_subfolder)
self._configure_cmake().install()
tools.rmdir(os.path.join(self.package_folder, "share"))
variables = os.path.join(self.package_folder, self._variables)
content = textwrap.dedent("""\
set(BTYACC_EXECUTABLE "${CMAKE_CURRENT_LIST_DIR}/btyacc")
if(NOT EXISTS "${BTYACC_EXECUTABLE}")
set(BTYACC_EXECUTABLE "${BTYACC_EXECUTABLE}.exe")
endif()
""")
tools.save(variables, content)

def package_info(self):
bindir = os.path.join(self.package_folder, "bin")
self.output.info(f"Appending PATH environment variable: {bindir}")
self.env_info.PATH.append(bindir)
self.cpp_info.build_modules["cmake"] = [self._variables]
self.cpp_info.build_modules["cmake_find_package"] = [self._variables]
self.cpp_info.build_modules["cmake_find_package_multi"] = \
[self._variables]
self.cpp_info.builddirs = ["bin"]
31 changes: 31 additions & 0 deletions recipes/btyacc/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 3.1)

project(test_package C)

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

find_package(btyacc REQUIRED CONFIG)
if(NOT DEFINED BTYACC_EXECUTABLE)
message(FATAL_ERROR "BTYACC_EXECUTABLE is not defined")
endif()

set(bin "${PROJECT_BINARY_DIR}")
add_custom_command(
OUTPUT main.c
COMMAND "${BTYACC_EXECUTABLE}" -b y "${PROJECT_SOURCE_DIR}/test.y"
friendlyanon marked this conversation as resolved.
Show resolved Hide resolved
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${bin}/y.tab.c" "${bin}/main.c"
COMMAND "${CMAKE_COMMAND}" -E remove "${bin}/y.tab.c"
MAIN_DEPENDENCY test.y
WORKING_DIRECTORY "${bin}"
COMMENT "Generating main.c"
VERBATIM
)

add_executable(test_package "${bin}/main.c")

enable_testing()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we don't use ctest because it hides the output and also because we don't use assert statement on test package code. But I'm okay as it doesn't affect the test result.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I used CTest here was because I don't know whether run spawns a shell, where I can pipe things, or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice trick!

add_test(
NAME main
COMMAND "${CMAKE_COMMAND}" -E echo "(())()(())" | test_package
)
23 changes: 23 additions & 0 deletions recipes/btyacc/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import functools
import os

from conans import ConanFile, CMake, tools


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.configure()
return cmake

def build(self):
if not tools.cross_building(self):
self._configure_cmake().build()

def test(self):
if not tools.cross_building(self):
self._configure_cmake().test()
43 changes: 43 additions & 0 deletions recipes/btyacc/all/test_package/test.y
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
%{
/* first section */
%}
/*
* [test] btyacc
* [test] cc
* [test] input (())()(())
* [test] input-fail (())(*)(())
* [test] btyacc -DABC
* [test] cc
* [test] input (())(*)(())
*/
%%
%{
/* second section */
%}
S : /* empty */ { printf("S -> epsilon\n"); }
| '(' S ')' S { printf("S -> ( S ) S\n"); }
%ifdef ABC
/* see how preprocessor can be used */
| '*' { printf("S -> *\n"); }
%endif
;
%%
#include <stdio.h>

int main() {
int rv;
printf("yyparse() = %d\n", (rv=yyparse()));
return rv;
}

yylex() {
int ch;

do { ch = getchar(); } while (ch == ' ' || ch == '\n' || ch == '\t');
if (ch == EOF) return 0;
return ch;
}

void yyerror(const char *s, ...) {
printf("%s\n",s);
}
3 changes: 3 additions & 0 deletions recipes/btyacc/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"3.0":
folder: all