1414import subprocess
1515import sys
1616
17- USE_LINKS = sys .platform != 'win32'
18-
19- DART_ANALYZE = os .path .join (os .path .dirname (os .path .abspath (__file__ )), 'dart_analyze.py' )
20-
2117
2218def dart_filter (path ):
2319 if os .path .isdir (path ):
2420 return True
2521 _ , ext = os .path .splitext (path )
26- # .dart includes '.mojom.dart'
2722 return ext == '.dart'
2823
2924
@@ -41,21 +36,6 @@ def has_pubspec_yaml(paths):
4136 return False
4237
4338
44- def link (from_root , to_root ):
45- ensure_dir_exists (os .path .dirname (to_root ))
46- try :
47- os .unlink (to_root )
48- except OSError as err :
49- if err .errno == errno .ENOENT :
50- pass
51-
52- try :
53- os .symlink (from_root , to_root )
54- except OSError as err :
55- if err .errno == errno .EEXIST :
56- pass
57-
58-
5939def copy (from_root , to_root , filter_func = None ):
6040 if not os .path .exists (from_root ):
6141 return
@@ -84,18 +64,6 @@ def copy(from_root, to_root, filter_func=None):
8464 dirs [:] = list (filter (wrapped_filter , dirs ))
8565
8666
87- def copy_or_link (from_root , to_root , filter_func = None ):
88- if USE_LINKS :
89- link (from_root , to_root )
90- else :
91- copy (from_root , to_root , filter_func )
92-
93-
94- def link_if_possible (from_root , to_root ):
95- if USE_LINKS :
96- link (from_root , to_root )
97-
98-
9967def remove_if_exists (path ):
10068 try :
10169 os .remove (path )
@@ -118,47 +86,6 @@ def list_files(from_root, filter_func=None):
11886 return file_list
11987
12088
121- def remove_broken_symlink (path ):
122- if not USE_LINKS :
123- return
124- try :
125- link_path = os .readlink (path )
126- except OSError as err :
127- # Path was not a symlink.
128- if err .errno == errno .EINVAL :
129- pass
130- else :
131- if not os .path .exists (link_path ):
132- remove_if_exists (path )
133-
134-
135- def remove_broken_symlinks (root_dir ):
136- if not USE_LINKS :
137- return
138- for current_dir , _ , child_files in os .walk (root_dir ):
139- for filename in child_files :
140- path = os .path .join (current_dir , filename )
141- remove_broken_symlink (path )
142-
143-
144- def analyze_entrypoints (dart_sdk , package_root , entrypoints ):
145- cmd = ['python' , DART_ANALYZE ]
146- cmd .append ('--dart-sdk' )
147- cmd .append (dart_sdk )
148- cmd .append ('--entrypoints' )
149- cmd .extend (entrypoints )
150- cmd .append ('--package-root' )
151- cmd .append (package_root )
152- cmd .append ('--no-hints' )
153- try :
154- subprocess .check_output (cmd , stderr = subprocess .STDOUT )
155- except subprocess .CalledProcessError as err :
156- print ('Failed analyzing %s' % entrypoints )
157- print (err .output )
158- return err .returncode
159- return 0
160-
161-
16289def main ():
16390 parser = argparse .ArgumentParser (description = 'Generate a dart-pkg' )
16491 parser .add_argument (
@@ -177,23 +104,10 @@ def main():
177104 help = 'Directory where dart_pkg should go' ,
178105 required = True
179106 )
180- parser .add_argument (
181- '--package-root' , metavar = 'package_root' , help = 'packages/ directory' , required = True
182- )
183107 parser .add_argument ('--stamp-file' , metavar = 'stamp_file' , help = 'timestamp file' , required = True )
184- parser .add_argument (
185- '--entries-file' , metavar = 'entries_file' , help = 'script entries file' , required = True
186- )
187108 parser .add_argument (
188109 '--package-sources' , metavar = 'package_sources' , help = 'Package sources' , nargs = '+'
189110 )
190- parser .add_argument (
191- '--package-entrypoints' ,
192- metavar = 'package_entrypoints' ,
193- help = 'Package entry points for analyzer' ,
194- nargs = '*' ,
195- default = []
196- )
197111 parser .add_argument (
198112 '--sdk-ext-directories' ,
199113 metavar = 'sdk_ext_directories' ,
@@ -249,14 +163,7 @@ def main():
249163 for source in args .package_sources :
250164 relative_source = os .path .relpath (source , common_source_prefix )
251165 target = os .path .join (target_dir , relative_source )
252- copy_or_link (source , target )
253-
254- entrypoint_targets = []
255- for source in args .package_entrypoints :
256- relative_source = os .path .relpath (source , common_source_prefix )
257- target = os .path .join (target_dir , relative_source )
258- copy_or_link (source , target )
259- entrypoint_targets .append (target )
166+ copy (source , target )
260167
261168 # Copy sdk-ext sources into pkg directory
262169 sdk_ext_dir = os .path .join (target_dir , 'sdk_ext' )
@@ -266,30 +173,13 @@ def main():
266173 for source in sdk_ext_sources :
267174 relative_source = os .path .relpath (source , common_prefix )
268175 target = os .path .join (sdk_ext_dir , relative_source )
269- copy_or_link (source , target )
176+ copy (source , target )
270177
271178 common_source_prefix = os .path .dirname (os .path .commonprefix (args .sdk_ext_files ))
272179 for source in args .sdk_ext_files :
273180 relative_source = os .path .relpath (source , common_source_prefix )
274181 target = os .path .join (sdk_ext_dir , relative_source )
275- copy_or_link (source , target )
276-
277- # Symlink packages/
278- package_path = os .path .join (args .package_root , args .package_name )
279- copy_or_link (lib_path , package_path )
280-
281- # Link dart-pkg/$package/packages to dart-pkg/packages
282- link_if_possible (args .package_root , target_packages_dir )
283-
284- # Remove any broken symlinks in target_dir and package root.
285- remove_broken_symlinks (target_dir )
286- remove_broken_symlinks (args .package_root )
287-
288- # If any entrypoints are defined, write them to disk so that the analyzer
289- # test can find them.
290- with open (args .entries_file , 'w' ) as file :
291- for entrypoint in entrypoint_targets :
292- file .write (entrypoint + '\n ' )
182+ copy (source , target )
293183
294184 # Write stamp file.
295185 with open (args .stamp_file , 'w' ):
0 commit comments