summaryrefslogtreecommitdiff
path: root/bsp/hpmicro/tools/sdk_dist.py
blob: 7169ecc108043bbdc5472dcb68c8d70cba25318d (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
33
34
35
36
37
38
39
40
41
42
43
44
import os

def update_rtt_root_path(path):
    if not os.path.isfile(path):
        return

    with open(path, 'r') as f:
        data = f.read()

    data = data.replace("RTT_ROOT = os.path.normpath(os.getcwd() + '/../../..')",
                        "RTT_ROOT = os.path.join(os.getcwd(), 'rt-thread')")
    data = data.replace('RTT_ROOT = os.path.normpath(os.getcwd() + "/../../..")',
                        "RTT_ROOT = os.path.join(os.getcwd(), 'rt-thread')")

    with open(path, 'w') as f:
        f.write(data)


def update_dist_project_paths(dist_dir):
    update_rtt_root_path(os.path.join(dist_dir, 'SConstruct'))
    update_rtt_root_path(os.path.join(dist_dir, 'rtconfig.py'))

    kconfig_path = os.path.join(dist_dir, 'Kconfig')
    if os.path.isfile(kconfig_path):
        with open(kconfig_path, 'r') as f:
            data = f.read()

        data = data.replace('rsource "../libraries/Kconfig"',
                            'rsource "libraries/Kconfig"')

        with open(kconfig_path, 'w') as f:
            f.write(data)

# BSP dist function
def dist_do_building(BSP_ROOT, dist_dir):
    from mkdist import bsp_copy_files

    library_dir  = os.path.join(dist_dir, 'libraries')

    print("=> copy HPMicro bsp libraries")
    library_path = os.path.join(os.path.dirname(BSP_ROOT), 'libraries')

    bsp_copy_files(library_path, library_dir)
    update_dist_project_paths(dist_dir)