mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
change from dictionary to list-based for patching script
this guarantees that publication happens in order.
This commit is contained in:
parent
fc14af1de1
commit
11eadf8ea8
1 changed files with 57 additions and 43 deletions
100
publish.py
100
publish.py
|
|
@ -5,24 +5,26 @@ import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
# format is {crate : path}
|
# format is [crate : path]
|
||||||
CRATES = {
|
# this is an ordered list that also prescribes the publication order to crates.io
|
||||||
"xous" : "xous-rs",
|
UTRA_CRATES = [
|
||||||
"xous-kernel" : "kernel",
|
["svd2utra", "svd2utra"],
|
||||||
"xous-ipc" : "xous-ipc",
|
["utralib", "utralib"],
|
||||||
"xous-api-log" : "api/xous-api-log",
|
]
|
||||||
"xous-api-names" : "api/xous-api-names",
|
CRATES = [
|
||||||
"xous-api-susres" : "api/xous-api-susres",
|
["xous", "xous-rs"],
|
||||||
"xous-api-ticktimer" : "api/xous-api-ticktimer",
|
["xous-kernel", "kernel"],
|
||||||
"xous-log" : "services/xous-log",
|
["xous-ipc", "xous-ipc"],
|
||||||
"xous-names" : "services/xous-names",
|
["xous-api-log", "api/xous-api-log"],
|
||||||
"xous-susres" : "services/xous-susres",
|
["xous-api-names", "api/xous-api-names"],
|
||||||
"xous-ticktimer" : "services/xous-ticktimer",
|
["xous-api-susres", "api/xous-api-susres"],
|
||||||
}
|
["xous-api-ticktimer", "api/xous-api-ticktimer"],
|
||||||
UTRA_CRATES = {
|
["xous-log", "services/xous-log"],
|
||||||
"svd2utra" : "svd2utra",
|
["xous-names", "services/xous-names"],
|
||||||
"utralib" : "utralib",
|
["xous-susres", "services/xous-susres"],
|
||||||
}
|
["xous-ticktimer", "services/xous-ticktimer"],
|
||||||
|
]
|
||||||
|
# dictionary of crate names -> version strings
|
||||||
VERSIONS = {}
|
VERSIONS = {}
|
||||||
|
|
||||||
class PatchInfo:
|
class PatchInfo:
|
||||||
|
|
@ -32,6 +34,7 @@ class PatchInfo:
|
||||||
print("Bad crate path: {}".format(filename))
|
print("Bad crate path: {}".format(filename))
|
||||||
self.cratename = cratename
|
self.cratename = cratename
|
||||||
self.cratelist = cratelist
|
self.cratelist = cratelist
|
||||||
|
self.debug = False
|
||||||
|
|
||||||
def get_version(self):
|
def get_version(self):
|
||||||
with open(self.filepath, 'r') as file:
|
with open(self.filepath, 'r') as file:
|
||||||
|
|
@ -50,21 +53,32 @@ class PatchInfo:
|
||||||
version = line.split('=')[1].replace('"', '').strip()
|
version = line.split('=')[1].replace('"', '').strip()
|
||||||
if line.strip().startswith('name'):
|
if line.strip().startswith('name'):
|
||||||
name = line.split('=')[1].replace('"', '').strip()
|
name = line.split('=')[1].replace('"', '').strip()
|
||||||
if name in self.cratelist:
|
for [item_name, path] in self.cratelist:
|
||||||
name_check = True
|
if name == item_name:
|
||||||
|
name_check = True
|
||||||
if name_check:
|
if name_check:
|
||||||
assert version is not None # "Target name found but no version was extracted!"
|
assert version is not None # "Target name found but no version was extracted!"
|
||||||
VERSIONS[name] = version
|
VERSIONS[name] = version
|
||||||
|
|
||||||
return name_check
|
return name_check
|
||||||
|
|
||||||
|
def debug_mode(self, arg):
|
||||||
|
self.debug = arg
|
||||||
|
|
||||||
|
def output(self, line):
|
||||||
|
if self.debug:
|
||||||
|
print("Dry run: {}".format(line.rstrip()))
|
||||||
|
else:
|
||||||
|
self.file.write(line)
|
||||||
|
|
||||||
# assumes that VERSIONS has been initialized.
|
# assumes that VERSIONS has been initialized.
|
||||||
def increment_versions(self):
|
def increment_versions(self):
|
||||||
# check that global variables are in sane states
|
# check that global variables are in sane states
|
||||||
assert len(VERSIONS) > 0 # "No VERSIONS found, something is weird."
|
assert len(VERSIONS) > 0 # "No VERSIONS found, something is weird."
|
||||||
with open(self.filepath, 'r') as file:
|
with open(self.filepath, 'r') as file:
|
||||||
lines = file.readlines()
|
lines = file.readlines()
|
||||||
with open(self.filepath, 'w') as file:
|
with open(self.filepath, 'w', newline='\n') as file:
|
||||||
|
self.file = file
|
||||||
in_package = False
|
in_package = False
|
||||||
in_dependencies = False
|
in_dependencies = False
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
|
@ -77,18 +91,18 @@ class PatchInfo:
|
||||||
in_dependencies = True
|
in_dependencies = True
|
||||||
else:
|
else:
|
||||||
in_dependencies = False
|
in_dependencies = False
|
||||||
file.write(line)
|
self.output(line)
|
||||||
elif line.strip().startswith('#'): # skip comments
|
elif line.strip().startswith('#'): # skip comments
|
||||||
file.write(line)
|
self.output(line)
|
||||||
elif in_package:
|
elif in_package:
|
||||||
# increment my own version, if I'm in the listed crates
|
# increment my own version, if I'm in the listed crates
|
||||||
if self.cratename is not None:
|
if self.cratename is not None:
|
||||||
if line.strip().startswith('version'):
|
if line.strip().startswith('version'):
|
||||||
file.write('version = "{}"\n'.format(bump_version(VERSIONS[self.cratename])))
|
self.output('version = "{}"\n'.format(bump_version(VERSIONS[self.cratename])))
|
||||||
else:
|
else:
|
||||||
file.write(line)
|
self.output(line)
|
||||||
else:
|
else:
|
||||||
file.write(line)
|
self.output(line)
|
||||||
|
|
||||||
if line.strip().startswith('name'):
|
if line.strip().startswith('name'):
|
||||||
this_crate = line.split('=')[1].replace('"', '').strip()
|
this_crate = line.split('=')[1].replace('"', '').strip()
|
||||||
|
|
@ -122,11 +136,14 @@ class PatchInfo:
|
||||||
print("Warning! Version substitution failed for {}:{} in crate {} ({})".format(depcrate, oldver, this_crate, numsubs))
|
print("Warning! Version substitution failed for {}:{} in crate {} ({})".format(depcrate, oldver, this_crate, numsubs))
|
||||||
|
|
||||||
# print("orig: {}\nnew: {}".format(line, newline))
|
# print("orig: {}\nnew: {}".format(line, newline))
|
||||||
file.write(newline)
|
self.output(newline)
|
||||||
else:
|
else:
|
||||||
file.write(line)
|
self.output(line)
|
||||||
else:
|
else:
|
||||||
file.write(line)
|
self.output(line)
|
||||||
|
# if debug mode, just write the line unharmed
|
||||||
|
if self.debug:
|
||||||
|
self.file.write(line)
|
||||||
|
|
||||||
def bump_version(semver):
|
def bump_version(semver):
|
||||||
components = semver.split('.')
|
components = semver.split('.')
|
||||||
|
|
@ -138,11 +155,6 @@ def bump_version(semver):
|
||||||
retver += "."
|
retver += "."
|
||||||
return retver
|
return retver
|
||||||
|
|
||||||
def merge_two_dicts(x, y):
|
|
||||||
z = x.copy()
|
|
||||||
z.update(y)
|
|
||||||
return z
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="Update and publish crates")
|
parser = argparse.ArgumentParser(description="Update and publish crates")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
|
@ -166,20 +178,21 @@ def main():
|
||||||
print("Warning: no dependencies selected, operation is a no-op. Use -x/-u/... to select dependency trees")
|
print("Warning: no dependencies selected, operation is a no-op. Use -x/-u/... to select dependency trees")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
cratelist = {}
|
cratelist = []
|
||||||
if args.xous:
|
if args.utralib: # ordering is important, the UTRA crates need to publish before Xous crates
|
||||||
cratelist = merge_two_dicts(cratelist, CRATES)
|
cratelist += UTRA_CRATES
|
||||||
if args.utralib:
|
|
||||||
cratelist = merge_two_dicts(cratelist, UTRA_CRATES)
|
|
||||||
if not args.xous: # most Xous crates are also affected by this, so they need a bump as well
|
if not args.xous: # most Xous crates are also affected by this, so they need a bump as well
|
||||||
cratelist = merge_two_dicts(cratelist, CRATES)
|
cratelist += CRATES
|
||||||
|
if args.xous:
|
||||||
|
cratelist += CRATES
|
||||||
|
|
||||||
if args.bump:
|
if args.bump:
|
||||||
cargo_toml_paths = []
|
cargo_toml_paths = []
|
||||||
for path in Path('.').rglob('Cargo.toml'):
|
for path in Path('.').rglob('Cargo.toml'):
|
||||||
if 'target' not in str(path):
|
if 'target' not in str(path):
|
||||||
not_core_path = True
|
not_core_path = True
|
||||||
for editpath in cratelist.values():
|
for cratespec in cratelist:
|
||||||
|
editpath = cratespec[1]
|
||||||
if editpath in str(Path(path)).replace('\\', '/'): # fix windows paths
|
if editpath in str(Path(path)).replace('\\', '/'): # fix windows paths
|
||||||
not_core_path = False
|
not_core_path = False
|
||||||
if not_core_path:
|
if not_core_path:
|
||||||
|
|
@ -191,7 +204,7 @@ def main():
|
||||||
|
|
||||||
patches = []
|
patches = []
|
||||||
# extract the versions of crates to patch
|
# extract the versions of crates to patch
|
||||||
for (crate, path) in cratelist.items():
|
for [crate, path] in cratelist:
|
||||||
#print("extracting {}".format(path))
|
#print("extracting {}".format(path))
|
||||||
patchinfo = PatchInfo(path + '/Cargo.toml', cratelist, crate)
|
patchinfo = PatchInfo(path + '/Cargo.toml', cratelist, crate)
|
||||||
if not patchinfo.get_version():
|
if not patchinfo.get_version():
|
||||||
|
|
@ -210,6 +223,7 @@ def main():
|
||||||
print("{}: {} -> {}".format(name, ver, bump_version(ver)))
|
print("{}: {} -> {}".format(name, ver, bump_version(ver)))
|
||||||
|
|
||||||
for patch in patches:
|
for patch in patches:
|
||||||
|
patch.debug_mode(not args.wet_run)
|
||||||
patch.increment_versions()
|
patch.increment_versions()
|
||||||
|
|
||||||
if args.publish:
|
if args.publish:
|
||||||
|
|
@ -224,7 +238,7 @@ def main():
|
||||||
cmd = wet_cmd
|
cmd = wet_cmd
|
||||||
else:
|
else:
|
||||||
cmd = dry_cmd
|
cmd = dry_cmd
|
||||||
for (crate, path) in cratelist.items():
|
for [crate, path] in cratelist:
|
||||||
print("Publishing {} in {}".format(crate, path))
|
print("Publishing {} in {}".format(crate, path))
|
||||||
try:
|
try:
|
||||||
subprocess.run(cmd, cwd=path, check=True)
|
subprocess.run(cmd, cwd=path, check=True)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue