Skip to content

Commit

Permalink
Fix limited shared option regex
Browse files Browse the repository at this point in the history
- Now is possible to validate shared recipe when using multiple lines
- Added unit tests to validate os name and if is CI running

Signed-off-by: Uilian Ries <[email protected]>
  • Loading branch information
uilianries committed Jan 22, 2018
1 parent 29dda80 commit 289acf1
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bincrafters/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.10.0'
__version__ = '0.10.1'
11 changes: 7 additions & 4 deletions bincrafters/build_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import platform


def get_value_from_recipe(search_string):
with open("conanfile.py", "r") as conanfile:
def get_value_from_recipe(search_string, recipe="conanfile.py"):
with open(recipe, "r") as conanfile:
contents = conanfile.read()
result = re.search(search_string, contents)
return result
Expand All @@ -23,11 +23,14 @@ def get_version_from_recipe():


def is_shared():
return "shared" in get_value_from_recipe(r'''options\s*=\s*(.*)''').groups()[0]
match = get_value_from_recipe(r'''options.*=([\s\S]*?)(?=}|$)''')
if match is None:
return False
return "shared" in match.groups()[0]


def is_ci_running():
return os.getenv("APPVEYOR_REPO_NAME", "") or os.getenv("TRAVIS_REPO_SLUG", "")
return (os.getenv("APPVEYOR_REPO_NAME", None) or os.getenv("TRAVIS_REPO_SLUG", None)) is not None


def get_repo_name_from_ci():
Expand Down
2 changes: 1 addition & 1 deletion bincrafters/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
conan_package_tools>=0.8.4
conan_package_tools>=0.9.0
9 changes: 9 additions & 0 deletions tests/test_package_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from bincrafters import build_template_header_only
from bincrafters import build_template_installer
import os
import platform


os.environ["CONAN_GCC_VERSIONS"] = "7"
Expand Down Expand Up @@ -67,3 +68,11 @@ def test_build_boost_header_only():
assert 0 == len(options)
assert 1 == len(builder.items)
assert "" == _get_upload_when_stable()

def test_get_os():
expected_os = platform.system()
assert expected_os == build_shared.get_os()

def test_ci_is_running():
expected = True if os.getenv("CI", None) is not None else False
assert expected == build_shared.is_ci_running()
156 changes: 156 additions & 0 deletions tests/test_shared_option.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import tempfile
import contextlib
import os
from bincrafters import build_shared


recipe_with_shared_1 = """
class FoobarConan(ConanFile):
name = "foobar"
version = "0.1.0"
url = "https://github.com/bincrafters/foobar"
description = "Just another foobar "
license = "MIT"
exports = ["LICENSE.md"]
exports_sources = ["CMakeLists.txt"]
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
options = {"with_zlib": [True, False],
"build_tests": [True, False],
"build_binaries": [True, False],
"static_rt": [True, False],
"shared": [True, False], # Just another comment
}
default_options = "with_zlib=False", "build_tests=False", "static_rt=True", "build_binaries=True", "shared=False"
source_subfolder = "source_subfolder"
build_subfolder = "build_subfolder"
def requirements(self):
if self.options.with_zlib:
self.requires("zlib/1.2.11@conan/stable")
def source(self):
repo_url = "https://github.com/bincrafters/foobar.git"
self.run("git clone -b v{0} {1} {2}".format(self.version, repo_url, self.source_subfolder))
def build(self):
cmake = CMake(self)
cmake.configure(build_folder=self.build_subfolder)
cmake.build()
cmake.install()
def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
"""

recipe_with_shared_2 = """
class FoobarConan(ConanFile):
name="foobar"
version="0.1.0"
url="https://github.com/bincrafters/foobar"
description="Just another foobar "
license="MIT"
exports="LICENSE.md"
exports_sources="CMakeLists.txt"
generators="cmake"
settings="os", "arch", "compiler", "build_type"
options={"shared": [True, False]}
default_options="shared=False"
def source(self):
repo_url = "https://github.com/bincrafters/foobar.git"
self.run("git clone -b v{0} {1} {2}".format(self.version, repo_url, self.source_subfolder))
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
cmake.install()
def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
"""

recipe_with_no_shared_1 = """
name = "foobar"
version = "0.1.0"
no_copy_source = True
def source(self):
self.run("git clone ...")
tools.download("url", "file.zip")
tools.unzip("file.zip" )
def package(self):
self.copy("*.h", "include")
def package_id(self):
self.info.header_only()
"""

recipe_with_no_shared_2 = """
class FoobarConan(ConanFile):
name = "foobar"
version = "0.1.0"
url = "https://github.com/bincrafters/foobar"
description = "Just another foobar "
license = "MIT"
exports = ["LICENSE.md"]
exports_sources = ["CMakeLists.txt"]
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
options = {"with_zlib": [True, False],
"build_tests": [True, False],
"build_binaries": [True, False],
"static_rt": [True, False]
}
default_options = "with_zlib=False", "build_tests=False", "static_rt=True", "build_binaries=True"
source_subfolder = "source_subfolder"
build_subfolder = "build_subfolder"
def requirements(self):
if self.options.with_zlib:
self.requires("zlib/1.2.11@conan/stable")
def source(self):
repo_url = "https://github.com/bincrafters/foobar.git"
self.run("git clone -b v{0} {1} {2}".format(self.version, repo_url, self.source_subfolder))
def build(self):
cmake = CMake(self)
cmake.configure(build_folder=self.build_subfolder)
cmake.build()
cmake.install()
def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
"""

@contextlib.contextmanager
def chdir(path):
prev_cwd = os.getcwd()
os.chdir(path)
try:
yield
finally:
os.chdir(prev_cwd)

def create_and_validate(recipe_buffer, expected_value):
tempdir = tempfile.mkdtemp()
with chdir(tempdir):
with open("conanfile.py", "w") as fd:
fd.write(recipe_buffer)
fd.flush()
assert expected_value == build_shared.is_shared()

def test_recipe_with_shared_option():
create_and_validate(recipe_with_shared_1, True)
create_and_validate(recipe_with_shared_2, True)

def test_recipe_with_no_shared_option():
create_and_validate(recipe_with_no_shared_1, False)
create_and_validate(recipe_with_no_shared_2, False)

0 comments on commit 289acf1

Please sign in to comment.