summaryrefslogtreecommitdiff
path: root/scripts/qmlbenchrunner/change_sdk_ver.py
blob: dee4afdc123fcfa12ca031c6a1d67a577b05190a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
# Copyright (C) 2021 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

import os
import sys
import re

cmake_ver = ""

with open("qtbase/.cmake.conf") as cmake:
    for line in cmake.readlines():
        if line.startswith("set(QT_REPO_MODULE_VERSION"):
            cmake_ver = re.match(".+(\d.\d+.\d+)", line).groups()[0]


for root, dirs, files in os.walk(os.path.expanduser(os.environ.get("LB_TOOLCHAIN"))):
    for name in files:
        with open(os.path.join(root, name), mode='r+') as f:
            start = f.read().find("set(PACKAGE_VERSION")
            if start < 0:
                continue
            f.seek(start)
            end = f.read().find("\n")
            f.seek(start)
            toWrite = f"set(PACKAGE_VERSION \"{cmake_ver}\")"
            if len(toWrite) == end:
                f.write(toWrite)
                print(f"Wrote '{toWrite}' to {os.path.join(root, name)}")
            else:
                print(f"Writing to {os.path.join(root, name)} would cause corruption.")
                print(f.read()[start:start+end])