def do(args): """ Import a binary package into a toolchain - Check that there is a CMake module into the binary package - Add the qiBuild package to the cache - Add the qiBuild package from cache to toolchain """ package_name = args.package_name package_path = args.package_path with qibuild.sh.TempDir() as tmp: package = qitoolchain.binary_package.open_package(package_path) package_metadata = package.get_metadata() if package_name is None: package_name = package_metadata['name'] package_names = [ package_name, package_metadata['name'] ] package_names = list(set(package_names)) tc = qitoolchain.get_toolchain(args) # extract it to the default packages path of the toolchain tc_packages_path = qitoolchain.toolchain.get_default_packages_path(tc.name) dest = os.path.join(tc_packages_path, package_name) qibuild.sh.rm(dest) LOGGER.info(_MESSAGE_START.format(tc.name, package_name)) with qibuild.sh.TempDir() as tmp: qibuild_pkg = _convert_to_qibuild(tmp, package, package_names) extracted = qibuild.archive.extract(qibuild_pkg, tmp, quiet=True) qibuild.sh.install(extracted, dest, quiet=True) qibuild_package = qitoolchain.Package(package_name, dest) tc.add_package(qibuild_package) LOGGER.info(_MESSAGE_END.format(tc.name, package_name))
def do(args): """ Import a binary package into a toolchain - Convert the binary package into a qiBuild package - Add the qiBuild package to the cache - Add the qiBuild package from cache to toolchain """ name = args.name package_path = args.package_path converted_package_path = convert_package(package_path, name, interactive=True) toolchain = qitoolchain.parsers.get_toolchain(args) tc_packages_path = qitoolchain.toolchain.get_default_packages_path( toolchain.name) message = """ Importing '{1}' in the toolchain {0} ... """.format(toolchain.name, package_path) qisys.ui.info(message) # installation of the qiBuild package package_dest = os.path.join(tc_packages_path, name) qisys.sh.rm(package_dest) with qisys.sh.TempDir() as tmp: extracted = qisys.archive.extract(converted_package_path, tmp, quiet=True) qisys.sh.install(extracted, package_dest, quiet=True) qibuild_package = qitoolchain.Package(name, package_dest) toolchain.add_package(qibuild_package) ui.info("done")
def parse_feed(toolchain, feed, qibuild_cfg, dry_run=False): """ Helper for toolchain.parse_feed """ # Reset toolchain.packages: package_names = [package.name for package in toolchain.packages] for package_name in package_names: toolchain.remove_package(package_name) parser = ToolchainFeedParser() parser.parse(feed) package_trees = parser.packages errors = list() for package_tree in package_trees: package = qitoolchain.Package(None, None) if dry_run: package_name = package_tree.get("name") package_url = package_tree.get("url") # Check that url can be opened fp = None try: fp = qitoolchain.remote.open_remote_location(package_url) except Exception, e: error = "Could not add %s from %s\n" % (package_name, package_url) error += "Error was: %s" % e errors.append(error) continue finally:
def test_add_package_with_tc_file(self): tc = qitoolchain.Toolchain("test") naoqi_ctc = qitoolchain.Package("naoqi-ctc", "/path/to/ctc", "toolchain-geode.cmake") tc.add_package(naoqi_ctc) tc_file = get_tc_file_contents(tc) self.assertTrue('include("toolchain-geode.cmake")' in tc_file, tc_file)
def test_remove_package_with_tc_file(self): tc = qitoolchain.Toolchain("test") naoqi_ctc = qitoolchain.Package("naoqi-ctc", "/path/to/ctc", "toolchain-geode.cmake") tc.add_package(naoqi_ctc) tc.remove_package("naoqi-ctc") tc_file = get_tc_file_contents(tc) self.assertFalse("toolchain-geode.cmake" in tc_file)
def setUp(self): self.tmp = tempfile.mkdtemp(prefix="test-feed") qibuild.sh.mkdir(os.path.join(self.tmp, "qi")) self.world_package = qitoolchain.Package("world", "package/world") self.world_project = qibuild.project.Project("world", "src/world") self.hello_project = qibuild.project.Project("hello", "src/hello") self.world_project.build_directory = "src/world/build" self.hello_project.build_directory = "src/hello/build" self.hello_project.depends = ["world"] self.toc = qibuild.toc.Toc(self.tmp)
def test_tc_order(self): tc = qitoolchain.Toolchain("test") a_path = "/path/to/a" b_path = "/path/to/b" a_cmake = "a-config.cmake" b_cmake = "b-config.cmake" a_package = qitoolchain.Package("a", a_path, a_cmake) b_package = qitoolchain.Package("b", b_path, b_cmake) tc.add_package(a_package) tc.add_package(b_package) tc_file = get_tc_file_contents(tc) tc_file_lines = tc_file.splitlines() a_path_index = 0 b_path_index = 0 a_cmake_index = 0 b_cmake_index = 0 for (i, line) in enumerate(tc_file_lines): if a_cmake in line: a_cmake_index = i if b_cmake in line: b_cmake_index = i if a_path in line: a_path_index = i if b_path in line: b_path_index = i self.assertTrue(a_path_index != 0) self.assertTrue(b_path_index != 0) self.assertTrue(a_cmake_index != 0) self.assertTrue(b_cmake_index != 0) # Check that toolchain files are always written before # CMAKE_FIND_ROOT_PATH self.assertTrue(a_cmake_index < a_path_index) self.assertTrue(a_cmake_index < b_path_index) self.assertTrue(b_cmake_index < a_path_index) self.assertTrue(b_cmake_index < b_path_index)
def do(args): """ Add a package to a toolchain - Check that there is a current toolchain - Add the package to the cache - Add the package from cache to toolchain """ package_name = args.package_name package_path = args.package_path tc = qitoolchain.get_toolchain(args) # extract it to the default packages path of the toolchain tc_packages_path = qitoolchain.toolchain.get_default_packages_path(tc.name) dest = os.path.join(tc_packages_path, package_name) qibuild.sh.rm(dest) with qibuild.sh.TempDir() as tmp: extracted = qibuild.archive.extract(package_path, tmp) qibuild.sh.install(extracted, dest, quiet=True) package = qitoolchain.Package(package_name, dest) tc.add_package(package)
def test_add_package(self): tc = qitoolchain.Toolchain("test") self.assertEquals(tc.packages, list()) foo_package = qitoolchain.Package("foo", "/path/to/foo") tc.add_package(foo_package) self.assertEquals(tc.packages, [foo_package]) # Check that generated toolchain file is correct tc_file = get_tc_file_contents(tc) self.assertTrue( 'list(INSERT CMAKE_FIND_ROOT_PATH 0 "%s")' % "/path/to/foo" in tc_file, tc_file) # Check that adding the package twice does nothing tc.add_package(foo_package) self.assertEquals(tc.packages, [foo_package]) # Create a new toolchain object and check that toolchain # file contents did not change other_tc = qitoolchain.Toolchain("test") other_tc_file = get_tc_file_contents(other_tc) self.assertEquals(other_tc_file, tc_file)
class QiToolchainTestCase(unittest.TestCase): def setUp(self): """ Small hack: set qitoolchain.CONFIG_PATH global variable for test """ self.tmp = tempfile.mkdtemp(prefix="test-qitoolchain") qitoolchain.toolchain.CONFIG_PATH = os.path.join(self.tmp, "config") qitoolchain.toolchain.CACHE_PATH = os.path.join(self.tmp, "cache") qitoolchain.toolchain.SHARE_PATH = os.path.join(self.tmp, "share") def tearDown(self): qibuild.sh.rm(self.tmp) def test_setup(self): # Check that we are not modifying normal config config_path = qitoolchain.get_tc_config_path() expected = os.path.join(self.tmp, "config", "toolchains.cfg") self.assertEquals(config_path, expected) # Check that there are no toolchain yet tc_names = qitoolchain.get_tc_names() self.assertEquals(tc_names, list()) def test_create_toolchain(self): qitoolchain.Toolchain("foo") self.assertEquals(qitoolchain.get_tc_names(), ["foo"]) def test_remove_toolchain(self): tc = qitoolchain.Toolchain("foo") self.assertEquals(qitoolchain.get_tc_names(), ["foo"]) tc.remove() self.assertEquals(qitoolchain.get_tc_names(), list()) def test_add_package(self): tc = qitoolchain.Toolchain("test") self.assertEquals(tc.packages, list()) foo_package = qitoolchain.Package("foo", "/path/to/foo") tc.add_package(foo_package) self.assertEquals(tc.packages, [foo_package]) # Check that generated toolchain file is correct tc_file = get_tc_file_contents(tc) self.assertTrue( 'list(INSERT CMAKE_FIND_ROOT_PATH 0 "%s")' % "/path/to/foo" in tc_file, tc_file) # Check that adding the package twice does nothing tc.add_package(foo_package) self.assertEquals(tc.packages, [foo_package]) # Create a new toolchain object and check that toolchain # file contents did not change other_tc = qitoolchain.Toolchain("test") other_tc_file = get_tc_file_contents(other_tc) self.assertEquals(other_tc_file, tc_file) def test_remove_package(self): tc = qitoolchain.Toolchain("test") error = None try: tc.remove_package("foo") except Exception, e: error = e self.assertFalse(error is None) self.assertTrue("No such package" in str(error)) foo_package = qitoolchain.Package("foo", "/path/to/foo") tc.add_package(foo_package) tc.remove_package("foo") tc_file = get_tc_file_contents(tc) self.assertFalse("/path/to/foo" in tc_file)