Skip to content

Commit 82c2399

Browse files
author
Natalie Chin
authored
Merge pull request #53 from crytic/fix/old-linux-versions
Support for older solc versions with Linux
2 parents b83fd28 + 2e3454d commit 82c2399

File tree

4 files changed

+116
-8
lines changed

4 files changed

+116
-8
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
name: Install Mac OS solc-select
3+
4+
defaults:
5+
run:
6+
# To load bashrc
7+
shell: bash -ieo pipefail {0}
8+
9+
on:
10+
pull_request:
11+
branches: [master, dev]
12+
schedule:
13+
# run CI every day even if no PRs/merges occur
14+
- cron: '0 12 * * *'
15+
16+
jobs:
17+
build:
18+
name: Install test
19+
runs-on: macos-latest
20+
21+
steps:
22+
- name: Checkout Code
23+
uses: actions/checkout@v2
24+
25+
- name: Set up Python 3.6
26+
uses: actions/setup-python@v2
27+
with:
28+
python-version: 3.6
29+
30+
- name: Install all solc versions
31+
run: |
32+
python3 setup.py develop
33+
solc-select install all
34+
- name: Test minimum release
35+
run: |
36+
solc-select use 0.3.6
37+
- name: Test 0.8.0
38+
run: |
39+
solc-select use 0.8.0
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
name: Install Linux solc-select
3+
4+
defaults:
5+
run:
6+
# To load bashrc
7+
shell: bash -ieo pipefail {0}
8+
9+
on:
10+
pull_request:
11+
branches: [master, dev]
12+
schedule:
13+
# run CI every day even if no PRs/merges occur
14+
- cron: '0 12 * * *'
15+
16+
17+
jobs:
18+
build:
19+
name: Install Ubuntu test
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout Code
24+
uses: actions/checkout@v2
25+
26+
- name: Set up Python 3.6
27+
uses: actions/setup-python@v2
28+
with:
29+
python-version: 3.6
30+
31+
- name: Install all solc versions
32+
run: |
33+
sudo python3 setup.py develop
34+
solc-select install all
35+
solc-select install all
36+
- name: Test minimum release
37+
run: |
38+
solc-select use 0.4.0
39+
- name: Test 0.8.0
40+
run: |
41+
solc-select use 0.8.0

solc_select/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def solc_select():
4545
versions = args.get(INSTALL_VERSIONS)
4646
if versions == []:
4747
print("Available versions to install:")
48-
for version in sorted(get_installable_versions()):
48+
for version in get_installable_versions():
4949
print(version)
5050
else:
5151
install_artifacts(args.get(INSTALL_VERSIONS))

solc_select/solc_select.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import re
55
import sys
66
import urllib.request
7+
from distutils.version import StrictVersion
78

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

3637

3738
def installed_versions():
38-
return [f.replace("solc-", "") for f in sorted(os.listdir(artifacts_dir))]
39+
return [
40+
f.replace("solc-", "") for f in sorted(os.listdir(artifacts_dir)) if f.startswith("solc-")
41+
]
3942

4043

41-
# TODO: accept versions in range
4244
def install_artifacts(versions):
4345
releases = get_available_versions()
4446

@@ -47,7 +49,7 @@ def install_artifacts(versions):
4749
if versions and version not in versions:
4850
continue
4951

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

6062

63+
def is_older_linux(version):
64+
return soliditylang_platform() == "linux-amd64" and StrictVersion(version) <= StrictVersion(
65+
"0.4.10"
66+
)
67+
68+
69+
def get_url(version, artifact):
70+
if is_older_linux(version):
71+
return f"https://raw.githubusercontent.com/crytic/solc/master/linux/amd64/{artifact}"
72+
return f"https://binaries.soliditylang.org/{soliditylang_platform()}/{artifact}"
73+
74+
6175
def switch_global_version(version):
6276
if version in installed_versions():
6377
with open(f"{solc_select_dir}/global-version", "w") as f:
@@ -74,8 +88,8 @@ def switch_global_version(version):
7488

7589

7690
def valid_version(version):
77-
# check that it matches <digit>.<digit>.<digit>
7891
match = re.search(r"^(\d+).(\d+).(\d+)$", version)
92+
7993
if match is None:
8094
raise argparse.ArgumentTypeError(f"Invalid version '{version}'.")
8195
return version
@@ -88,17 +102,31 @@ def valid_install_arg(arg):
88102

89103

90104
def get_installable_versions():
91-
return set(get_available_versions()) - set(installed_versions())
105+
installable = list(set(get_available_versions()) - set(installed_versions()))
106+
installable.sort(key=StrictVersion)
107+
return installable
92108

93109

94110
def get_available_versions():
95111
url = f"https://binaries.soliditylang.org/{soliditylang_platform()}/list.json"
96112
list_json = urllib.request.urlopen(url).read()
97-
return json.loads(list_json)["releases"]
113+
available_releases = json.loads(list_json)["releases"]
114+
if soliditylang_platform() == "linux-amd64":
115+
available_releases.update(get_additional_linux_versions())
116+
return available_releases
117+
118+
119+
def get_additional_linux_versions():
120+
if soliditylang_platform() == "linux-amd64":
121+
# This is just to be dynamic, but figure out a better way to do this.
122+
url = "https://raw.githubusercontent.com/crytic/solc/list-json/linux/amd64/list.json"
123+
github_json = urllib.request.urlopen(url).read()
124+
return json.loads(github_json)["releases"]
125+
return []
98126

99127

100128
def soliditylang_platform():
101-
if sys.platform == "linux":
129+
if sys.platform.startswith("linux"):
102130
platform = "linux-amd64"
103131
elif sys.platform == "darwin":
104132
platform = "macosx-amd64"

0 commit comments

Comments
 (0)