2024-08-04 20:31:36 +02:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
import os
|
2024-08-11 02:56:31 +02:00
|
|
|
import re
|
2024-08-04 20:31:36 +02:00
|
|
|
|
|
|
|
|
import blocks
|
2024-08-11 02:56:31 +02:00
|
|
|
import toolchain_info as info
|
2024-08-04 20:31:36 +02:00
|
|
|
|
|
|
|
|
def set_toolchain(block : blocks.CodeBlock):
|
|
|
|
|
|
2024-08-11 02:56:31 +02:00
|
|
|
# Init toolchain info if not initialized
|
|
|
|
|
if not 'root' in info.TOOLCHAIN_PATH:
|
|
|
|
|
info.init_toolchain_info()
|
|
|
|
|
|
2024-08-04 20:31:36 +02:00
|
|
|
# Reset toolchain to ensure that no toolchain exists in the "select" folder
|
|
|
|
|
reset_toolchain()
|
|
|
|
|
|
|
|
|
|
# Create "selected" folder if it doesn't exist
|
2024-08-11 02:56:31 +02:00
|
|
|
selected_path = info.TOOLCHAIN_PATH['selected']
|
2024-08-04 20:31:36 +02:00
|
|
|
os.makedirs(selected_path,
|
|
|
|
|
mode=0o777,
|
|
|
|
|
exist_ok=True)
|
|
|
|
|
|
2024-08-11 03:45:00 +02:00
|
|
|
if block.gnat_version[0] != "default":
|
|
|
|
|
ver = block.gnat_version[1]
|
2024-08-04 20:31:36 +02:00
|
|
|
|
2024-08-11 02:56:31 +02:00
|
|
|
os.symlink(info.TOOLCHAIN_PATH['root'] + '/gnat/' + ver,
|
|
|
|
|
info.TOOLCHAIN_PATH['selected'] + '/gnat')
|
2024-08-04 20:31:36 +02:00
|
|
|
|
2024-08-11 03:45:00 +02:00
|
|
|
if block.gnatprove_version[0] != "default":
|
|
|
|
|
ver = block.gnatprove_version[1]
|
2024-08-04 23:25:47 +02:00
|
|
|
|
2024-08-11 02:56:31 +02:00
|
|
|
os.symlink(info.TOOLCHAIN_PATH['root'] + '/gnatprove/' + ver,
|
|
|
|
|
info.TOOLCHAIN_PATH['selected'] + '/gnatprove')
|
2024-08-04 23:25:47 +02:00
|
|
|
|
2024-08-11 03:45:00 +02:00
|
|
|
if block.gprbuild_version[0] != "default":
|
|
|
|
|
ver = block.gprbuild_version[1]
|
2024-08-04 23:25:47 +02:00
|
|
|
|
2024-08-11 02:56:31 +02:00
|
|
|
os.symlink(info.TOOLCHAIN_PATH['root'] + '/gprbuild/' + ver,
|
|
|
|
|
info.TOOLCHAIN_PATH['selected'] + '/gprbuild')
|
2024-08-04 20:31:36 +02:00
|
|
|
|
|
|
|
|
def reset_toolchain():
|
2024-08-11 02:56:31 +02:00
|
|
|
selected_folders = [info.TOOLCHAIN_PATH['selected'] + '/gnat',
|
|
|
|
|
info.TOOLCHAIN_PATH['selected'] + '/gnatprove',
|
|
|
|
|
info.TOOLCHAIN_PATH['selected'] + '/gprbuild']
|
2024-08-04 20:31:36 +02:00
|
|
|
|
|
|
|
|
for f in selected_folders:
|
|
|
|
|
if os.path.exists(f):
|
|
|
|
|
os.unlink(f)
|