2 """Build OpenDaylight's .debs using build description and Jinja2 templates."""
6 from string import Template
9 import cache.cache as cache
10 import templates.build_debianfiles as build_debfiles
12 # Common paths used in this script
13 # This file is assumed to be in the root of the .deb build logic's dir
15 project_root = os.path.dirname(os.path.abspath(__file__))
17 # Cache directory for OpenDaylight's release tarball
18 cache_dir = os.path.join(project_root, "cache")
20 # Debian templates directory
21 templates_dir = os.path.join(project_root, "templates")
23 # Specialized opendaylight directory for each build
24 odl_dir_template = Template("opendaylight/opendaylight-$version_major.$version_minor."
25 "$version_patch-$pkg_version/")
26 odl_deb_template = Template("opendaylight/opendaylight_$version_major.$version_minor."
27 "$version_patch-${pkg_version}_all.deb")
31 """Build the .deb described by the given build description.
33 :param build: Description of a debian build
37 # Specialize a series of name templates for the given build
38 odl_dir_name = odl_dir_template.substitute(build)
39 odl_dir_path = os.path.join(templates_dir, os.pardir, odl_dir_name)
40 odl_deb = odl_deb_template.substitute(build)
42 # Call helper script to build the required debian files
43 build_debfiles.build_debfiles(build)
45 # Call a helper function to cache the artifacts required for each build
46 odl_tarball_path = cache.cache_build(build)
48 # Move ODL's tarball to the specialized OpenDaylight directory
49 shutil.copy(odl_tarball_path, odl_dir_path)
51 # Build debian package
52 os.chdir(odl_dir_path)
53 subprocess.call(["dpkg-buildpackage", "-us -uc -b",
54 odl_dir_path], shell=True)
56 # Install opendaylight's dependencies
57 control_file_path = os.path.join(odl_dir_path, "debian/control")
58 subprocess.call(["sudo mk-build-deps -i " + control_file_path], shell=True)
60 os.chdir(project_root)
62 # Copy the .debs from their output dir to the cache dir
63 shutil.copy(odl_deb, cache_dir)