5"""Used to merge and copy dart source files for deployment to AppEngine"""
11from os.path
import basename, dirname, exists, isabs, join
14re_directive = re.compile(
r'^(library|import|part|native|resource)\s+(.*);$')
15re_comment = re.compile(
r'^(///|/\*| \*).*$')
20 def __init__(self, name, imports, sources, natives, code, comment):
30 """ Parses a .dart source file that is the root of a library, and returns
31 information about it: the name, the imports, included sources, and any
42 for line
in fileinput.input(library):
43 match = re_directive.match(line)
45 directive = match.group(1)
46 if directive ==
'library':
47 assert libraryname
is None
48 libraryname = match.group(2)
49 elif directive ==
'part':
50 suffix = match.group(2)
51 if not suffix.startswith(
'of '):
52 sources.append(match.group(2).strip(
'"\''))
53 elif directive ==
'import':
54 imports.append(match.group(2))
57 'unknown directive %s in %s' % (directive, line))
60 if not libraryname
and re_comment.match(line):
61 librarycomment.append(line)
63 inlinecode.append(line)
65 return Library(libraryname, imports, sources, natives, inlinecode,
70 return os.path.normpath(os.path.join(*args))
75 with open(src,
'r')
as s:
77 if not line.startswith(
'part of '):
81def main(outdir=None, *inputs):
82 if not outdir
or not inputs:
83 print(
"""Usage: %s OUTDIR INPUTS
84 OUTDIR is the war directory to copy to
85 INPUTS
is a list of files
or patterns used to specify the input
87This script should be run
from the client root directory.
88Files will be merged
and copied to: OUTDIR/relative-path-of-file,
89except for dart files
with absolute paths, which will be copied to
90 OUTDIR/absolute-path-
as-directories
""" % sys.argv[0])
95 entry_libraries.extend(glob(i))
97 for entrypoint
in entry_libraries:
100 worklist = [os.path.normpath(entrypoint)]
102 while len(worklist) > 0:
109 if (dirname(dirname(lib)).endswith(
'dom/generated/src')
or
110 dirname(lib).endswith(
'dom/src')):
116 outpath =
join(outdir, lib[1:]
if isabs(lib)
else lib)
117 dstpath = dirname(outpath)
118 if not exists(dstpath):
122 with open(outpath,
'w')
as f:
123 prefix = os.environ.get(
'DART_HTML_PREFIX')
125 f.write(prefix +
'\n')
128 f.write(
'%s' % (
''.
join(library.comment)))
129 f.write(
"library %s;\n\n" % library.name)
131 f.write(
"library %s;\n\n" %
basename(lib))
132 for importfile
in library.imports:
133 f.write(
"import %s;\n" % importfile)
134 f.write(
'%s' % (
''.
join(library.code)))
138 for suffix
in library.imports:
139 m = re.match(
r'[\'"]([^\'"]+)[\'"](\s+as\s+\w+)?.*$', suffix)
141 if not uri.startswith(
'dart:'):
142 worklist.append(
normjoin(dirname(lib), uri))
147if __name__ ==
'__main__':
148 sys.exit(
main(*sys.argv[1:]))
def __init__(self, name, imports, sources, natives, code, comment)
def parseLibrary(library)
def mergefiles(srcs, dstfile)
def main(outdir=None, *inputs)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
def print(*args, **kwargs)
static SkString join(const CommandLineFlags::StringArray &)