initial commit
This commit is contained in:
commit
a66ca12afb
3 changed files with 262 additions and 0 deletions
99
daklib_arch.py
Normal file
99
daklib_arch.py
Normal file
|
@ -0,0 +1,99 @@
|
|||
"""architecture matching
|
||||
|
||||
@copyright: 2014, Ansgar Burchardt <ansgar@debian.org>
|
||||
@license: GPL-2+
|
||||
"""
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
def _load_table(path):
|
||||
table = []
|
||||
with open(path, 'r') as fh:
|
||||
for line in fh:
|
||||
if not line or line.startswith('#'):
|
||||
continue
|
||||
table.append(line.split())
|
||||
return table
|
||||
|
||||
_cached_cputable = None
|
||||
def _cputable():
|
||||
global _cached_cputable
|
||||
if _cached_cputable is None:
|
||||
_cached_cputable = _load_table('/usr/share/dpkg/cputable')
|
||||
return _cached_cputable
|
||||
|
||||
_cached_arch2triplet = None
|
||||
_cached_triplet2arch = None
|
||||
def _triplettable():
|
||||
global _cached_arch2triplet, _cached_triplet2arch
|
||||
if _cached_arch2triplet is None or _cached_triplet2arch is None:
|
||||
table = _load_table('/usr/share/dpkg/triplettable')
|
||||
arch2triplet = {}
|
||||
triplet2arch = {}
|
||||
for row in table:
|
||||
if '<cpu>' in row[0] or '<cpu>' in row[1]:
|
||||
for cpu in _cputable():
|
||||
replaced_row = [ column.replace('<cpu>', cpu[0]) for column in row ]
|
||||
arch2triplet[replaced_row[1]] = replaced_row[0]
|
||||
triplet2arch[replaced_row[0]] = replaced_row[1]
|
||||
else:
|
||||
arch2triplet[row[1]] = row[0]
|
||||
triplet2arch[row[0]] = row[1]
|
||||
_cached_arch2triplet = arch2triplet
|
||||
_cached_triplet2arch = triplet2arch
|
||||
return _cached_triplet2arch, _cached_arch2triplet
|
||||
|
||||
class InvalidArchitecture(Exception):
|
||||
pass
|
||||
|
||||
def Debian_arch_to_Debian_triplet(arch):
|
||||
parts = arch.split('-')
|
||||
|
||||
# Handle architecture wildcards
|
||||
if 'any' in parts:
|
||||
if len(parts) == 3:
|
||||
return parts
|
||||
elif len(parts) == 2:
|
||||
return 'any', parts[0], parts[1]
|
||||
else:
|
||||
return 'any', 'any', 'any'
|
||||
|
||||
if len(parts) == 2 and parts[0] == 'linux':
|
||||
arch = parts[1]
|
||||
|
||||
triplet = _triplettable()[1].get(arch, None)
|
||||
if triplet is None:
|
||||
return None
|
||||
return triplet.split('-', 2)
|
||||
|
||||
def match_architecture(arch, wildcard):
|
||||
# 'all' has no valid triplet
|
||||
if arch == 'all' or wildcard == 'all':
|
||||
return arch == wildcard
|
||||
if wildcard is 'any' or arch == wildcard:
|
||||
return True
|
||||
|
||||
triplet_arch = Debian_arch_to_Debian_triplet(arch)
|
||||
triplet_wildcard = Debian_arch_to_Debian_triplet(wildcard)
|
||||
|
||||
if triplet_arch is None or len(triplet_arch) != 3:
|
||||
raise InvalidArchitecture('{0} is not a valid architecture name'.format(arch))
|
||||
if triplet_wildcard is None or len(triplet_wildcard) != 3:
|
||||
raise InvalidArchitecture('{0} is not a valid architecture name or wildcard'.format(wildcard))
|
||||
|
||||
for i in range(0,3):
|
||||
if triplet_arch[i] != triplet_wildcard[i] and triplet_wildcard[i] != 'any':
|
||||
return False
|
||||
return True
|
100
debarch.py
Normal file
100
debarch.py
Normal file
|
@ -0,0 +1,100 @@
|
|||
"""architecture matching
|
||||
|
||||
@copyright: 2014, Ansgar Burchardt <ansgar@debian.org>
|
||||
@copyright: 2014, Johannes Schauer <j.schauer@email.de>
|
||||
@license: GPL-2+
|
||||
"""
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
_cached_arch2triplet = None
|
||||
_cached_triplet2arch = None
|
||||
_cached_cputable = None
|
||||
|
||||
def _load_table(path):
|
||||
table = []
|
||||
with open(path, "r") as f:
|
||||
for line in f:
|
||||
if not line or line.startswith('#'):
|
||||
continue
|
||||
table.append(line.split())
|
||||
return table
|
||||
|
||||
def _read_cputable():
|
||||
global _cached_cputable
|
||||
if _cached_cputable is None:
|
||||
_cached_cputable = _load_table('/usr/share/dpkg/cputable')
|
||||
return _cached_cputable
|
||||
|
||||
def _read_triplettable():
|
||||
global _cached_arch2triplet, _cached_triplet2arch
|
||||
if _cached_arch2triplet is None or _cached_triplet2arch is None:
|
||||
table = _load_table('/usr/share/dpkg/triplettable')
|
||||
arch2triplet = dict()
|
||||
triplet2arch = dict()
|
||||
for row in table:
|
||||
debtriplet = row[0]
|
||||
debarch = row[1]
|
||||
if '<cpu>' in debtriplet:
|
||||
for r in _read_cputable():
|
||||
cpu = r[0]
|
||||
dt = debtriplet.replace('<cpu>', cpu)
|
||||
da = debarch.replace('<cpu>', cpu)
|
||||
arch2triplet[da] = dt
|
||||
triplet2arch[dt] = da
|
||||
else:
|
||||
arch2triplet[debarch] = debtriplet
|
||||
triplet2arch[debtriplet] = debarch
|
||||
_cached_arch2triplet = arch2triplet
|
||||
_cached_triplet2arch = triplet2arch
|
||||
return _cached_triplet2arch, _cached_arch2triplet
|
||||
|
||||
def debwildcard_to_debtriplet(arch):
|
||||
arch_tuple = arch.split('-', 2)
|
||||
|
||||
if 'any' in arch_tuple:
|
||||
if len(arch_tuple) == 3:
|
||||
return arch_tuple
|
||||
elif len(arch_tuple) == 2:
|
||||
return ('any', arch_tuple[0], arch_tuple[1])
|
||||
else:
|
||||
return ('any', 'any', 'any')
|
||||
else:
|
||||
return debarch_to_debtriplet(arch)
|
||||
|
||||
def debarch_to_debtriplet(arch):
|
||||
if (arch.startswith("linux-")):
|
||||
arch = arch[6:]
|
||||
|
||||
triplet = _read_triplettable()[1].get(arch)
|
||||
|
||||
if triplet is None:
|
||||
return
|
||||
return triplet.split('-', 2)
|
||||
|
||||
def match_architecture(real, alias):
|
||||
if alias == real or alias == "any":
|
||||
return True
|
||||
|
||||
real = debarch_to_debtriplet(real)
|
||||
alias = debwildcard_to_debtriplet(alias)
|
||||
|
||||
if real is None or len(real) != 3 or alias is None or len(alias) != 3:
|
||||
return False
|
||||
|
||||
for i in range(0,3):
|
||||
if (alias[i] != real[i] and alias[i] != "any"):
|
||||
return False
|
||||
return True
|
63
run.py
Executable file
63
run.py
Executable file
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import subprocess
|
||||
import yaml
|
||||
import daklib_arch
|
||||
import debarch
|
||||
|
||||
os_list = []
|
||||
|
||||
os_list = set([row[0].split('-')[1] for row in debarch._load_table('/usr/share/dpkg/ostable')])
|
||||
|
||||
cpu_list = set([row[0] for row in debarch._load_table('/usr/share/dpkg/cputable')])
|
||||
|
||||
wildcard_list = [ o + "-" + c for o in os_list for c in cpu_list]
|
||||
|
||||
deb_list = subprocess.check_output(["dpkg-architecture", "-L"]).decode().split()
|
||||
|
||||
def dpkg_arch_matches(arch, wildcard):
|
||||
# environment must be empty or otherwise the DEB_HOST_ARCH environment
|
||||
# variable will influence the result
|
||||
return subprocess.call(
|
||||
['dpkg-architecture', '-i%s' % wildcard, '-a%s' % arch],
|
||||
env={}) == 0
|
||||
|
||||
def dose_arch_matches(arch, wildcard):
|
||||
with open("/tmp/sources", "w") as f:
|
||||
f.write("""
|
||||
Package: foo
|
||||
Architecture: %s
|
||||
Version: 0.invalid.0
|
||||
"""%(wildcard))
|
||||
with open("/tmp/packages", "w") as f:
|
||||
f.write("""
|
||||
Package: build-essential
|
||||
Architecture: %s
|
||||
Version: 0.invalid.0
|
||||
"""%(arch))
|
||||
data = subprocess.check_output(['dose-builddebcheck', '--deb-native-arch=%s'%arch,
|
||||
'--successes', '/tmp/packages', '/tmp/sources'])
|
||||
data = yaml.load(data, Loader=yaml.CBaseLoader)
|
||||
return len(data['report']) == 1
|
||||
|
||||
check_pairs = [ (d,w) for d in deb_list for w in wildcard_list ]
|
||||
len_check_pairs = len(check_pairs)
|
||||
|
||||
print("checking %d testcases"%len_check_pairs)
|
||||
|
||||
for i,(d,w) in enumerate(check_pairs):
|
||||
print("\r%f"%((i*100)/len_check_pairs), end="")
|
||||
dose_res = dose_arch_matches(d, w)
|
||||
dpkg_res = dpkg_arch_matches(d, w)
|
||||
try:
|
||||
dak_res = daklib_arch.match_architecture(d, w)
|
||||
except daklib_arch.InvalidArchitecture:
|
||||
dak_res = False
|
||||
deb_res = debarch.match_architecture(d,w)
|
||||
if dose_res != dpkg_res or dose_res != dak_res \
|
||||
or dose_res != deb_res:
|
||||
print("difference!")
|
||||
print("dose: %s matches %s: %s"%(w,d,dose_res))
|
||||
print("dpkg: %s matches %s: %s"%(w,d,dpkg_res))
|
||||
print("deb: %s matches %s: %s"%(w,d,deb_res))
|
||||
print("dak: %s matches %s: %s"%(w,d,dak_res))
|
Loading…
Reference in a new issue