@@ -64,14 +64,20 @@ def optimize_imports(assembled_content):
6464 return result
6565
6666
67- entry_scripts = {" build.py" : " rebuild.py" ,
68- " ci_build.py" : " ci_rebuild.py" }
67+ entry_scripts = {' build.py' : ' rebuild.py' ,
68+ ' ci_build.py' : ' ci_rebuild.py' }
6969
7070for script_name , output_name in entry_scripts .items ():
7171 build_file_content = file_utils .read_file (script_name )
72- imported_files = [" build" ]
72+ imported_files = [' build' ]
7373
74- assembled_content = ""
74+ assembled_content = ''
75+
76+ shebang = None
77+ if build_file_content .startswith ('#!' ):
78+ splitted_content = build_file_content .split ('\n ' , 1 )
79+ shebang = splitted_content [0 ]
80+ build_file_content = splitted_content [1 ]
7581
7682 next_content = build_file_content
7783 while next_content :
@@ -81,6 +87,9 @@ def optimize_imports(assembled_content):
8187 assembled_content = optimize_imports (assembled_content )
8288 assembled_content = string_utils .remove_empty_lines (assembled_content )
8389
84- output_path = os .path .join ("build" , output_name )
90+ if shebang :
91+ assembled_content = shebang + '\n ' + assembled_content
92+
93+ output_path = os .path .join ('build' , output_name )
8594 file_utils .write_file (output_path , assembled_content )
8695 file_utils .make_executable (output_path )
0 commit comments