Skip to content

Commit

Permalink
Qbs: fix handling spaces
Browse files Browse the repository at this point in the history
Also add a simple static lib functional test
as well as api to create libs.
  • Loading branch information
ABBAPOH committed Jun 1, 2024
1 parent f042537 commit f38d6bd
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 5 deletions.
4 changes: 3 additions & 1 deletion conan/api/subapi/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def get_builtin_template(template_name):
from conan.internal.api.new.autotools_lib import autotools_lib_files
from conan.internal.api.new.autoools_exe import autotools_exe_files
from conan.internal.api.new.local_recipes_index import local_recipes_index_files
from conan.internal.api.new.qbs_lib import qbs_lib_files
new_templates = {"basic": basic_file,
"cmake_lib": cmake_lib_files,
"cmake_exe": cmake_exe_files,
Expand All @@ -41,7 +42,8 @@ def get_builtin_template(template_name):
"autotools_lib": autotools_lib_files,
"autotools_exe": autotools_exe_files,
"alias": alias_file,
"local_recipes_index": local_recipes_index_files}
"local_recipes_index": local_recipes_index_files,
"qbs_lib": qbs_lib_files}
template_files = new_templates.get(template_name)
return template_files

Expand Down
46 changes: 46 additions & 0 deletions conan/internal/api/new/qbs_lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from conan.internal.api.new.cmake_lib import source_cpp, source_h


conanfile_sources = '''
import os
from conan import ConanFile, tools
from conan.tools.qbs import Qbs
from conan.tools.files import copy, collect_libs
class {{package_name}}Recipe(ConanFile):
name = "{{name}}"
version = "{{version}}"
exports_sources = "*.cpp", "*.h", "*.qbs"
settings = "os", "compiler", "arch"
def build(self):
qbs = Qbs(self)
qbs.profile = ""
qbs.build()
def package(self):
qbs = Qbs(self)
qbs.profile = ""
qbs.install()
def package_info(self):
self.cpp_info.libs = collect_libs(self)
'''

qbs_file = '''
Library {
type: "staticlibrary"
files: [ "{{name}}.h", "{{name}}.cpp" ]
Depends { name: "cpp" }
Depends { name: "bundle" }
bundle.isBundle: false
install: true
}
'''

qbs_lib_files = {"conanfile.py": conanfile_sources,
"{{name}}.qbs": qbs_file,
"{{name}}.cpp": source_cpp,
"{{name}}.h": source_h}
8 changes: 4 additions & 4 deletions conan/tools/qbs/qbs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from conan.tools.build import build_jobs
from conan.tools.build import build_jobs, cmd_args_to_string
from conan.errors import ConanException


Expand Down Expand Up @@ -59,7 +59,7 @@ def build(self, products=None):
config = self._configuration[name]
args.extend(_configuration_dict_to_commandlist(name, config))

cmd = 'qbs build %s' % (' '.join(args))
cmd = 'qbs build %s' % cmd_args_to_string(args)
self._conanfile.run(cmd)

def build_all(self):
Expand All @@ -79,7 +79,7 @@ def build_all(self):
config = self._configuration[name]
args.extend(_configuration_dict_to_commandlist(name, config))

cmd = 'qbs build %s' % (' '.join(args))
cmd = 'qbs build %s' % cmd_args_to_string(args)
self._conanfile.run(cmd)

def install(self):
Expand All @@ -92,5 +92,5 @@ def install(self):
for name in self._configuration:
args.append('config:%s' % name)

cmd = 'qbs install %s' % (' '.join(args))
cmd = 'qbs install %s' % cmd_args_to_string(args)
self._conanfile.run(cmd)
40 changes: 40 additions & 0 deletions test/functional/toolchains/qbs/test_qbs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import pytest

from conan.internal.api.new.cmake_lib import source_cpp, source_h
from conan.internal.api.new.qbs_lib import qbs_file, conanfile_sources
from conan.test.utils.tools import TestClient
from jinja2 import Template


def gen_file(template, **context):
t = Template(template)
return t.render(**context)


@pytest.mark.tool("qbs")
def test_qbs_static_lib():
client = TestClient()

context = {
"name": "hello",
"version": "2.0",
"package_name": "hello"
}

client.save({
"conanfile.py": gen_file(conanfile_sources, **context),
"hello.cpp": gen_file(source_cpp, **context),
"hello.h": gen_file(source_h, **context),
"hello.qbs": gen_file(qbs_file, **context),
}, clean_first=True)

client.run("create .")
assert "compiling hello.cpp" in client.out


@pytest.mark.tool("qbs")
def test_api_qbs_create_lib():
client = TestClient()
client.run("new qbs_lib -d name=hello -d version=1.0")
client.run("create .")
assert "compiling hello.cpp" in client.out

0 comments on commit f38d6bd

Please sign in to comment.