From 59b7db63b187176d21d96bc9316d3d28b223db68 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Mon, 6 Apr 2020 16:49:52 -0700 Subject: [PATCH 1/7] Fix alignments. --- litex_setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/litex_setup.py b/litex_setup.py index be5e819fc..59e8d1b2b 100755 --- a/litex_setup.py +++ b/litex_setup.py @@ -11,10 +11,10 @@ current_path = os.path.dirname(os.path.realpath(__file__)) # name, (url, recursive clone, develop) repos = [ # HDL - ("migen", ("https://github.com/m-labs/", True, True)), + ("migen", ("https://github.com/m-labs/", True, True)), # LiteX SoC builder - ("litex", ("https://github.com/enjoy-digital/", True, True)), + ("litex", ("https://github.com/enjoy-digital/", True, True)), # LiteX cores ecosystem ("liteeth", ("https://github.com/enjoy-digital/", False, True)), @@ -29,7 +29,7 @@ repos = [ ("litespi", ("https://github.com/litex-hub/", False, True)), # LiteX boards support - ("litex-boards", ("https://github.com/litex-hub/", False, True)), + ("litex-boards", ("https://github.com/litex-hub/", False, True)), ] repos = OrderedDict(repos) From 6adabae730603cf2248aef429c243ce12a0830d4 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Mon, 6 Apr 2020 16:39:49 -0700 Subject: [PATCH 2/7] Adding SiFive RISC-V toolchain downloading to litex_setup.py --- litex_setup.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/litex_setup.py b/litex_setup.py index 59e8d1b2b..14fc0cb37 100755 --- a/litex_setup.py +++ b/litex_setup.py @@ -5,6 +5,7 @@ import sys import subprocess from collections import OrderedDict +import urllib.request current_path = os.path.dirname(os.path.realpath(__file__)) @@ -33,14 +34,68 @@ repos = [ ] repos = OrderedDict(repos) + +def sifive_riscv_download(): + base_url = "https://static.dev.sifive.com/dev-tools/" + base_file = "riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-" + + is_windows = ( + sys.platform.startswith('win') or sys.platform.startswith('cygwin')) + if is_windows: + end_file = 'w64-mingw32.zip' + elif sys.platform.startswith('linux'): + end_file = 'linux-ubuntu14.tar.gz' + elif sys.platform.startswith('darwin'): + end_file = 'apple-darwin.tar.gz' + else: + raise NotImplementedError(sys.platform) + fn = base_file + end_file + + if not os.path.exists(fn): + url = base_url+fn + print("Downloading", url, "to", fn) + urllib.request.urlretrieve(url, fn) + else: + print("Using existing file", fn) + + print("Extracting", fn) + if fn.endswith(".tar.gz"): + import tarfile + with tarfile.open(fn) as t: + t.extractall() + elif fn.endswith(".zip"): + import zipfile + with zipfile.open(fn) as z: + z.extractall() + + if "--user" in sys.argv[1:] and not is_windows: + print("Linking compiler into ~/.local/bin") + local_bin_dir = os.path.join( + base_file + end_file.split('.', 1)[0], "bin") + assert os.path.exists(local_bin_dir), local_bin_dir + user_bin_dir = os.path.abspath(os.path.expanduser("~/.local/bin")) + if not os.path.exists(user_bin_dir): + os.makedirs(user_bin_dir) + for f in os.listdir(local_bin_dir): + src = os.path.abspath(os.path.join(local_bin_dir, f)) + dst = os.path.join(user_bin_dir, f) + assert os.path.exists(src), src + if os.path.exists(dst): + os.unlink(dst) + assert not os.path.exists(dst), dst + os.symlink(src, dst) + + if len(sys.argv) < 2: print("Available commands:") print("- init") print("- install (add --user to install to user directory)") print("- update") + print("- gcc") exit() if "init" in sys.argv[1:]: + os.chdir(os.path.join(current_path)) for name in repos.keys(): url, need_recursive, need_develop = repos[name] # clone repo (recursive if needed) @@ -66,6 +121,10 @@ if "install" in sys.argv[1:]: subprocess.check_call( "python3 setup.py develop", shell=True) + os.chdir(os.path.join(current_path)) + +if "gcc" in sys.argv[1:]: + sifive_riscv_download() if "update" in sys.argv[1:]: for name in repos.keys(): @@ -75,3 +134,10 @@ if "update" in sys.argv[1:]: subprocess.check_call( "git pull", shell=True) + os.chdir(os.path.join(current_path)) + +if "--user" in sys.argv[1:]: + if ".local/bin" not in os.environ.get("PATH", ""): + print("Make sure that ~/.local/bin is in your PATH") +elif "gcc" in sys.argv[1:]: + print("Make sure that the download RISC-V compiler is in your $PATH.") From 141644d157373ea50bdfd4c10b64c645222f78c4 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Mon, 6 Apr 2020 16:54:25 -0700 Subject: [PATCH 3/7] Make travis use litex_setup.py for GCC download. --- .travis.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index c892607ad..9ff86a27d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ python: "3.6" install: # Get Migen / LiteX / Cores - cd ~/ - - wget https://raw.githubusercontent.com/enjoy-digital/litex/master/litex_setup.py + - cp $TRAVIS_BUILD_DIR/litex_setup.py . - python3 litex_setup.py init install # Install the LiteX version being tested. - cd $TRAVIS_BUILD_DIR @@ -13,8 +13,10 @@ install: before_script: # Get RISC-V toolchain - - wget https://static.dev.sifive.com/dev-tools/riscv64-unknown-elf-gcc-8.1.0-2019.01.0-x86_64-linux-ubuntu14.tar.gz - - tar -xvf riscv64-unknown-elf-gcc-8.1.0-2019.01.0-x86_64-linux-ubuntu14.tar.gz + - cd ~/ + - python3 litex_setup.py gcc - export PATH=$PATH:$PWD/riscv64-unknown-elf-gcc-8.1.0-2019.01.0-x86_64-linux-ubuntu14/bin/ -script: python setup.py test +script: + - cd $TRAVIS_BUILD_DIR + - python setup.py test From 2b2aff127489d8ebb8e97382b875dce2121c92db Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Mon, 6 Apr 2020 17:27:24 -0700 Subject: [PATCH 4/7] Improve the path messages a little. --- litex_setup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/litex_setup.py b/litex_setup.py index 14fc0cb37..b7239ccf4 100755 --- a/litex_setup.py +++ b/litex_setup.py @@ -139,5 +139,7 @@ if "update" in sys.argv[1:]: if "--user" in sys.argv[1:]: if ".local/bin" not in os.environ.get("PATH", ""): print("Make sure that ~/.local/bin is in your PATH") + print("export PATH=$PATH:~/.local/bin") elif "gcc" in sys.argv[1:]: - print("Make sure that the download RISC-V compiler is in your $PATH.") + print("Make sure that the downloaded RISC-V compiler is in your $PATH.") + print("export PATH=$PATH:$(echo $PWD/riscv64-*/bin/)") From a1dd8fc883d713b4a25a34e8867b6f17b0115d2e Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Mon, 6 Apr 2020 17:36:09 -0700 Subject: [PATCH 5/7] Ignore SSL errors on CI. --- litex_setup.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/litex_setup.py b/litex_setup.py index b7239ccf4..61a556a8b 100755 --- a/litex_setup.py +++ b/litex_setup.py @@ -85,6 +85,10 @@ def sifive_riscv_download(): assert not os.path.exists(dst), dst os.symlink(src, dst) +if os.environ.get('TRAVIS', '') == 'true': + # Ignore `ssl.SSLCertVerificationError` on CI. + import ssl + ssl._create_default_https_context = ssl._create_unverified_context if len(sys.argv) < 2: print("Available commands:") From 7f0ecddfb2505d89e72850b935ec4e3b24bf3131 Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Mon, 6 Apr 2020 17:45:55 -0700 Subject: [PATCH 6/7] Use shutil.unpack_archive. --- litex_setup.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/litex_setup.py b/litex_setup.py index 61a556a8b..fa33fb992 100755 --- a/litex_setup.py +++ b/litex_setup.py @@ -3,6 +3,7 @@ import os import sys import subprocess +import shutil from collections import OrderedDict import urllib.request @@ -59,14 +60,7 @@ def sifive_riscv_download(): print("Using existing file", fn) print("Extracting", fn) - if fn.endswith(".tar.gz"): - import tarfile - with tarfile.open(fn) as t: - t.extractall() - elif fn.endswith(".zip"): - import zipfile - with zipfile.open(fn) as z: - z.extractall() + shutil.unpack_archive(fn) if "--user" in sys.argv[1:] and not is_windows: print("Linking compiler into ~/.local/bin") From 9e324d9e16ecd26a1ab72b82ab926365e05618ab Mon Sep 17 00:00:00 2001 From: Tim 'mithro' Ansell Date: Mon, 6 Apr 2020 17:57:32 -0700 Subject: [PATCH 7/7] Remove symlinking step. --- litex_setup.py | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/litex_setup.py b/litex_setup.py index fa33fb992..a9be614d6 100755 --- a/litex_setup.py +++ b/litex_setup.py @@ -62,23 +62,6 @@ def sifive_riscv_download(): print("Extracting", fn) shutil.unpack_archive(fn) - if "--user" in sys.argv[1:] and not is_windows: - print("Linking compiler into ~/.local/bin") - local_bin_dir = os.path.join( - base_file + end_file.split('.', 1)[0], "bin") - assert os.path.exists(local_bin_dir), local_bin_dir - user_bin_dir = os.path.abspath(os.path.expanduser("~/.local/bin")) - if not os.path.exists(user_bin_dir): - os.makedirs(user_bin_dir) - for f in os.listdir(local_bin_dir): - src = os.path.abspath(os.path.join(local_bin_dir, f)) - dst = os.path.join(user_bin_dir, f) - assert os.path.exists(src), src - if os.path.exists(dst): - os.unlink(dst) - assert not os.path.exists(dst), dst - os.symlink(src, dst) - if os.environ.get('TRAVIS', '') == 'true': # Ignore `ssl.SSLCertVerificationError` on CI. import ssl @@ -138,6 +121,6 @@ if "--user" in sys.argv[1:]: if ".local/bin" not in os.environ.get("PATH", ""): print("Make sure that ~/.local/bin is in your PATH") print("export PATH=$PATH:~/.local/bin") -elif "gcc" in sys.argv[1:]: +if "gcc" in sys.argv[1:] and 'riscv64' not in os.environ.get("PATH", ""): print("Make sure that the downloaded RISC-V compiler is in your $PATH.") print("export PATH=$PATH:$(echo $PWD/riscv64-*/bin/)")