forked from f4pga/prjxray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_environment.py
executable file
·66 lines (50 loc) · 2.12 KB
/
create_environment.py
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
63
64
65
66
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017-2020 The Project X-Ray Authors.
#
# Use of this source code is governed by a ISC-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/ISC
#
# SPDX-License-Identifier: ISC
import os
from prjxray.util import get_part_information, get_part_resources, get_fabric_for_part
def get_environment_variables():
"""
This function returns a dict of environment settings for a given part.
It requires a basic setup of the prjxray environment that contains
information about the databse directory location, the FPGA part, etc.
One of the settings must be sourced, to set up the basic environment.
"""
environment = dict()
# Get base environment variables and resources' paths
part = os.environ['XRAY_PART']
database = os.environ['XRAY_DATABASE']
database_dir = os.environ['XRAY_DATABASE_DIR']
xray_root = os.environ['XRAY_DIR']
db_root = os.path.join(database_dir, database)
res_path = os.path.join(xray_root, 'settings', database)
# Get device information
part_info = get_part_information(db_root, part)
fabric = get_fabric_for_part(db_root, part)
resources = get_part_resources(res_path, os.environ['XRAY_PART'])
environment['XRAY_DEVICE'] = part_info['device']
environment['XRAY_PACKAGE'] = part_info['package']
environment['XRAY_SPEED_GRADE'] = part_info['speedgrade']
environment['XRAY_FABRIC'] = fabric
for number, pin in resources['pins'].items():
environment['XRAY_PIN_{:02d}'.format(number)] = pin
return environment
def main():
# Only dump the environment when the resource.yaml file for the family
# exists to prevent errors during the creation on the stdout.
# SKIP_ENV in the environment turns off the environment dump for updating
# all parts and resources, which will create the resource.yaml file.
if 'SKIP_ENV' in os.environ:
return
environment = get_environment_variables()
for key, value in environment.items():
print("export {}={}".format(key, value))
if __name__ == "__main__":
main()