44import re
55import sys
66import urllib .request
7+ from distutils .version import StrictVersion
78
89home_dir = os .path .expanduser ("~" )
910solc_select_dir = f"{ home_dir } /.solc-select"
@@ -35,10 +36,11 @@ def current_version():
3536
3637
3738def 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
4244def 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+
6175def 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
7690def 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
90104def 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
94110def 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
100128def 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