@@ -182,6 +182,27 @@ def emsdk_path():
182
182
else :
183
183
EMSDK_SET_ENV = os .path .join (emsdk_path (), 'emsdk_set_env.bat' )
184
184
185
+
186
+ # Parses https://github.com/emscripten-core/emscripten/tree/d6aced8 to a pair (https://github.com/emscripten-core/emscripten, d6aced8)
187
+ def parse_github_url_and_refspec (url ):
188
+ if not url :
189
+ return ('' , '' )
190
+
191
+ if url .endswith (('/tree/' , '/tree' , '/commit/' , '/commit' )):
192
+ raise Exception ('Malformed git URL and refspec ' + url + '!' )
193
+
194
+ if '/tree/' in url :
195
+ if url .endswith ('/' ):
196
+ raise Exception ('Malformed git URL and refspec ' + url + '!' )
197
+ return url .split ('/tree/' )
198
+ elif '/commit/' in url :
199
+ if url .endswith ('/' ):
200
+ raise Exception ('Malformed git URL and refspec ' + url + '!' )
201
+ return url .split ('/commit/' )
202
+ else :
203
+ return (url , 'main' ) # Assume the default branch is main in the absence of a refspec
204
+
205
+
185
206
ARCHIVE_SUFFIXES = ('zip' , '.tar' , '.gz' , '.xz' , '.tbz2' , '.bz2' )
186
207
187
208
@@ -498,11 +519,11 @@ def num_files_in_directory(path):
498
519
return len ([name for name in os .listdir (path ) if os .path .exists (os .path .join (path , name ))])
499
520
500
521
501
- def run (cmd , cwd = None ):
522
+ def run (cmd , cwd = None , quiet = False ):
502
523
debug_print ('run(cmd=' + str (cmd ) + ', cwd=' + str (cwd ) + ')' )
503
524
process = subprocess .Popen (cmd , cwd = cwd , env = os .environ .copy ())
504
525
process .communicate ()
505
- if process .returncode != 0 :
526
+ if process .returncode != 0 and not quiet :
506
527
errlog (str (cmd ) + ' failed with error code ' + str (process .returncode ) + '!' )
507
528
return process .returncode
508
529
@@ -792,33 +813,37 @@ def git_clone(url, dstpath):
792
813
git_clone_args = []
793
814
if GIT_CLONE_SHALLOW :
794
815
git_clone_args += ['--depth' , '1' ]
816
+ print ('Cloning from ' + url + '...' )
795
817
return run ([GIT (), 'clone' ] + git_clone_args + [url , dstpath ]) == 0
796
818
797
819
798
- def git_checkout_and_pull (repo_path , branch ):
799
- debug_print ('git_checkout_and_pull(repo_path=' + repo_path + ', branch=' + branch + ')' )
820
+ def git_checkout_and_pull (repo_path , branch_or_tag ):
821
+ debug_print ('git_checkout_and_pull(repo_path=' + repo_path + ', branch/tag =' + branch_or_tag + ')' )
800
822
ret = run ([GIT (), 'fetch' , '--quiet' , 'origin' ], repo_path )
801
823
if ret != 0 :
802
824
return False
803
825
try :
804
- print ("Fetching latest changes to the branch '" + branch + "' for '" + repo_path + "'..." )
826
+ print ("Fetching latest changes to the branch/tag '" + branch_or_tag + "' for '" + repo_path + "'..." )
805
827
ret = run ([GIT (), 'fetch' , '--quiet' , 'origin' ], repo_path )
806
828
if ret != 0 :
807
829
return False
808
- # run([GIT, 'checkout', '-b', branch, '--track', 'origin/'+branch], repo_path)
809
830
# this line assumes that the user has not gone and manually messed with the
810
831
# repo and added new remotes to ambiguate the checkout.
811
- ret = run ([GIT (), 'checkout' , '--quiet' , branch ], repo_path )
832
+ ret = run ([GIT (), 'checkout' , '--quiet' , branch_or_tag ], repo_path )
812
833
if ret != 0 :
813
834
return False
814
- # this line assumes that the user has not gone and made local changes to the repo
815
- ret = run ([GIT (), 'merge' , '--ff-only' , 'origin/' + branch ], repo_path )
835
+ # Test if branch_or_tag is a branch, or if it is a tag that needs to be updated
836
+ target_is_tag = run ([GIT (), 'symbolic-ref' , '-q' , 'HEAD' ], repo_path , quiet = True )
837
+ if not target_is_tag :
838
+ # update branch to latest (not needed for tags)
839
+ # this line assumes that the user has not gone and made local changes to the repo
840
+ ret = run ([GIT (), 'merge' , '--ff-only' , 'origin/' + branch_or_tag ], repo_path )
816
841
if ret != 0 :
817
842
return False
818
843
except :
819
844
errlog ('git operation failed!' )
820
845
return False
821
- print ("Successfully updated and checked out branch '" + branch + "' on repository '" + repo_path + "'" )
846
+ print ("Successfully updated and checked out branch/tag '" + branch_or_tag + "' on repository '" + repo_path + "'" )
822
847
print ("Current repository version: " + git_repo_version (repo_path ))
823
848
return True
824
849
@@ -1684,7 +1709,9 @@ def __init__(self, data):
1684
1709
setattr (self , key , value )
1685
1710
1686
1711
# Cache the name ID of this Tool (these are read very often)
1687
- self .name = self .id + '-' + self .version
1712
+ self .name = self .id
1713
+ if self .version :
1714
+ self .name += '-' + self .version
1688
1715
if hasattr (self , 'bitness' ):
1689
1716
self .name += '-' + str (self .bitness ) + 'bit'
1690
1717
@@ -2873,6 +2900,10 @@ def main(args):
2873
2900
in the environment where the build is invoked.
2874
2901
See README.md for details.
2875
2902
2903
+ --override-repository: Specifies the git URL to use for a given Tool. E.g.
2904
+ --override-repository emscripten-main@https://github.com/<fork>/emscripten/tree/<refspec>
2905
+
2906
+
2876
2907
emsdk uninstall <tool/sdk> - Removes the given tool or SDK from disk.''' )
2877
2908
2878
2909
if WINDOWS :
@@ -2920,6 +2951,13 @@ def extract_bool_arg(name):
2920
2951
return True
2921
2952
return False
2922
2953
2954
+ def extract_string_arg (name ):
2955
+ for i in range (len (args )):
2956
+ if args [i ] == name :
2957
+ value = args [i + 1 ]
2958
+ del args [i :i + 2 ]
2959
+ return value
2960
+
2923
2961
arg_old = extract_bool_arg ('--old' )
2924
2962
arg_uses = extract_bool_arg ('--uses' )
2925
2963
arg_permanent = extract_bool_arg ('--permanent' )
@@ -2949,6 +2987,20 @@ def extract_bool_arg(name):
2949
2987
load_dot_emscripten ()
2950
2988
load_sdk_manifest ()
2951
2989
2990
+ # Apply any overrides to git branch names to clone from.
2991
+ forked_url = extract_string_arg ('--override-repository' )
2992
+ while forked_url :
2993
+ tool_name , url_and_refspec = forked_url .split ('@' )
2994
+ t = find_tool (tool_name )
2995
+ if not t :
2996
+ errlog ('Failed to find tool ' + tool_name + '!' )
2997
+ return False
2998
+ else :
2999
+ t .url , t .git_branch = parse_github_url_and_refspec (url_and_refspec )
3000
+ debug_print ('Reading git repository URL "' + t .url + '" and git branch "' + t .git_branch + '" for Tool "' + tool_name + '".' )
3001
+
3002
+ forked_url = extract_string_arg ('--override-repository' )
3003
+
2952
3004
# Process global args
2953
3005
for i in range (len (args )):
2954
3006
if args [i ].startswith ('--generator=' ):
0 commit comments