14
14
import subprocess
15
15
import sys
16
16
17
- USE_LINKS = sys .platform != 'win32'
18
-
19
- DART_ANALYZE = os .path .join (os .path .dirname (os .path .abspath (__file__ )), 'dart_analyze.py' )
20
-
21
17
22
18
def dart_filter (path ):
23
19
if os .path .isdir (path ):
24
20
return True
25
21
_ , ext = os .path .splitext (path )
26
- # .dart includes '.mojom.dart'
27
22
return ext == '.dart'
28
23
29
24
@@ -41,21 +36,6 @@ def has_pubspec_yaml(paths):
41
36
return False
42
37
43
38
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
-
59
39
def copy (from_root , to_root , filter_func = None ):
60
40
if not os .path .exists (from_root ):
61
41
return
@@ -84,18 +64,6 @@ def copy(from_root, to_root, filter_func=None):
84
64
dirs [:] = list (filter (wrapped_filter , dirs ))
85
65
86
66
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
-
99
67
def remove_if_exists (path ):
100
68
try :
101
69
os .remove (path )
@@ -118,47 +86,6 @@ def list_files(from_root, filter_func=None):
118
86
return file_list
119
87
120
88
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
-
162
89
def main ():
163
90
parser = argparse .ArgumentParser (description = 'Generate a dart-pkg' )
164
91
parser .add_argument (
@@ -177,23 +104,10 @@ def main():
177
104
help = 'Directory where dart_pkg should go' ,
178
105
required = True
179
106
)
180
- parser .add_argument (
181
- '--package-root' , metavar = 'package_root' , help = 'packages/ directory' , required = True
182
- )
183
107
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
- )
187
108
parser .add_argument (
188
109
'--package-sources' , metavar = 'package_sources' , help = 'Package sources' , nargs = '+'
189
110
)
190
- parser .add_argument (
191
- '--package-entrypoints' ,
192
- metavar = 'package_entrypoints' ,
193
- help = 'Package entry points for analyzer' ,
194
- nargs = '*' ,
195
- default = []
196
- )
197
111
parser .add_argument (
198
112
'--sdk-ext-directories' ,
199
113
metavar = 'sdk_ext_directories' ,
@@ -249,14 +163,7 @@ def main():
249
163
for source in args .package_sources :
250
164
relative_source = os .path .relpath (source , common_source_prefix )
251
165
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 )
260
167
261
168
# Copy sdk-ext sources into pkg directory
262
169
sdk_ext_dir = os .path .join (target_dir , 'sdk_ext' )
@@ -266,30 +173,13 @@ def main():
266
173
for source in sdk_ext_sources :
267
174
relative_source = os .path .relpath (source , common_prefix )
268
175
target = os .path .join (sdk_ext_dir , relative_source )
269
- copy_or_link (source , target )
176
+ copy (source , target )
270
177
271
178
common_source_prefix = os .path .dirname (os .path .commonprefix (args .sdk_ext_files ))
272
179
for source in args .sdk_ext_files :
273
180
relative_source = os .path .relpath (source , common_source_prefix )
274
181
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 )
293
183
294
184
# Write stamp file.
295
185
with open (args .stamp_file , 'w' ):
0 commit comments