163 parser = argparse.ArgumentParser(description='Generate a dart-pkg')
164 parser.add_argument(
165 '--dart-sdk', action='store', metavar='dart_sdk', help='Path to the Dart SDK.'
166 )
167 parser.add_argument(
168 '--package-name',
169 action='store',
170 metavar='package_name',
171 help='Name of package',
172 required=True
173 )
174 parser.add_argument(
175 '--pkg-directory',
176 metavar='pkg_directory',
177 help='Directory where dart_pkg should go',
178 required=True
179 )
180 parser.add_argument(
181 '--package-root', metavar='package_root', help='packages/ directory', required=True
182 )
183 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 parser.add_argument(
188 '--package-sources', metavar='package_sources', help='Package sources', nargs='+'
189 )
190 parser.add_argument(
191 '--package-entrypoints',
192 metavar='package_entrypoints',
193 help='Package entry points for analyzer',
194 nargs='*',
195 default=[]
196 )
197 parser.add_argument(
198 '--sdk-ext-directories',
199 metavar='sdk_ext_directories',
200 help='Directory containing .dart sources',
201 nargs='*',
202 default=[]
203 )
204 parser.add_argument(
205 '--sdk-ext-files',
206 metavar='sdk_ext_files',
207 help='List of .dart files that are part of sdk_ext.',
208 nargs='*',
209 default=[]
210 )
211 parser.add_argument(
212 '--sdk-ext-mappings',
213 metavar='sdk_ext_mappings',
214 help='Mappings for SDK extension libraries.',
215 nargs='*',
216 default=[]
217 )
218 parser.add_argument(
219 '--read_only',
220 action='store_true',
221 dest='read_only',
222 help='Package is a read only package.',
223 default=False
224 )
225 args = parser.parse_args()
226
227
229
230 target_dir = os.path.join(args.pkg_directory, args.package_name)
231 target_packages_dir = os.path.join(target_dir, 'packages')
232 lib_path = os.path.join(target_dir, 'lib')
234
235 mappings = {}
236 for mapping in args.sdk_ext_mappings:
237 library, path = mapping.split(',', 1)
238 mappings[library] = '../sdk_ext/%s' % path
239
240 sdkext_path = os.path.join(lib_path, '_sdkext')
241 if mappings:
242 with open(sdkext_path, 'w') as stream:
243 json.dump(mappings, stream, sort_keys=True, indent=2, separators=(',', ': '))
244 else:
246
247
248 common_source_prefix = os.path.dirname(os.path.commonprefix(args.package_sources))
249 for source in args.package_sources:
250 relative_source = os.path.relpath(source, common_source_prefix)
251 target = os.path.join(target_dir, relative_source)
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)
259 entrypoint_targets.append(target)
260
261
262 sdk_ext_dir = os.path.join(target_dir, 'sdk_ext')
263 for directory in args.sdk_ext_directories:
264 sdk_ext_sources =
list_files(directory, dart_filter)
265 common_prefix = os.path.commonprefix(sdk_ext_sources)
266 for source in sdk_ext_sources:
267 relative_source = os.path.relpath(source, common_prefix)
268 target = os.path.join(sdk_ext_dir, relative_source)
270
271 common_source_prefix = os.path.dirname(os.path.commonprefix(args.sdk_ext_files))
272 for source in args.sdk_ext_files:
273 relative_source = os.path.relpath(source, common_source_prefix)
274 target = os.path.join(sdk_ext_dir, relative_source)
276
277
278 package_path = os.path.join(args.package_root, args.package_name)
280
281
283
284
287
288
289
290 with open(args.entries_file, 'w') as file:
291 for entrypoint in entrypoint_targets:
292 file.write(entrypoint + '\n')
293
294
295 with open(args.stamp_file, 'w'):
296 pass
297
298 return 0
299
300
def remove_if_exists(path)
def remove_broken_symlinks(root_dir)