File: build_matlab_toolbox2.py

package info (click to toggle)
robotraconteur 1.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,380 kB
  • sloc: cpp: 1,149,268; cs: 87,653; java: 58,127; python: 26,897; ansic: 356; sh: 152; makefile: 90; xml: 51
file content (62 lines) | stat: -rw-r--r-- 2,332 bytes parent folder | download
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import argparse
import os
from pathlib import Path
import shutil
import urllib
import subprocess
import re

asset_dirs = ["artifacts/main", "artifacts/build_python_version"]


def main():

    workdir = Path("build-matlab-toolbox").absolute()

    workdir.mkdir()

    with open("artifacts/main/out-matlab/rrversion.txt", "r") as f:
        tag_name = f.read().strip()

    print(f"tag_name: {tag_name}")

    Path("distfiles").mkdir(exist_ok=True)

    for asset_dir in asset_dirs:
        for fname in list(Path(asset_dir).glob('**/RobotRaconteur-*-MATLAB*')):
            if fname.is_dir():
                continue
            print(fname)
            dest = Path(fname)
            shutil.copy(str(fname), "distfiles/" + dest.name)

    build_dir = Path("build-matlab-toolbox/build")
    matlab_dir = build_dir.joinpath("matlab")
    matlab_dir.mkdir(exist_ok=True, parents=True)

    subprocess.check_call(
        "tar xf ../../../distfiles/RobotRaconteur-*-MATLAB-glnxa64.tar.gz --strip-components 1", shell=True, cwd=matlab_dir)
    subprocess.check_call(
        "tar xf ../../../distfiles/RobotRaconteur-*-MATLAB-maci64.tar.gz --strip-components 1 --wildcards RobotRaconteur-*-MATLAB-maci64/RobotRaconteurMex.*", shell=True, cwd=matlab_dir)
    subprocess.check_call(
        "tar xf ../../../distfiles/RobotRaconteur-*-MATLAB-maca64.tar.gz --strip-components 1 --wildcards RobotRaconteur-*-MATLAB-maca64/RobotRaconteurMex.*", shell=True, cwd=matlab_dir)
    subprocess.check_call(
        "unzip -j ../../../distfiles/RobotRaconteur-*-MATLAB-win64.zip RobotRaconteur-*-MATLAB-win64/RobotRaconteurMex.mexw64", shell=True, cwd=matlab_dir)

    semver_regex = r"^((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*))(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"

    print(tag_name)
    semver_match = re.match(semver_regex, tag_name)

    toolbox_ver = semver_match.group(1)

    with open("robotraconteur/packaging/matlab/RobotRaconteurMatlab.prj.in") as f1:
        s1 = f1.read()
    with open(build_dir.joinpath("RobotRaconteurMatlab.prj"), "w") as f2:
        f2.write(s1.replace("$(rr_version)", toolbox_ver))

    shutil.copy("robotraconteur/packaging/matlab/logo-icon.png", build_dir)


if __name__ == "__main__":
    main()