litex_setup: Use subprocess so failures are noticed.
[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
9 current_path = os.path.dirname(os.path.realpath(__file__))
10
11 # name, (url, recursive clone, develop)
12 repos = [
13 # HDL
14 ("migen", ("https://github.com/m-labs/", True, True)),
15
16 # LiteX SoC builder
17 ("litex", ("https://github.com/enjoy-digital/", True, True)),
18
19 # LiteX cores ecosystem
20 ("liteeth", ("https://github.com/enjoy-digital/", False, True)),
21 ("litedram", ("https://github.com/enjoy-digital/", False, True)),
22 ("litepcie", ("https://github.com/enjoy-digital/", False, True)),
23 ("litesata", ("https://github.com/enjoy-digital/", False, True)),
24 ("litesdcard", ("https://github.com/enjoy-digital/", False, True)),
25 ("liteiclink", ("https://github.com/enjoy-digital/", False, True)),
26 ("litevideo", ("https://github.com/enjoy-digital/", False, True)),
27 ("litescope", ("https://github.com/enjoy-digital/", False, True)),
28 ("litejesd204b", ("https://github.com/enjoy-digital/", False, True)),
29 ("litespi", ("https://github.com/litex-hub/", False, True)),
30
31 # LiteX boards support
32 ("litex-boards", ("https://github.com/litex-hub/", False, True)),
33 ]
34 repos = OrderedDict(repos)
35
36 if len(sys.argv) < 2:
37 print("Available commands:")
38 print("- init")
39 print("- install (add --user to install to user directory)")
40 print("- update")
41 exit()
42
43 if "init" in sys.argv[1:]:
44 for name in repos.keys():
45 url, need_recursive, need_develop = repos[name]
46 # clone repo (recursive if needed)
47 print("[cloning " + name + "]...")
48 full_url = url + name
49 opts = "--recursive" if need_recursive else ""
50 subprocess.check_call(
51 "git clone " + full_url + " " + opts,
52 shell=True)
53
54 if "install" in sys.argv[1:]:
55 for name in repos.keys():
56 url, need_recursive, need_develop = repos[name]
57 # develop if needed
58 print("[installing " + name + "]...")
59 if need_develop:
60 os.chdir(os.path.join(current_path, name))
61 if "--user" in sys.argv[1:]:
62 subprocess.check_call(
63 "python3 setup.py develop --user",
64 shell=True)
65 else:
66 subprocess.check_call(
67 "python3 setup.py develop",
68 shell=True)
69
70 if "update" in sys.argv[1:]:
71 for name in repos.keys():
72 # update
73 print("[updating " + name + "]...")
74 os.chdir(os.path.join(current_path, name))
75 subprocess.check_call(
76 "git pull",
77 shell=True)