|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import sys |
| 3 | +import struct |
| 4 | +import subprocess |
| 5 | +import re |
| 6 | +import os |
| 7 | +import os.path |
| 8 | +import argparse |
| 9 | +import time |
| 10 | +import shutil |
| 11 | + |
| 12 | +def main(): |
| 13 | + parser = argparse.ArgumentParser(description='Version updater') |
| 14 | + parser.add_argument('-v', '--version', action='store', required=True, help='Version in X.Y.Z form') |
| 15 | + args = parser.parse_args() |
| 16 | + |
| 17 | + major, minor, sub = args.version.split(".") |
| 18 | + # Silly way to check for integer x.y.z |
| 19 | + major = int(major) |
| 20 | + minor = int(minor) |
| 21 | + sub = int(sub) |
| 22 | + |
| 23 | + # platform.txt |
| 24 | + with open("platform.txt", "r") as fin: |
| 25 | + with open("platform.txt.new", "w") as fout: |
| 26 | + for l in fin: |
| 27 | + if l.startswith("version="): |
| 28 | + l = "version=" + str(args.version) + "\n" |
| 29 | + fout.write(l); |
| 30 | + shutil.move("platform.txt.new", "platform.txt") |
| 31 | + |
| 32 | + # package.json |
| 33 | + with open("package.json", "r") as fin: |
| 34 | + with open("package.json.new", "w") as fout: |
| 35 | + for l in fin: |
| 36 | + if l.startswith(' "version": '): |
| 37 | + l = l.split(":")[0] |
| 38 | + l = l + ': "1.' + str(major) + "{:02d}".format(minor) + "{:02d}".format(sub) + '.0",' + "\n" |
| 39 | + fout.write(l); |
| 40 | + shutil.move("package.json.new", "package.json") |
| 41 | + |
| 42 | + # cores/rp2040/RP2040Version.h |
| 43 | + with open("cores/rp2040/RP2040Version.h", "w") as fout: |
| 44 | + fout.write("#pragma once\n") |
| 45 | + fout.write("#define ARDUINO_PICO_MAJOR " + str(major) + "\n") |
| 46 | + fout.write("#define ARDUINO_PICO_MINOR " + str(minor) + "\n") |
| 47 | + fout.write("#define ARDUINO_PICO_REVISION " + str(sub) + "\n") |
| 48 | + fout.write('#define ARDUINO_PICO_VERSION_STR "' + str(args.version) + '"' + "\n") |
| 49 | + |
| 50 | +main() |
0 commit comments