Ignore SSL errors on CI.
[litex.git] / litex_setup.py
1 #!/usr/bin/env python3
2
3 import os
4 import sys
5 import subprocess
6 from collections import OrderedDict
7
8 import urllib.request
9
10 current_path = os.path.dirname(os.path.realpath(__file__))
11
12 # name, (url, recursive clone, develop)
13 repos = [
14 # HDL
15 ("migen", ("https://github.com/m-labs/", True, True)),
16
17 # LiteX SoC builder
18 ("litex", ("https://github.com/enjoy-digital/", True, True)),
19
20 # LiteX cores ecosystem
21 ("liteeth", ("https://github.com/enjoy-digital/", False, True)),
22 ("litedram", ("https://github.com/enjoy-digital/", False, True)),
23 ("litepcie", ("https://github.com/enjoy-digital/", False, True)),
24 ("litesata", ("https://github.com/enjoy-digital/", False, True)),
25 ("litesdcard", ("https://github.com/enjoy-digital/", False, True)),
26 ("liteiclink", ("https://github.com/enjoy-digital/", False, True)),
27 ("litevideo", ("https://github.com/enjoy-digital/", False, True)),
28 ("litescope", ("https://github.com/enjoy-digital/", False, True)),
29 ("litejesd204b", ("https://github.com/enjoy-digital/", False, True)),
30 ("litespi", ("https://github.com/litex-hub/", False, True)),
31
32 # LiteX boards support
33 ("litex-boards", ("https://github.com/litex-hub/", False, True)),
34 ]
35 repos = OrderedDict(repos)
36
37
38 def sifive_riscv_download():
39 base_url = "https://static.dev.sifive.com/dev-tools/"
40 base_file = "riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-"
41
42 is_windows = (
43 sys.platform.startswith('win') or sys.platform.startswith('cygwin'))
44 if is_windows:
45 end_file = 'w64-mingw32.zip'
46 elif sys.platform.startswith('linux'):
47 end_file = 'linux-ubuntu14.tar.gz'
48 elif sys.platform.startswith('darwin'):
49 end_file = 'apple-darwin.tar.gz'
50 else:
51 raise NotImplementedError(sys.platform)
52 fn = base_file + end_file
53
54 if not os.path.exists(fn):
55 url = base_url+fn
56 print("Downloading", url, "to", fn)
57 urllib.request.urlretrieve(url, fn)
58 else:
59 print("Using existing file", fn)
60
61 print("Extracting", fn)
62 if fn.endswith(".tar.gz"):
63 import tarfile
64 with tarfile.open(fn) as t:
65 t.extractall()
66 elif fn.endswith(".zip"):
67 import zipfile
68 with zipfile.open(fn) as z:
69 z.extractall()
70
71 if "--user" in sys.argv[1:] and not is_windows:
72 print("Linking compiler into ~/.local/bin")
73 local_bin_dir = os.path.join(
74 base_file + end_file.split('.', 1)[0], "bin")
75 assert os.path.exists(local_bin_dir), local_bin_dir
76 user_bin_dir = os.path.abspath(os.path.expanduser("~/.local/bin"))
77 if not os.path.exists(user_bin_dir):
78 os.makedirs(user_bin_dir)
79 for f in os.listdir(local_bin_dir):
80 src = os.path.abspath(os.path.join(local_bin_dir, f))
81 dst = os.path.join(user_bin_dir, f)
82 assert os.path.exists(src), src
83 if os.path.exists(dst):
84 os.unlink(dst)
85 assert not os.path.exists(dst), dst
86 os.symlink(src, dst)
87
88 if os.environ.get('TRAVIS', '') == 'true':
89 # Ignore `ssl.SSLCertVerificationError` on CI.
90 import ssl
91 ssl._create_default_https_context = ssl._create_unverified_context
92
93 if len(sys.argv) < 2:
94 print("Available commands:")
95 print("- init")
96 print("- install (add --user to install to user directory)")
97 print("- update")
98 print("- gcc")
99 exit()
100
101 if "init" in sys.argv[1:]:
102 os.chdir(os.path.join(current_path))
103 for name in repos.keys():
104 url, need_recursive, need_develop = repos[name]
105 # clone repo (recursive if needed)
106 print("[cloning " + name + "]...")
107 full_url = url + name
108 opts = "--recursive" if need_recursive else ""
109 subprocess.check_call(
110 "git clone " + full_url + " " + opts,
111 shell=True)
112
113 if "install" in sys.argv[1:]:
114 for name in repos.keys():
115 url, need_recursive, need_develop = repos[name]
116 # develop if needed
117 print("[installing " + name + "]...")
118 if need_develop:
119 os.chdir(os.path.join(current_path, name))
120 if "--user" in sys.argv[1:]:
121 subprocess.check_call(
122 "python3 setup.py develop --user",
123 shell=True)
124 else:
125 subprocess.check_call(
126 "python3 setup.py develop",
127 shell=True)
128 os.chdir(os.path.join(current_path))
129
130 if "gcc" in sys.argv[1:]:
131 sifive_riscv_download()
132
133 if "update" in sys.argv[1:]:
134 for name in repos.keys():
135 # update
136 print("[updating " + name + "]...")
137 os.chdir(os.path.join(current_path, name))
138 subprocess.check_call(
139 "git pull",
140 shell=True)
141 os.chdir(os.path.join(current_path))
142
143 if "--user" in sys.argv[1:]:
144 if ".local/bin" not in os.environ.get("PATH", ""):
145 print("Make sure that ~/.local/bin is in your PATH")
146 print("export PATH=$PATH:~/.local/bin")
147 elif "gcc" in sys.argv[1:]:
148 print("Make sure that the downloaded RISC-V compiler is in your $PATH.")
149 print("export PATH=$PATH:$(echo $PWD/riscv64-*/bin/)")