Skip to content

Commit

Permalink
Merge pull request #53 from crytic/fix/old-linux-versions
Browse files Browse the repository at this point in the history
Support for older solc versions with Linux
  • Loading branch information
Natalie Chin authored May 5, 2021
2 parents b83fd28 + 2e3454d commit 82c2399
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 8 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/macos_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: Install Mac OS solc-select

defaults:
run:
# To load bashrc
shell: bash -ieo pipefail {0}

on:
pull_request:
branches: [master, dev]
schedule:
# run CI every day even if no PRs/merges occur
- cron: '0 12 * * *'

jobs:
build:
name: Install test
runs-on: macos-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Set up Python 3.6
uses: actions/setup-python@v2
with:
python-version: 3.6

- name: Install all solc versions
run: |
python3 setup.py develop
solc-select install all
- name: Test minimum release
run: |
solc-select use 0.3.6
- name: Test 0.8.0
run: |
solc-select use 0.8.0
41 changes: 41 additions & 0 deletions .github/workflows/ubuntu_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
name: Install Linux solc-select

defaults:
run:
# To load bashrc
shell: bash -ieo pipefail {0}

on:
pull_request:
branches: [master, dev]
schedule:
# run CI every day even if no PRs/merges occur
- cron: '0 12 * * *'


jobs:
build:
name: Install Ubuntu test
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Set up Python 3.6
uses: actions/setup-python@v2
with:
python-version: 3.6

- name: Install all solc versions
run: |
sudo python3 setup.py develop
solc-select install all
solc-select install all
- name: Test minimum release
run: |
solc-select use 0.4.0
- name: Test 0.8.0
run: |
solc-select use 0.8.0
2 changes: 1 addition & 1 deletion solc_select/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def solc_select():
versions = args.get(INSTALL_VERSIONS)
if versions == []:
print("Available versions to install:")
for version in sorted(get_installable_versions()):
for version in get_installable_versions():
print(version)
else:
install_artifacts(args.get(INSTALL_VERSIONS))
Expand Down
42 changes: 35 additions & 7 deletions solc_select/solc_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import sys
import urllib.request
from distutils.version import StrictVersion

home_dir = os.path.expanduser("~")
solc_select_dir = f"{home_dir}/.solc-select"
Expand Down Expand Up @@ -35,10 +36,11 @@ def current_version():


def installed_versions():
return [f.replace("solc-", "") for f in sorted(os.listdir(artifacts_dir))]
return [
f.replace("solc-", "") for f in sorted(os.listdir(artifacts_dir)) if f.startswith("solc-")
]


# TODO: accept versions in range
def install_artifacts(versions):
releases = get_available_versions()

Expand All @@ -47,7 +49,7 @@ def install_artifacts(versions):
if versions and version not in versions:
continue

url = f"https://binaries.soliditylang.org/{soliditylang_platform()}/{artifact}"
url = get_url(version, artifact)
artifact_file = f"{artifacts_dir}/solc-{version}"
print(f"Installing '{version}'...")
urllib.request.urlretrieve(url, artifact_file)
Expand All @@ -58,6 +60,18 @@ def install_artifacts(versions):
print(f"Version '{version}' installed.")


def is_older_linux(version):
return soliditylang_platform() == "linux-amd64" and StrictVersion(version) <= StrictVersion(
"0.4.10"
)


def get_url(version, artifact):
if is_older_linux(version):
return f"https://raw.githubusercontent.com/crytic/solc/master/linux/amd64/{artifact}"
return f"https://binaries.soliditylang.org/{soliditylang_platform()}/{artifact}"


def switch_global_version(version):
if version in installed_versions():
with open(f"{solc_select_dir}/global-version", "w") as f:
Expand All @@ -74,8 +88,8 @@ def switch_global_version(version):


def valid_version(version):
# check that it matches <digit>.<digit>.<digit>
match = re.search(r"^(\d+).(\d+).(\d+)$", version)

if match is None:
raise argparse.ArgumentTypeError(f"Invalid version '{version}'.")
return version
Expand All @@ -88,17 +102,31 @@ def valid_install_arg(arg):


def get_installable_versions():
return set(get_available_versions()) - set(installed_versions())
installable = list(set(get_available_versions()) - set(installed_versions()))
installable.sort(key=StrictVersion)
return installable


def get_available_versions():
url = f"https://binaries.soliditylang.org/{soliditylang_platform()}/list.json"
list_json = urllib.request.urlopen(url).read()
return json.loads(list_json)["releases"]
available_releases = json.loads(list_json)["releases"]
if soliditylang_platform() == "linux-amd64":
available_releases.update(get_additional_linux_versions())
return available_releases


def get_additional_linux_versions():
if soliditylang_platform() == "linux-amd64":
# This is just to be dynamic, but figure out a better way to do this.
url = "https://raw.githubusercontent.com/crytic/solc/list-json/linux/amd64/list.json"
github_json = urllib.request.urlopen(url).read()
return json.loads(github_json)["releases"]
return []


def soliditylang_platform():
if sys.platform == "linux":
if sys.platform.startswith("linux"):
platform = "linux-amd64"
elif sys.platform == "darwin":
platform = "macosx-amd64"
Expand Down

0 comments on commit 82c2399

Please sign in to comment.