Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: GPL-2.0-only |
| 5 | # |
| 6 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 7 | def create_socket(url, d): |
| 8 | import urllib |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 9 | from bb.utils import export_proxies |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 10 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 11 | export_proxies(d) |
| 12 | return urllib.request.urlopen(url) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 13 | |
| 14 | def get_links_from_url(url, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 | "Return all the href links found on the web location" |
| 16 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 17 | from bs4 import BeautifulSoup, SoupStrainer |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 18 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 19 | soup = BeautifulSoup(create_socket(url,d), "html.parser", parse_only=SoupStrainer("a")) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 20 | hyperlinks = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 21 | for line in soup.find_all('a', href=True): |
| 22 | hyperlinks.append(line['href'].strip('/')) |
| 23 | return hyperlinks |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 24 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 25 | def find_latest_numeric_release(url, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | "Find the latest listed numeric release on the given url" |
| 27 | max=0 |
| 28 | maxstr="" |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 29 | for link in get_links_from_url(url, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | try: |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 31 | # TODO use bb.utils.vercmp_string_op() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 32 | release = float(link) |
| 33 | except: |
| 34 | release = 0 |
| 35 | if release > max: |
| 36 | max = release |
| 37 | maxstr = link |
| 38 | return maxstr |
| 39 | |
| 40 | def is_src_rpm(name): |
| 41 | "Check if the link is pointing to a src.rpm file" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 42 | return name.endswith(".src.rpm") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 43 | |
| 44 | def package_name_from_srpm(srpm): |
| 45 | "Strip out the package name from the src.rpm filename" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 46 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 47 | # ca-certificates-2016.2.7-1.0.fc24.src.rpm |
| 48 | # ^name ^ver ^release^removed |
| 49 | (name, version, release) = srpm.replace(".src.rpm", "").rsplit("-", 2) |
| 50 | return name |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 51 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 52 | def get_source_package_list_from_url(url, section, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 53 | "Return a sectioned list of package names from a URL list" |
| 54 | |
| 55 | bb.note("Reading %s: %s" % (url, section)) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 56 | links = get_links_from_url(url, d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 57 | srpms = filter(is_src_rpm, links) |
| 58 | names_list = map(package_name_from_srpm, srpms) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 59 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 60 | new_pkgs = set() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 61 | for pkgs in names_list: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 62 | new_pkgs.add(pkgs + ":" + section) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 63 | return new_pkgs |
| 64 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 65 | def get_source_package_list_from_url_by_letter(url, section, d): |
| 66 | import string |
| 67 | from urllib.error import HTTPError |
| 68 | packages = set() |
| 69 | for letter in (string.ascii_lowercase + string.digits): |
| 70 | # Not all subfolders may exist, so silently handle 404 |
| 71 | try: |
| 72 | packages |= get_source_package_list_from_url(url + "/" + letter, section, d) |
| 73 | except HTTPError as e: |
| 74 | if e.code != 404: raise |
| 75 | return packages |
| 76 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 77 | def get_latest_released_fedora_source_package_list(d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 78 | "Returns list of all the name os packages in the latest fedora distro" |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 79 | latest = find_latest_numeric_release("http://archive.fedoraproject.org/pub/fedora/linux/releases/", d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 80 | package_names = get_source_package_list_from_url_by_letter("http://archive.fedoraproject.org/pub/fedora/linux/releases/%s/Everything/source/tree/Packages/" % latest, "main", d) |
| 81 | package_names |= get_source_package_list_from_url_by_letter("http://archive.fedoraproject.org/pub/fedora/linux/updates/%s/SRPMS/" % latest, "updates", d) |
| 82 | return latest, package_names |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 83 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 84 | def get_latest_released_opensuse_source_package_list(d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 85 | "Returns list of all the name os packages in the latest opensuse distro" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 86 | latest = find_latest_numeric_release("http://download.opensuse.org/source/distribution/leap", d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 87 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 88 | package_names = get_source_package_list_from_url("http://download.opensuse.org/source/distribution/leap/%s/repo/oss/suse/src/" % latest, "main", d) |
| 89 | package_names |= get_source_package_list_from_url("http://download.opensuse.org/update/leap/%s/oss/src/" % latest, "updates", d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 90 | return latest, package_names |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 91 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 92 | def get_latest_released_clear_source_package_list(d): |
| 93 | latest = find_latest_numeric_release("https://download.clearlinux.org/releases/", d) |
| 94 | package_names = get_source_package_list_from_url("https://download.clearlinux.org/releases/%s/clear/source/SRPMS/" % latest, "main", d) |
| 95 | return latest, package_names |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 96 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 97 | def find_latest_debian_release(url, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 98 | "Find the latest listed debian release on the given url" |
| 99 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 100 | releases = [link.replace("Debian", "") |
| 101 | for link in get_links_from_url(url, d) |
| 102 | if link.startswith("Debian")] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 103 | releases.sort() |
| 104 | try: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 105 | return releases[-1] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 106 | except: |
| 107 | return "_NotFound_" |
| 108 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 109 | def get_debian_style_source_package_list(url, section, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 110 | "Return the list of package-names stored in the debian style Sources.gz file" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 111 | import gzip |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 112 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 113 | package_names = set() |
| 114 | for line in gzip.open(create_socket(url, d), mode="rt"): |
| 115 | if line.startswith("Package:"): |
| 116 | pkg = line.split(":", 1)[1].strip() |
| 117 | package_names.add(pkg + ":" + section) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 118 | return package_names |
| 119 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 120 | def get_latest_released_debian_source_package_list(d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 121 | "Returns list of all the name of packages in the latest debian distro" |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 122 | latest = find_latest_debian_release("http://ftp.debian.org/debian/dists/", d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 123 | url = "http://ftp.debian.org/debian/dists/stable/main/source/Sources.gz" |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 124 | package_names = get_debian_style_source_package_list(url, "main", d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 125 | url = "http://ftp.debian.org/debian/dists/stable-proposed-updates/main/source/Sources.gz" |
| 126 | package_names |= get_debian_style_source_package_list(url, "updates", d) |
| 127 | return latest, package_names |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 128 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 129 | def find_latest_ubuntu_release(url, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 130 | """ |
| 131 | Find the latest listed Ubuntu release on the given ubuntu/dists/ URL. |
| 132 | |
| 133 | To avoid matching development releases look for distributions that have |
| 134 | updates, so the resulting distro could be any supported release. |
| 135 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 136 | url += "?C=M;O=D" # Descending Sort by Last Modified |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 137 | for link in get_links_from_url(url, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 138 | if "-updates" in link: |
| 139 | distro = link.replace("-updates", "") |
| 140 | return distro |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 141 | return "_NotFound_" |
| 142 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 143 | def get_latest_released_ubuntu_source_package_list(d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 144 | "Returns list of all the name os packages in the latest ubuntu distro" |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 145 | latest = find_latest_ubuntu_release("http://archive.ubuntu.com/ubuntu/dists/", d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 146 | url = "http://archive.ubuntu.com/ubuntu/dists/%s/main/source/Sources.gz" % latest |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 147 | package_names = get_debian_style_source_package_list(url, "main", d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 148 | url = "http://archive.ubuntu.com/ubuntu/dists/%s-updates/main/source/Sources.gz" % latest |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 149 | package_names |= get_debian_style_source_package_list(url, "updates", d) |
| 150 | return latest, package_names |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 151 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 152 | def create_distro_packages_list(distro_check_dir, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 153 | import shutil |
| 154 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 155 | pkglst_dir = os.path.join(distro_check_dir, "package_lists") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 156 | bb.utils.remove(pkglst_dir, True) |
| 157 | bb.utils.mkdirhier(pkglst_dir) |
| 158 | |
| 159 | per_distro_functions = ( |
| 160 | ("Debian", get_latest_released_debian_source_package_list), |
| 161 | ("Ubuntu", get_latest_released_ubuntu_source_package_list), |
| 162 | ("Fedora", get_latest_released_fedora_source_package_list), |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 163 | ("openSUSE", get_latest_released_opensuse_source_package_list), |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 164 | ("Clear", get_latest_released_clear_source_package_list), |
| 165 | ) |
| 166 | |
| 167 | for name, fetcher_func in per_distro_functions: |
| 168 | try: |
| 169 | release, package_list = fetcher_func(d) |
| 170 | except Exception as e: |
| 171 | bb.warn("Cannot fetch packages for %s: %s" % (name, e)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 172 | bb.note("Distro: %s, Latest Release: %s, # src packages: %d" % (name, release, len(package_list))) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 173 | if len(package_list) == 0: |
| 174 | bb.error("Didn't fetch any packages for %s %s" % (name, release)) |
| 175 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 176 | package_list_file = os.path.join(pkglst_dir, name + "-" + release) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 177 | with open(package_list_file, 'w') as f: |
| 178 | for pkg in sorted(package_list): |
| 179 | f.write(pkg + "\n") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 180 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 181 | def update_distro_data(distro_check_dir, datetime, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 182 | """ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 183 | If distro packages list data is old then rebuild it. |
| 184 | The operations has to be protected by a lock so that |
| 185 | only one thread performes it at a time. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 186 | """ |
| 187 | if not os.path.isdir (distro_check_dir): |
| 188 | try: |
| 189 | bb.note ("Making new directory: %s" % distro_check_dir) |
| 190 | os.makedirs (distro_check_dir) |
| 191 | except OSError: |
| 192 | raise Exception('Unable to create directory %s' % (distro_check_dir)) |
| 193 | |
| 194 | |
| 195 | datetime_file = os.path.join(distro_check_dir, "build_datetime") |
| 196 | saved_datetime = "_invalid_" |
| 197 | import fcntl |
| 198 | try: |
| 199 | if not os.path.exists(datetime_file): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 200 | open(datetime_file, 'w+').close() # touch the file so that the next open won't fail |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 201 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 202 | f = open(datetime_file, "r+") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 203 | fcntl.lockf(f, fcntl.LOCK_EX) |
| 204 | saved_datetime = f.read() |
| 205 | if saved_datetime[0:8] != datetime[0:8]: |
| 206 | bb.note("The build datetime did not match: saved:%s current:%s" % (saved_datetime, datetime)) |
| 207 | bb.note("Regenerating distro package lists") |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 208 | create_distro_packages_list(distro_check_dir, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 209 | f.seek(0) |
| 210 | f.write(datetime) |
| 211 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 212 | except OSError as e: |
| 213 | raise Exception('Unable to open timestamp: %s' % e) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 214 | finally: |
| 215 | fcntl.lockf(f, fcntl.LOCK_UN) |
| 216 | f.close() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 217 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 218 | def compare_in_distro_packages_list(distro_check_dir, d): |
| 219 | if not os.path.isdir(distro_check_dir): |
| 220 | raise Exception("compare_in_distro_packages_list: invalid distro_check_dir passed") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 221 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 222 | localdata = bb.data.createCopy(d) |
| 223 | pkglst_dir = os.path.join(distro_check_dir, "package_lists") |
| 224 | matching_distros = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 225 | pn = recipe_name = d.getVar('PN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 226 | bb.note("Checking: %s" % pn) |
| 227 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 228 | if pn.find("-native") != -1: |
| 229 | pnstripped = pn.split("-native") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 230 | localdata.setVar('OVERRIDES', "pn-" + pnstripped[0] + ":" + d.getVar('OVERRIDES')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 231 | recipe_name = pnstripped[0] |
| 232 | |
| 233 | if pn.startswith("nativesdk-"): |
| 234 | pnstripped = pn.split("nativesdk-") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 235 | localdata.setVar('OVERRIDES', "pn-" + pnstripped[1] + ":" + d.getVar('OVERRIDES')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 236 | recipe_name = pnstripped[1] |
| 237 | |
| 238 | if pn.find("-cross") != -1: |
| 239 | pnstripped = pn.split("-cross") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 240 | localdata.setVar('OVERRIDES', "pn-" + pnstripped[0] + ":" + d.getVar('OVERRIDES')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 241 | recipe_name = pnstripped[0] |
| 242 | |
| 243 | if pn.find("-initial") != -1: |
| 244 | pnstripped = pn.split("-initial") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 245 | localdata.setVar('OVERRIDES', "pn-" + pnstripped[0] + ":" + d.getVar('OVERRIDES')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 246 | recipe_name = pnstripped[0] |
| 247 | |
| 248 | bb.note("Recipe: %s" % recipe_name) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 249 | |
| 250 | distro_exceptions = dict({"OE-Core":'OE-Core', "OpenedHand":'OpenedHand', "Intel":'Intel', "Upstream":'Upstream', "Windriver":'Windriver', "OSPDT":'OSPDT Approved', "Poky":'poky'}) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 251 | tmp = localdata.getVar('DISTRO_PN_ALIAS') or "" |
| 252 | for str in tmp.split(): |
| 253 | if str and str.find("=") == -1 and distro_exceptions[str]: |
| 254 | matching_distros.append(str) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 255 | |
| 256 | distro_pn_aliases = {} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 257 | for str in tmp.split(): |
| 258 | if "=" in str: |
| 259 | (dist, pn_alias) = str.split('=') |
| 260 | distro_pn_aliases[dist.strip().lower()] = pn_alias.strip() |
| 261 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 262 | for file in os.listdir(pkglst_dir): |
| 263 | (distro, distro_release) = file.split("-") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 264 | f = open(os.path.join(pkglst_dir, file), "r") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 265 | for line in f: |
| 266 | (pkg, section) = line.split(":") |
| 267 | if distro.lower() in distro_pn_aliases: |
| 268 | pn = distro_pn_aliases[distro.lower()] |
| 269 | else: |
| 270 | pn = recipe_name |
| 271 | if pn == pkg: |
| 272 | matching_distros.append(distro + "-" + section[:-1]) # strip the \n at the end |
| 273 | f.close() |
| 274 | break |
| 275 | f.close() |
| 276 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 277 | for item in tmp.split(): |
| 278 | matching_distros.append(item) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 279 | bb.note("Matching: %s" % matching_distros) |
| 280 | return matching_distros |
| 281 | |
| 282 | def create_log_file(d, logname): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 283 | logpath = d.getVar('LOG_DIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 284 | bb.utils.mkdirhier(logpath) |
| 285 | logfn, logsuffix = os.path.splitext(logname) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 286 | logfile = os.path.join(logpath, "%s.%s%s" % (logfn, d.getVar('DATETIME'), logsuffix)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 287 | if not os.path.exists(logfile): |
| 288 | slogfile = os.path.join(logpath, logname) |
| 289 | if os.path.exists(slogfile): |
| 290 | os.remove(slogfile) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 291 | open(logfile, 'w+').close() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 292 | os.symlink(logfile, slogfile) |
| 293 | d.setVar('LOG_FILE', logfile) |
| 294 | return logfile |
| 295 | |
| 296 | |
| 297 | def save_distro_check_result(result, datetime, result_file, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 298 | pn = d.getVar('PN') |
| 299 | logdir = d.getVar('LOG_DIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 300 | if not logdir: |
| 301 | bb.error("LOG_DIR variable is not defined, can't write the distro_check results") |
| 302 | return |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 303 | bb.utils.mkdirhier(logdir) |
| 304 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 305 | line = pn |
| 306 | for i in result: |
| 307 | line = line + "," + i |
| 308 | f = open(result_file, "a") |
| 309 | import fcntl |
| 310 | fcntl.lockf(f, fcntl.LOCK_EX) |
| 311 | f.seek(0, os.SEEK_END) # seek to the end of file |
| 312 | f.write(line + "\n") |
| 313 | fcntl.lockf(f, fcntl.LOCK_UN) |
| 314 | f.close() |