def test_collect_integration(cli, datafiles): project = str(datafiles) checkout = os.path.join(project, "checkout") element_name = "collect_integration/collect.bst" result = cli.run(project=project, args=["build", element_name]) result.assert_success() result = cli.run( project=project, args=["artifact", "checkout", "--directory", checkout, element_name], ) result.assert_success() assert_contains(checkout, ["/script.sh"]) with open(os.path.join(checkout, "script.sh"), "r") as f: artifact = f.readlines() expected = [ "#!/bin/sh\n", "set -e\n", "\n", "# integration commands from collect_integration/dep1.bst\n", "foo\n", "\n", "bar\n", "\n", "# integration commands from collect_integration/dep2.bst\n", "baz\n", "\n", "quuz\n", "\n", ] assert artifact == expected
def test_tar_build(cli, datafiles): project = str(datafiles) checkout_dir = os.path.join(cli.directory, "tar_checkout") tarpath = os.path.join(checkout_dir, "hello.tar.gz") result = cli.run(project=project, args=["build", "tar-test.bst"]) result.assert_success() result = cli.run( project=project, args=[ "artifact", "checkout", "--directory", checkout_dir, "tar-test.bst", ], ) result.assert_success() assert_contains(checkout_dir, ["/hello.tar.gz"]) tar_hello = tarfile.open(tarpath) contents = tar_hello.getnames() assert contents == ["hello.c"]
def test_distutils_run(cli, datafiles): project = str(datafiles) element_name = "distutils/distutilshello.bst" result = cli.run(project=project, args=["build", element_name]) assert result.exit_code == 0 result = cli.run(project=project, args=["shell", element_name, "/usr/bin/hello"]) assert result.exit_code == 0 assert result.output == """Hello World!\n"""
def test_make_run(cli, datafiles): project = str(datafiles) element_name = "make/makehello.bst" result = cli.run(project=project, args=["build", element_name]) assert result.exit_code == 0 result = cli.run( project=project, args=["shell", element_name, "/usr/bin/hello"] ) assert result.exit_code == 0 assert result.output == "Hello, world\n"
def test_cmake_confroot_build(cli, datafiles): project = str(datafiles) checkout = os.path.join(cli.directory, "checkout") element_name = "cmake/cmakeconfroothello.bst" result = cli.run(project=project, args=["build", element_name]) assert result.exit_code == 0 result = cli.run( project=project, args=["artifact", "checkout", element_name, "--directory", checkout], ) assert result.exit_code == 0 assert_contains(checkout, ["/usr", "/usr/bin", "/usr/bin/hello"])
def test_dpkg_deploy(cli, datafiles): project = str(datafiles) checkout_dir = os.path.join(cli.directory, "debian_package") result = cli.run(project=project, args=["build", "dpkg-deploy-test.bst"]) result.assert_success() result = cli.run( project=project, args=[ "artifact", "checkout", "--directory", checkout_dir, "dpkg-deploy-test.bst", ], ) result.assert_success() # FIXME: assert_contains() doesn't seem to like this .deb file assert os.listdir(checkout_dir) == ["test_0.1_amd64.deb"]
def test_dpkg_build(cli, datafiles): project = str(datafiles) checkout_dir = os.path.join(cli.directory, "checkout") result = cli.run(project=project, args=["build", "dpkg-build-test.bst"]) result.assert_success() result = cli.run( project=project, args=[ "artifact", "checkout", "--directory", checkout_dir, "dpkg-build-test.bst", ], ) result.assert_success() assert_contains(checkout_dir, ["/usr/share/foo", "/usr/share/doc/test/changelog.gz"])
def test_quilt_build(cli, datafiles): project = str(datafiles) checkout = os.path.join(cli.directory, "quilt_checkout") result = cli.run(project=project, args=["build", "quilt-build-test.bst"]) result.assert_success() result = cli.run( project=project, args=[ "artifact", "checkout", "--directory", checkout, "quilt-build-test.bst", ], ) result.assert_success() assert_contains(checkout, ["/patches/series", "/patches/test", "/src/hello.c"])
def test_gen_ccimports(cli, datafiles): project = str(datafiles) checkout = os.path.join(project, "checkout") prj_prefix = "bazelize-" element_name = "bazelize/imports.bst" build_file = "BUILD" # default build file name # try to build result = cli.run( project=project, args=["build", element_name], ) result.assert_success() # try to checkout result = cli.run( project=project, args=["artifact", "checkout", "--directory", checkout, element_name], ) result.assert_success() # check for existence of the build file assert_contains(checkout, [os.path.sep + build_file]) # format test content to check against the content of the build file # format expected library data def gen_cc_lib(lib_type): libname = "ccimp_" + lib_type lib_map = {"interface": ".ifso", "shared": ".so", "static": ".a"} if lib_type == "multi": lib_ext = [lib_map["interface"], lib_map["shared"]] else: lib_ext = [lib_map[lib_type]] files = get_files(libname, lib_ext, LIB_PREFIX) lib_entries = {} for fname in files: for k, v in lib_map.items(): if fname.endswith(v): lib_entries["{}_library".format(k)] = fname entry = { "rule": "cc_import", "name": prj_prefix + libname, "hdrs": sorted(get_hdrs(libname)), } for k, v in lib_entries.items(): entry[k] = v return entry # nb. current rules are sorted by name field in the plugin expected = [ 'package(default_visibility = ["//visibility:public"])' + os.linesep ] expected.extend( ['load("@rules_cc//cc:defs.bzl", "cc_import")' + os.linesep]) lib_types = sorted(["shared", "static", "multi"]) for lib_type in lib_types: expected += render_entry(gen_cc_lib(lib_type)) with open(os.path.join(checkout, build_file), "r") as fdata: artifact = fdata.readlines() assert artifact == expected
def test_gen_buildrules(cli, datafiles): project = str(datafiles) checkout = os.path.join(project, "checkout") prj_prefix = "bazelize-" element_name = "bazelize/empty.bst" build_file = "BUILD" # default build file name # try to build result = cli.run( project=project, args=["build", element_name], ) result.assert_success() # try to checkout result = cli.run( project=project, args=["artifact", "checkout", "--directory", checkout, element_name], ) result.assert_success() # check for existence of the build file assert_contains(checkout, [os.path.sep + build_file]) # format test content to check against the content of the build file # format expected library data def gen_cc_lib(num): libname = "cclib" + str(num) return { "rule": "cc_library", "name": prj_prefix + libname, "srcs": sorted(get_libs(libname) + get_srcs(libname)), "hdrs": sorted(get_hdrs(libname)), } # format expected binary data # FIXME: bin1_srcs are [glob(app/*)] or ["app/afile.cpp", "app/bfile.c"] # see #6 bin1_deps = [prj_prefix + "cclib2", prj_prefix + "cclib1"] bin1_opts = ["-I/lib/inc", "-I/include/someinc"] bin1_lopts = ["-lboost_thread", "-lboost_system"] bin1 = { "rule": "cc_binary", "name": prj_prefix + "bazelize", "deps": sorted(bin1_deps), "copts": sorted(bin1_opts), "linkopts": sorted(bin1_lopts), } # nb. current rules are sorted by name field in the plugin expected = [ 'package(default_visibility = ["//visibility:public"])' + os.linesep ] expected.extend([ 'load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")' + os.linesep ]) expected += render_entry(bin1) expected += render_entry(gen_cc_lib(1)) expected += render_entry(gen_cc_lib(2)) with open(os.path.join(checkout, build_file), "r") as fdata: artifact = fdata.readlines() assert artifact == expected