From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id CC7E2139084 for ; Thu, 28 Dec 2017 13:43:55 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B9C6FE0E98; Thu, 28 Dec 2017 13:43:54 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 8B220E0E98 for ; Thu, 28 Dec 2017 13:43:53 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 20EE5340AFC for ; Thu, 28 Dec 2017 13:43:52 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id AE533AFBE for ; Thu, 28 Dec 2017 13:43:50 +0000 (UTC) From: "Michael Palimaka" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michael Palimaka" Message-ID: <1514468618.a050ce84b3cf99236a8d452c4688d5d5b69bc1ea.kensington@gentoo> Subject: [gentoo-commits] proj/kde:master commit in: Documentation/maintainers/ X-VCS-Repository: proj/kde X-VCS-Files: Documentation/maintainers/cmake_ebuild_check.py X-VCS-Directories: Documentation/maintainers/ X-VCS-Committer: kensington X-VCS-Committer-Name: Michael Palimaka X-VCS-Revision: a050ce84b3cf99236a8d452c4688d5d5b69bc1ea X-VCS-Branch: master Date: Thu, 28 Dec 2017 13:43:50 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 4214e025-ce8c-4ed6-b5bc-3b046536359c X-Archives-Hash: 6ebb78e7e32bde7bb3a2dd09a41ff633 commit: a050ce84b3cf99236a8d452c4688d5d5b69bc1ea Author: Michael Palimaka gentoo org> AuthorDate: Thu Dec 28 13:42:59 2017 +0000 Commit: Michael Palimaka gentoo org> CommitDate: Thu Dec 28 13:43:38 2017 +0000 URL: https://gitweb.gentoo.org/proj/kde.git/commit/?id=a050ce84 Documentation: add script to compare CMakeLists and ebuild dependencies Documentation/maintainers/cmake_ebuild_check.py | 146 ++++++++++++++++++++++++ 1 file changed, 146 insertions(+) diff --git a/Documentation/maintainers/cmake_ebuild_check.py b/Documentation/maintainers/cmake_ebuild_check.py new file mode 100755 index 0000000000..27786cf4cb --- /dev/null +++ b/Documentation/maintainers/cmake_ebuild_check.py @@ -0,0 +1,146 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2017 Michael Palimaka +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +import argparse +import os +import sys +import subprocess +import cmake_dep_check as cdc +import portage + + +def qatom(atom): + output = subprocess.check_output(['qatom', '--format', '%{CATEGORY}|%{PN}|%{PV}|%[PR]|%[SLOT]|%[pfx]|%[sfx]', atom]) + return output.decode('utf-8').split('|') + + +def get_cmake_deps(ebuild, repo): + cpv = qatom(ebuild) + settings = portage.config(config_root='/') + + tmpdir = os.path.join(settings.get('PORTAGE_TMPDIR'), 'portage') + tmp_path = os.path.join(tmpdir, cpv[0], cpv[1] + '-' + cpv[2]) + repo_path = portage.db['/']["vartree"].settings.repositories.treemap.get(repo) + ebuild_path = os.path.join(repo_path, cpv[0], cpv[1], cpv[1] + '-' + cpv[2] + '.ebuild') + + subprocess.call(['ebuild', ebuild_path, 'clean', 'prepare'], stdout=subprocess.DEVNULL) + + deps = cdc.getDeps(os.path.join(tmp_path)) + + subprocess.call(['ebuild', ebuild_path, 'clean']) + + return deps + + +def get_ebuild_deps(ebuild): + porttree = portage.db[portage.root]['porttree'] + depstr = porttree.dbapi.aux_get(ebuild, ['DEPEND', 'RDEPEND', 'PDEPEND']) + + depend = portage.dep.use_reduce(depstr[0], matchall=True, flat=True) + rdepend = portage.dep.use_reduce(depstr[1], matchall=True, flat=True) + pdepend = portage.dep.use_reduce(depstr[2], matchall=True, flat=True) + + all_depend = set(depend + rdepend + pdepend) + + return(all_depend) + + +def get_ebuild_repo(ebuild): + porttree = portage.db[portage.root]['porttree'] + repo = porttree.dbapi.aux_get(ebuild, ['repository']) + + return repo[0] + + +def clean_dep(dep): + if dep.startswith('!') or dep == '||': + return False + + parts = qatom(dep) + cp = parts[0] + '/' + parts[1] + + return cp + + +def main(): + parser = argparse.ArgumentParser(description='Compare CMakeLists.txt and ebuild dependencies') + parser.add_argument('ebuild', help='app-foo/bar-1.2.3', nargs=1) + parser.add_argument('--possible-bogus-ebuild', dest='bogusebuild', action='store_const', const=True, help='Show dependencies that appear in CMakeLists.txt but not the ebuild') + + args = parser.parse_args() + + ebuild = args.ebuild[0] + + ebuild_deps = get_ebuild_deps(ebuild) + cmake_deps = get_cmake_deps(ebuild, get_ebuild_repo(ebuild)) + + cmake_deps_merged = [] + + for cmake, deps in cmake_deps.items(): + for dep in deps: + if dep.startswith('ERROR'): + print(dep) + continue + if len(dep) == 0: + continue + clean = clean_dep(dep) + if clean: + cmake_deps_merged.append(clean) + + ebuild_deps_clean = [] + + for dep in ebuild_deps: + clean = clean_dep(dep) + if clean: + ebuild_deps_clean.append(clean) + + missing_cmake = [] + missing_ebuild = [] + + for dep in cmake_deps_merged: + if dep not in ebuild_deps_clean: + missing_ebuild.append(dep) + + for dep in ebuild_deps_clean: + if dep not in cmake_deps_merged: + missing_cmake.append(dep) + + missing_cmake = sorted(set(missing_cmake)) + missing_ebuild = sorted(set(missing_ebuild)) + + if len(missing_ebuild) > 0: + print('DEPENDENCIES IN CMAKELISTS BUT NOT EBUILD:') + print('==========================================') + for dep in missing_ebuild: + print(dep) + else: + print('Did not find any dependencies in CMakeLists that do not appear in the ebuild') + + if len(missing_cmake) > 0 and args.bogusebuild is True: + print('DEPENDENCIES IN EBUILD BUT NOT IN CMAKELISTS:') + print('=============================================') + for dep in missing_cmake: + print(dep) + + +if __name__ == '__main__': + sys.exit(main())