Skip to content

Commit fb2937f

Browse files
committed
Updated CI scripts
1 parent de86447 commit fb2937f

File tree

1 file changed

+77
-24
lines changed

1 file changed

+77
-24
lines changed

ci/build-tool

Lines changed: 77 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import time
4343
import urllib.error
4444
import urllib.request
4545

46-
from typing import Any, Final, TextIO
46+
from typing import Any, Final, TextIO, cast
4747

4848

4949
# ###########################################################################
@@ -781,7 +781,7 @@ def getDistributionCodenames(distribution : str = 'debian') -> list[str]:
781781
else:
782782
distroInfo = 'ubuntu-distro-info'
783783
try:
784-
process : subprocess.Popen = \
784+
process : subprocess.Popen[str] = \
785785
subprocess.Popen([ distroInfo, '--all'],
786786
stdout=subprocess.PIPE, universal_newlines=True)
787787
assert process is not None
@@ -805,7 +805,7 @@ def getDistributionCodenames(distribution : str = 'debian') -> list[str]:
805805
# ###### Get Debian default architecture ####################################
806806
def getDebianDefaultArchitecture() -> str:
807807
try:
808-
process : subprocess.Popen = \
808+
process : subprocess.Popen[str] = \
809809
subprocess.Popen([ 'dpkg', '--print-architecture'],
810810
stdout=subprocess.PIPE, universal_newlines=True)
811811
assert process is not None
@@ -879,8 +879,8 @@ def getDebianControlTarballName(packageInfo : dict[str,Any],
879879

880880

881881
# ###### Fetch Debian changelog file ########################################
882-
def fetchDebianChangelog(packageInfo : dict[str,Any],
883-
codename : str = 'unstable') -> list[str] | None:
882+
def fetchDebianChangelogAndControl(packageInfo : dict[str,Any],
883+
codename : str = 'unstable') -> tuple[list[str] | None, list[str] | None]:
884884
if not hasPackagingFor(packageInfo, 'debian'):
885885
sys.stderr.write('ERROR: Cannot find required Debian packaging information!\n')
886886
sys.exit(1)
@@ -963,7 +963,7 @@ def fetchDebianChangelog(packageInfo : dict[str,Any],
963963

964964
if debianNoSuchPackage == True:
965965
sys.stderr.write('not in Debian!\n')
966-
return None
966+
return (None, None)
967967

968968
if ( (debianVersion is None) or (debianLocation is None) or (debianArchive is None) ):
969969
sys.stderr.write('ERROR: Unable to determinate package status in Debian (https://packages.ubuntu.com/ may be malfunctioning)!\n')
@@ -978,36 +978,48 @@ def fetchDebianChangelog(packageInfo : dict[str,Any],
978978

979979

980980
# ====== Fetch debian archive ===============================================
981-
archiveFileURL : Final[str] = debianLocation + debianArchive
982-
result : list[str] | None = None
981+
archiveFileURL : Final[str] = debianLocation + debianArchive
982+
result : tuple[list[str] | None,list[str] | None] = (None, None)
983983
sys.stderr.write('Looking for \"debian\" archive at ' + archiveFileURL + ' ... ')
984984
sys.stderr.flush()
985985
try:
986-
archiveFileRequest : urllib.request.Request = urllib.request.Request(archiveFileURL,
987-
headers = httpHeders)
988-
archiveFile : http.client.HTTPResponse = urllib.request.urlopen(archiveFileRequest)
989-
debianArchiveFile : tempfile._TemporaryFileWrapper = tempfile.NamedTemporaryFile(delete = False)
986+
archiveFileRequest : urllib.request.Request = urllib.request.Request(archiveFileURL,
987+
headers = httpHeders)
988+
archiveFile : http.client.HTTPResponse = urllib.request.urlopen(archiveFileRequest)
989+
debianArchiveFile : tempfile._TemporaryFileWrapper[bytes] = \
990+
tempfile.NamedTemporaryFile(delete = False)
990991

991-
shutil.copyfileobj(archiveFile, debianArchiveFile)
992+
shutil.copyfileobj(cast(TextIO, archiveFile), debianArchiveFile)
992993
debianArchiveFile.close()
993994
archiveFile.close()
994995
sys.stderr.write('found!\n')
995996

997+
debianChangelog : list[str] = [ ]
998+
debianControl : list[str] = [ ]
996999
try:
997-
process : subprocess.Popen = \
1000+
# ------ Extract debian/changelog ----------------------------------
1001+
process : subprocess.Popen[str] = \
9981002
subprocess.Popen([ 'tar', 'x' + tarCompressionOption + 'fO', debianArchiveFile.name, 'debian/changelog'],
9991003
stdout=subprocess.PIPE, universal_newlines=True)
10001004
if ( (process is not None) and (process.stdout is not None) ):
1001-
result = process.stdout.readlines()
1005+
debianChangelog = process.stdout.readlines()
1006+
1007+
# ------ Extract debian/control ------------------------------------
1008+
process = \
1009+
subprocess.Popen([ 'tar', 'x' + tarCompressionOption + 'fO', debianArchiveFile.name, 'debian/control'],
1010+
stdout=subprocess.PIPE, universal_newlines=True)
1011+
if ( (process is not None) and (process.stdout is not None) ):
1012+
debianControl = process.stdout.readlines()
1013+
10021014
os.unlink(debianArchiveFile.name)
1015+
result = (debianChangelog, debianControl)
10031016

10041017
except Exception as e:
10051018
sys.stderr.write('ERROR: Failed to extract debian/changelog from ' + debianArchiveFile.name + ': ' + str(e) + '\n')
10061019
sys.exit(1)
10071020

10081021
except urllib.error.HTTPError as e:
10091022
sys.stderr.write('not found (HTTP ' + str(e.code) + ')!\n')
1010-
return None
10111023

10121024
return result
10131025

@@ -1212,6 +1224,7 @@ def makeSourceDeb(packageInfo : dict[str,Any],
12121224
re_launchpad : Final[re.Pattern[str]] = re.compile(r'^.*\(LP: #[0-9]+')
12131225
re_dhcompat : Final[re.Pattern[str]] = re.compile(r'^(Build-Depends:[ \t]*|[ \t]*)(debhelper-compat \(= [0-9]+\))(.*)$')
12141226
re_parallel : Final[re.Pattern[str]] = re.compile(r' --parallel')
1227+
re_vcs : Final[re.Pattern[str]] = re.compile(r'^(Vcs-[a-zA-Z]+)(:[ t]*)(.*)$')
12151228

12161229
printSection('Creating source Debian packages')
12171230

@@ -1282,9 +1295,10 @@ def makeSourceDeb(packageInfo : dict[str,Any],
12821295

12831296

12841297
# ====== Adapt packaging ==============================================
1285-
changeLogContents : list[str] = readTextFile(packageInfo['debian_changelog_name'])
1286-
controlContents : list[str] = readTextFile(packageInfo['debian_control_name'])
1287-
rulesContents : list[str] = readTextFile(packageInfo['debian_rules_name'])
1298+
changeLogContents : list[str] = readTextFile(packageInfo['debian_changelog_name'])
1299+
controlContents : list[str] = readTextFile(packageInfo['debian_control_name'])
1300+
rulesContents : list[str] = readTextFile(packageInfo['debian_rules_name'])
1301+
upstreamControlContents : list[str] | None = None
12881302

12891303
newDebianVersionPackaging : str = modifyDebianVersionPackaging(packageInfo, codename)
12901304
sys.stdout.write('Modifying packaging version from ' + \
@@ -1307,15 +1321,49 @@ def makeSourceDeb(packageInfo : dict[str,Any],
13071321
changeLogContents = \
13081322
[ line for line in changeLogContents if not re_launchpad.match(line) ]
13091323

1310-
# ------ Fetch distributor's latest changelog ----------------------
1311-
distributorChangelogContents = fetchDebianChangelog(packageInfo, codename)
1324+
# ------ Fetch distributor's latest changelog and control file -----
1325+
distributorChangelogContents, distributorControlContents = \
1326+
fetchDebianChangelogAndControl(packageInfo, codename)
1327+
1328+
# ------ Update debian/changelog -----------------------------------
13121329
if distributorChangelogContents is not None:
13131330
# Merge new entries from changelog into a single entry, and append
13141331
# the distributor's changelog with the rest:
1315-
changeLogContents = mergeDebianChangelogs(changeLogContents, distributorChangelogContents)
1332+
changeLogContents = \
1333+
mergeDebianChangelogs(changeLogContents, distributorChangelogContents)
13161334

13171335
changeLogContents = filterDebianChangelog(changeLogContents)
13181336

1337+
# ------ Update debian/control -------------------------------------
1338+
if distributorControlContents is not None:
1339+
# Find Vcs-* defined by distributor:
1340+
vcsGit : str | None = None
1341+
vcsBrowser : str | None = None
1342+
for line in distributorControlContents:
1343+
match : re.Match[str] | None = re_vcs.match(line)
1344+
if match:
1345+
if match.group(1) == 'Vcs-Git':
1346+
vcsGit = match.group(3)
1347+
elif match.group(1) == 'Vcs-Browser':
1348+
vcsBrowser = match.group(3)
1349+
1350+
# Replace Vcs-* with versions from distributor:
1351+
if ( (vcsGit is not None) or (vcsBrowser is not None) ):
1352+
for i in range(0, len(controlContents)):
1353+
match = re_vcs.match(controlContents[i])
1354+
if match:
1355+
if vcsGit is not None:
1356+
controlContents[i] = re.sub(r'^Vcs-Git:.*$', 'Vcs-Git: ' + vcsGit, controlContents[i])
1357+
if vcsBrowser is not None:
1358+
controlContents[i] = re.sub(r'^Vcs-Browser:.*$', 'Vcs-Browser: ' + vcsBrowser, controlContents[i])
1359+
else:
1360+
# No distributor Vcs-* fields -> remove them!
1361+
controlContents = \
1362+
[ line for line in controlContents if not re_vcs.match(line) ]
1363+
else:
1364+
controlContents = \
1365+
[ line for line in controlContents if not re_vcs.match(line) ]
1366+
13191367
# ------- Ubuntu ------------------------------------------------------
13201368
else:
13211369
# ------ Translate Debian debhelper configuration to Ubuntu --------
@@ -1325,7 +1373,7 @@ def makeSourceDeb(packageInfo : dict[str,Any],
13251373
if codename in DebhelperCompatFixes:
13261374
dhcompatVersion : int = DebhelperCompatFixes[codename]
13271375
for i in range(0, len(controlContents)):
1328-
match : re.Match[str] | None = re_dhcompat.match(controlContents[i])
1376+
match = re_dhcompat.match(controlContents[i])
13291377
if match:
13301378
controlContents[i] = match.group(1) + \
13311379
'debhelper (>= ' + str(dhcompatVersion) + ')' + \
@@ -1353,6 +1401,10 @@ def makeSourceDeb(packageInfo : dict[str,Any],
13531401
writeTextFile(upstreamSourceDir + '/debian/control', controlContents)
13541402
writeTextFile(upstreamSourceDir + '/debian/rules', rulesContents)
13551403

1404+
# print(upstreamSourceDir + '/debian/changelog')
1405+
# print(upstreamSourceDir + '/debian/control')
1406+
# sys.exit(2)
1407+
13561408
sys.stdout.write('Updated Debian changelog:\n')
13571409
showDiff(packageInfo['debian_changelog_name'], upstreamSourceDir + '/debian/changelog')
13581410
sys.stdout.write('Updated Debian control:\n')
@@ -1962,7 +2014,8 @@ elif tool == 'fetch-debian-changelog':
19622014
codename : str = 'unstable'
19632015
if len(sys.argv) >= 3:
19642016
codename = sys.argv[2]
1965-
changelogContents : list[str] | None = fetchDebianChangelog(packageInfo, codename)
2017+
changelogContents, controlContents = \
2018+
fetchDebianChangelogAndControl(packageInfo, codename)
19662019
if changelogContents is not None:
19672020
sys.stdout.write('\n')
19682021
for line in changelogContents:

0 commit comments

Comments
 (0)