Matthew Barth | ccb7f85 | 2016-11-23 17:43:02 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | """ |
| 4 | This script determines the given package's openbmc dependencies from its |
| 5 | configure.ac file where it downloads, configures, builds, and installs each of |
| 6 | these dependencies. Then the given package is configured, built, and installed |
| 7 | prior to executing its unit tests. |
| 8 | """ |
| 9 | |
Matthew Barth | d181037 | 2016-12-19 16:57:21 -0600 | [diff] [blame] | 10 | from git import Repo |
Matthew Barth | ccb7f85 | 2016-11-23 17:43:02 -0600 | [diff] [blame] | 11 | from urlparse import urljoin |
Matthew Barth | 33df879 | 2016-12-19 14:30:17 -0600 | [diff] [blame] | 12 | from subprocess import check_call, call |
Matthew Barth | ccb7f85 | 2016-11-23 17:43:02 -0600 | [diff] [blame] | 13 | import os |
| 14 | import sys |
Matthew Barth | 33df879 | 2016-12-19 14:30:17 -0600 | [diff] [blame] | 15 | import argparse |
| 16 | |
| 17 | |
| 18 | def check_call_cmd(dir, *cmd): |
| 19 | """ |
| 20 | Verbose prints the directory location the given command is called from and |
| 21 | the command, then executes the command using check_call. |
| 22 | |
| 23 | Parameter descriptions: |
| 24 | dir Directory location command is to be called from |
| 25 | cmd List of parameters constructing the complete command |
| 26 | """ |
| 27 | printline(dir, ">", " ".join(cmd)) |
| 28 | check_call(cmd) |
Matthew Barth | ccb7f85 | 2016-11-23 17:43:02 -0600 | [diff] [blame] | 29 | |
| 30 | |
| 31 | def clone_pkg(pkg): |
Matthew Barth | 33df879 | 2016-12-19 14:30:17 -0600 | [diff] [blame] | 32 | """ |
| 33 | Clone the given openbmc package's git repository from gerrit into |
| 34 | the WORKSPACE location |
| 35 | |
| 36 | Parameter descriptions: |
| 37 | pkg Name of the package to clone |
| 38 | """ |
Matthew Barth | ccb7f85 | 2016-11-23 17:43:02 -0600 | [diff] [blame] | 39 | pkg_repo = urljoin('https://gerrit.openbmc-project.xyz/openbmc/', pkg) |
Matthew Barth | d181037 | 2016-12-19 16:57:21 -0600 | [diff] [blame] | 40 | os.mkdir(os.path.join(WORKSPACE, pkg)) |
| 41 | printline(os.path.join(WORKSPACE, pkg), "> git clone", pkg_repo, "./") |
| 42 | return Repo.clone_from(pkg_repo, os.path.join(WORKSPACE, pkg)) |
Matthew Barth | 33df879 | 2016-12-19 14:30:17 -0600 | [diff] [blame] | 43 | |
| 44 | |
| 45 | def get_deps(configure_ac): |
| 46 | """ |
| 47 | Parse the given 'configure.ac' file for package dependencies and return |
| 48 | a list of the dependencies found. |
| 49 | |
| 50 | Parameter descriptions: |
| 51 | configure_ac Opened 'configure.ac' file object |
| 52 | """ |
| 53 | line = "" |
Brad Bishop | ebb4911 | 2017-02-13 11:07:26 -0500 | [diff] [blame] | 54 | dep_pkgs = set() |
Matthew Barth | 33df879 | 2016-12-19 14:30:17 -0600 | [diff] [blame] | 55 | for cfg_line in configure_ac: |
| 56 | # Remove whitespace & newline |
| 57 | cfg_line = cfg_line.rstrip() |
| 58 | # Check for line breaks |
| 59 | if cfg_line.endswith('\\'): |
| 60 | line += str(cfg_line[:-1]) |
| 61 | continue |
| 62 | line = line+cfg_line |
| 63 | |
| 64 | # Find any defined dependency |
Brad Bishop | ebb4911 | 2017-02-13 11:07:26 -0500 | [diff] [blame] | 65 | line_has = lambda x: x if x in line else None |
| 66 | macros = set(filter(line_has, DEPENDENCIES.iterkeys())) |
| 67 | if len(macros) == 1: |
| 68 | macro = ''.join(macros) |
| 69 | deps = filter(line_has, DEPENDENCIES[macro].iterkeys()) |
| 70 | dep_pkgs.update(map(lambda x: DEPENDENCIES[macro][x], deps)) |
| 71 | |
Matthew Barth | 33df879 | 2016-12-19 14:30:17 -0600 | [diff] [blame] | 72 | line = "" |
| 73 | |
Brad Bishop | ebb4911 | 2017-02-13 11:07:26 -0500 | [diff] [blame] | 74 | return list(dep_pkgs) |
Matthew Barth | ccb7f85 | 2016-11-23 17:43:02 -0600 | [diff] [blame] | 75 | |
| 76 | |
| 77 | def build_depends(pkg, pkgdir, dep_installed): |
| 78 | """ |
| 79 | For each package(pkg), starting with the package to be unit tested, |
| 80 | parse its 'configure.ac' file from within the package's directory(pkgdir) |
| 81 | for each package dependency defined recursively doing the same thing |
| 82 | on each package found as a dependency. |
| 83 | |
| 84 | Parameter descriptions: |
| 85 | pkg Name of the package |
| 86 | pkgdir Directory where package source is located |
| 87 | dep_installed Current list of dependencies and installation status |
| 88 | """ |
| 89 | os.chdir(pkgdir) |
| 90 | # Open package's configure.ac |
Matthew Barth | 33df879 | 2016-12-19 14:30:17 -0600 | [diff] [blame] | 91 | with open("configure.ac", "rt") as configure_ac: |
| 92 | # Retrieve dependency list from package's configure.ac |
| 93 | configure_ac_deps = get_deps(configure_ac) |
| 94 | for dep_pkg in configure_ac_deps: |
| 95 | # Dependency package not already known |
| 96 | if dep_installed.get(dep_pkg) is None: |
| 97 | # Dependency package not installed |
| 98 | dep_installed[dep_pkg] = False |
Matthew Barth | d181037 | 2016-12-19 16:57:21 -0600 | [diff] [blame] | 99 | dep_repo = clone_pkg(dep_pkg) |
Matthew Barth | 33df879 | 2016-12-19 14:30:17 -0600 | [diff] [blame] | 100 | # Determine this dependency package's |
| 101 | # dependencies and install them before |
| 102 | # returning to install this package |
| 103 | dep_pkgdir = os.path.join(WORKSPACE, dep_pkg) |
Matthew Barth | d181037 | 2016-12-19 16:57:21 -0600 | [diff] [blame] | 104 | dep_installed = build_depends(dep_pkg, |
| 105 | dep_repo.working_dir, |
Matthew Barth | 33df879 | 2016-12-19 14:30:17 -0600 | [diff] [blame] | 106 | dep_installed) |
| 107 | else: |
| 108 | # Dependency package known and installed |
| 109 | if dep_installed[dep_pkg]: |
Matthew Barth | ccb7f85 | 2016-11-23 17:43:02 -0600 | [diff] [blame] | 110 | continue |
Matthew Barth | 33df879 | 2016-12-19 14:30:17 -0600 | [diff] [blame] | 111 | else: |
| 112 | # Cyclic dependency failure |
| 113 | raise Exception("Cyclic dependencies found in "+pkg) |
Matthew Barth | ccb7f85 | 2016-11-23 17:43:02 -0600 | [diff] [blame] | 114 | |
| 115 | # Build & install this package |
| 116 | if not dep_installed[pkg]: |
Matthew Barth | 1d1c673 | 2017-03-24 10:00:28 -0500 | [diff] [blame] | 117 | conf_flags = [] |
Matthew Barth | ccb7f85 | 2016-11-23 17:43:02 -0600 | [diff] [blame] | 118 | os.chdir(pkgdir) |
| 119 | # Add any necessary configure flags for package |
| 120 | if CONFIGURE_FLAGS.get(pkg) is not None: |
Matthew Barth | 1d1c673 | 2017-03-24 10:00:28 -0500 | [diff] [blame] | 121 | conf_flags.extend(CONFIGURE_FLAGS.get(pkg)) |
Matthew Barth | 33df879 | 2016-12-19 14:30:17 -0600 | [diff] [blame] | 122 | check_call_cmd(pkgdir, './bootstrap.sh') |
Matthew Barth | 1d1c673 | 2017-03-24 10:00:28 -0500 | [diff] [blame] | 123 | check_call_cmd(pkgdir, './configure', *conf_flags) |
Matthew Barth | 33df879 | 2016-12-19 14:30:17 -0600 | [diff] [blame] | 124 | check_call_cmd(pkgdir, 'make') |
| 125 | check_call_cmd(pkgdir, 'make', 'install') |
Matthew Barth | ccb7f85 | 2016-11-23 17:43:02 -0600 | [diff] [blame] | 126 | dep_installed[pkg] = True |
| 127 | |
| 128 | return dep_installed |
| 129 | |
| 130 | |
| 131 | if __name__ == '__main__': |
| 132 | # CONFIGURE_FLAGS = [GIT REPO]:[CONFIGURE FLAGS] |
| 133 | CONFIGURE_FLAGS = { |
Adriana Kobylak | 43c31e8 | 2017-02-13 09:28:35 -0600 | [diff] [blame] | 134 | 'phosphor-objmgr': ['--enable-unpatched-systemd'], |
Matthew Barth | 1d1c673 | 2017-03-24 10:00:28 -0500 | [diff] [blame] | 135 | 'sdbusplus': ['--enable-transaction'], |
| 136 | 'phosphor-logging': |
| 137 | ['--enable-metadata-processing', |
| 138 | 'YAML_DIR=/usr/local/share/phosphor-dbus-interfaces/yaml'] |
Matthew Barth | ccb7f85 | 2016-11-23 17:43:02 -0600 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | # DEPENDENCIES = [MACRO]:[library/header]:[GIT REPO] |
| 142 | DEPENDENCIES = { |
| 143 | 'AC_CHECK_LIB': {'mapper': 'phosphor-objmgr'}, |
Matthew Barth | 710f3f0 | 2017-01-18 15:20:19 -0600 | [diff] [blame] | 144 | 'AC_CHECK_HEADER': { |
| 145 | 'host-ipmid': 'phosphor-host-ipmid', |
| 146 | 'sdbusplus': 'sdbusplus', |
Saqib Khan | 6614505 | 2017-02-14 12:02:07 -0600 | [diff] [blame] | 147 | 'phosphor-logging/log.hpp': 'phosphor-logging', |
Patrick Williams | eab8a37 | 2017-01-30 11:21:32 -0600 | [diff] [blame] | 148 | }, |
Brad Bishop | ebb4911 | 2017-02-13 11:07:26 -0500 | [diff] [blame] | 149 | 'AC_PATH_PROG': {'sdbus++': 'sdbusplus'}, |
Patrick Williams | eab8a37 | 2017-01-30 11:21:32 -0600 | [diff] [blame] | 150 | 'PKG_CHECK_MODULES': { |
Matthew Barth | 19e261e | 2017-02-01 12:55:22 -0600 | [diff] [blame] | 151 | 'phosphor-dbus-interfaces': 'phosphor-dbus-interfaces', |
Patrick Williams | f128b40 | 2017-03-29 06:45:59 -0500 | [diff] [blame] | 152 | 'openpower-dbus-interfaces': 'openpower-dbus-interfaces', |
Brad Bishop | ebb4911 | 2017-02-13 11:07:26 -0500 | [diff] [blame] | 153 | 'sdbusplus': 'sdbusplus', |
| 154 | 'phosphor-logging': 'phosphor-logging', |
| 155 | }, |
Matthew Barth | ccb7f85 | 2016-11-23 17:43:02 -0600 | [diff] [blame] | 156 | } |
| 157 | |
Matthew Barth | 33df879 | 2016-12-19 14:30:17 -0600 | [diff] [blame] | 158 | # Set command line arguments |
| 159 | parser = argparse.ArgumentParser() |
| 160 | parser.add_argument("-w", "--workspace", dest="WORKSPACE", required=True, |
| 161 | help="Workspace directory location(i.e. /home)") |
| 162 | parser.add_argument("-p", "--package", dest="PACKAGE", required=True, |
| 163 | help="OpenBMC package to be unit tested") |
| 164 | parser.add_argument("-v", "--verbose", action="store_true", |
| 165 | help="Print additional package status messages") |
| 166 | args = parser.parse_args(sys.argv[1:]) |
| 167 | WORKSPACE = args.WORKSPACE |
| 168 | UNIT_TEST_PKG = args.PACKAGE |
| 169 | if args.verbose: |
| 170 | def printline(*line): |
| 171 | for arg in line: |
| 172 | print arg, |
| 173 | print |
| 174 | else: |
| 175 | printline = lambda *l: None |
Matthew Barth | ccb7f85 | 2016-11-23 17:43:02 -0600 | [diff] [blame] | 176 | |
| 177 | prev_umask = os.umask(000) |
| 178 | # Determine dependencies and install them |
| 179 | dep_installed = dict() |
| 180 | dep_installed[UNIT_TEST_PKG] = False |
| 181 | dep_installed = build_depends(UNIT_TEST_PKG, |
| 182 | os.path.join(WORKSPACE, UNIT_TEST_PKG), |
| 183 | dep_installed) |
| 184 | os.chdir(os.path.join(WORKSPACE, UNIT_TEST_PKG)) |
Matthew Barth | 948b7cc | 2017-02-21 09:13:54 -0600 | [diff] [blame] | 185 | # Refresh dynamic linker run time bindings for dependencies |
| 186 | check_call_cmd(os.path.join(WORKSPACE, UNIT_TEST_PKG), 'ldconfig') |
Matthew Barth | ccb7f85 | 2016-11-23 17:43:02 -0600 | [diff] [blame] | 187 | # Run package unit tests |
Matthew Barth | 4ecbc9c | 2017-02-17 10:34:46 -0600 | [diff] [blame] | 188 | if args.verbose: |
| 189 | check_call_cmd(os.path.join(WORKSPACE, UNIT_TEST_PKG), 'make', 'check', |
| 190 | 'VERBOSE=1') |
| 191 | else: |
| 192 | check_call_cmd(os.path.join(WORKSPACE, UNIT_TEST_PKG), 'make', 'check') |
Matthew Barth | ccb7f85 | 2016-11-23 17:43:02 -0600 | [diff] [blame] | 193 | os.umask(prev_umask) |