2 """Build OpenDaylight's .debs using build description and Jinja2 templates."""
7 from string import Template
10 import templates.build_debianfiles as build_debfiles
12 # This file is assumed to be in the root of the Deb build logic's dir structure
13 deb_root = os.path.dirname(os.path.abspath(__file__))
15 # FIXME: Surely there is a better way to do this
16 pkg_lib = imp.load_source("", os.path.join(deb_root, os.pardir, "lib.py"))
18 # Common paths used in this script
19 templates_dir = os.path.join(deb_root, "templates")
21 # Templates that can be specialized per-build
22 # NB: Templates can't be concatenated with other Templates or strings, or
23 # cast to strings for concatenation. If they could, we would do elegant
24 # refactoring like concatenating paths to templates here and only calling
25 # Template.substitute in the build_rpm function.
26 deb_template = Template("opendaylight/opendaylight_$version_major."
27 "$version_minor.$version_patch-${pkg_version}_all.deb")
28 src_in_dir_template = Template("opendaylight/opendaylight-$version_major."
29 "$version_minor.$version_patch-$pkg_version/")
30 cfg_in_dir_template = Template("opendaylight/opendaylight-$version_major."
31 "$version_minor.$version_patch-$pkg_version/"
36 """Build the .deb described by the given build description.
38 :param build: Description of a Debian build
42 # Specialize templates for the given build
43 cfg_in_dir = os.path.join(
45 cfg_in_dir_template.substitute(build))
46 control_file_path = os.path.join(
48 src_in_dir_template.substitute(build),
50 deb = os.path.join(deb_root, deb_template.substitute(build))
51 src_in_dir_path = os.path.join(
53 src_in_dir_template.substitute(build))
55 # Cache ODL distro and systemd unit file to package
56 distro_tar_path = pkg_lib.cache_distro(build)
57 distro_tar_name = os.path.basename(distro_tar_path)
58 build['tarball_name'] = distro_tar_name
59 unitfile_path = pkg_lib.cache_sysd(build)["unitfile_path"]
61 # Call helper script to build the required Debian files
62 build_debfiles.build_debfiles(build)
64 # Copy ODL tarball into src input directory
65 shutil.copy(distro_tar_path, src_in_dir_path)
67 # Copy ODL systemd unit file to src input directory
68 shutil.copy(unitfile_path, cfg_in_dir)
70 # Build Debian package
71 os.chdir(src_in_dir_path)
72 subprocess.call(["dpkg-buildpackage", "-us -uc -b", src_in_dir_path],
75 # Build package that includes build dependencies
76 subprocess.call(["sudo mk-build-deps -i " + control_file_path], shell=True)
79 # Copy the .debs from their output dir to the cache dir
80 shutil.copy(deb, pkg_lib.cache_dir)