-
Notifications
You must be signed in to change notification settings - Fork 952
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Qbs: Added qbs test lib api and fixed handling spaces (#16382)
* Qbs: fix handling spaces Also add a simple static lib functional test as well as api to create libs. * implement shared libs in api/new * Properly test qbs lib package
- Loading branch information
Showing
5 changed files
with
125 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,103 @@ | ||
from conan.internal.api.new.cmake_lib import source_cpp, source_h, test_main | ||
|
||
|
||
conanfile_sources = ''' | ||
import os | ||
from conan import ConanFile | ||
from conan.tools.qbs import Qbs | ||
class {{package_name}}Recipe(ConanFile): | ||
name = "{{name}}" | ||
version = "{{version}}" | ||
exports_sources = "*.cpp", "*.h", "*.qbs" | ||
settings = "os", "compiler", "arch" | ||
options = {"shared": [True, False]} | ||
default_options = {"shared": False} | ||
def build(self): | ||
qbs = Qbs(self) | ||
qbs.profile = "" | ||
qbs_config = {"products.{{name}}.isShared": "true" if self.options.shared else "false"} | ||
qbs.add_configuration("default", qbs_config) | ||
qbs.build() | ||
def package(self): | ||
qbs = Qbs(self) | ||
qbs.profile = "" | ||
qbs.install() | ||
def package_info(self): | ||
self.cpp_info.libs = ["{{name}}"] | ||
''' | ||
|
||
qbs_lib_file = ''' | ||
Library { | ||
property bool isShared: true | ||
name: "{{name}}" | ||
type: isShared ? "dynamiclibrary" : "staticlibrary" | ||
files: [ "{{name}}.cpp" ] | ||
Group { | ||
name: "headers" | ||
files: [ "{{name}}.h" ] | ||
qbs.install: true | ||
qbs.installDir: "include" | ||
} | ||
Depends { name: "cpp" } | ||
Depends { name: "bundle" } | ||
bundle.isBundle: false | ||
install: true | ||
qbs.installPrefix: "" | ||
} | ||
''' | ||
|
||
test_conanfile_v2 = """import os | ||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.qbs import Qbs | ||
from conan.tools.build import cmd_args_to_string | ||
class {{package_name}}TestConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "PkgConfigDeps" | ||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
def build(self): | ||
qbs = Qbs(self) | ||
qbs.profile = "" | ||
qbs.build() | ||
qbs.install() | ||
def test(self): | ||
if can_run(self): | ||
cmd = os.path.join(self.package_folder, "bin", "example") | ||
self.run(cmd_args_to_string([cmd]), env="conanrun") | ||
""" | ||
|
||
qbs_test_file = ''' | ||
Application { | ||
name: "example" | ||
consoleApplication: true | ||
files: [ "example.cpp" ] | ||
Depends { name: "cpp" } | ||
install: true | ||
qbs.installPrefix: "" | ||
// external dependency via pkg-config | ||
qbsModuleProviders: ["qbspkgconfig"] | ||
moduleProviders.qbspkgconfig.libDirs: path | ||
Depends { name: "{{name}}" } | ||
} | ||
''' | ||
|
||
qbs_lib_files = {"conanfile.py": conanfile_sources, | ||
"{{name}}.qbs": qbs_lib_file, | ||
"{{name}}.cpp": source_cpp, | ||
"{{name}}.h": source_h, | ||
"test_package/conanfile.py": test_conanfile_v2, | ||
"test_package/example.cpp": test_main, | ||
"test_package/example.qbs": qbs_test_file} |
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
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,14 @@ | ||
import pytest | ||
|
||
from conan.test.utils.tools import TestClient | ||
|
||
@pytest.mark.parametrize('shared', [ | ||
('False'), | ||
('True'), | ||
]) | ||
@pytest.mark.tool("qbs") | ||
def test_api_qbs_create_lib(shared): | ||
client = TestClient() | ||
client.run("new qbs_lib -d name=hello -d version=1.0") | ||
client.run("create . -o:h &:shared={shared}".format(shared=shared)) | ||
assert "compiling hello.cpp" in client.out |