Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions | Variables
copy_dart Namespace Reference

Classes

class  Library
 

Functions

 parseLibrary (library)
 
 normjoin (*args)
 
 mergefiles (srcs, dstfile)
 
 main (outdir=None, *inputs)
 

Variables

 re_directive = re.compile(r'^(library|import|part|native|resource)\s+(.*);$')
 
 re_comment = re.compile(r'^(///|/\*| \*).*$')
 

Detailed Description

Used to merge and copy dart source files for deployment to AppEngine

Function Documentation

◆ main()

copy_dart.main (   outdir = None,
inputs 
)

Definition at line 81 of file copy_dart.py.

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
86 .dart files
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])
91 return 1
92
93 entry_libraries = []
94 for i in inputs:
95 entry_libraries.extend(glob(i))
96
97 for entrypoint in entry_libraries:
98 # Get the transitive set of dart files this entrypoint depends on, merging
99 # each library along the way.
100 worklist = [os.path.normpath(entrypoint)]
101 seen = set()
102 while len(worklist) > 0:
103 lib = worklist.pop()
104 if lib in seen:
105 continue
106
107 seen.add(lib)
108
109 if (dirname(dirname(lib)).endswith('dom/generated/src') or
110 dirname(lib).endswith('dom/src')):
111 continue
112
113 library = parseLibrary(lib)
114
115 # Ensure output directory exists
116 outpath = join(outdir, lib[1:] if isabs(lib) else lib)
117 dstpath = dirname(outpath)
118 if not exists(dstpath):
119 os.makedirs(dstpath)
120
121 # Create file containing all imports, and inlining all sources
122 with open(outpath, 'w') as f:
123 prefix = os.environ.get('DART_HTML_PREFIX')
124 if prefix:
125 f.write(prefix + '\n')
126 if library.name:
127 if library.comment:
128 f.write('%s' % (''.join(library.comment)))
129 f.write("library %s;\n\n" % library.name)
130 else:
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)))
135 mergefiles([normjoin(dirname(lib), s) for s in library.sources],
136 f)
137
138 for suffix in library.imports:
139 m = re.match(r'[\'"]([^\'"]+)[\'"](\s+as\s+\w+)?.*$', suffix)
140 uri = m.group(1)
141 if not uri.startswith('dart:'):
142 worklist.append(normjoin(dirname(lib), uri))
143
144 return 0
145
146
void print(void *str)
Definition bridge.cpp:126
Definition main.py:1

◆ mergefiles()

copy_dart.mergefiles (   srcs,
  dstfile 
)

Definition at line 73 of file copy_dart.py.

73def mergefiles(srcs, dstfile):
74 for src in srcs:
75 with open(src, 'r') as s:
76 for line in s:
77 if not line.startswith('part of '):
78 dstfile.write(line)
79
80

◆ normjoin()

copy_dart.normjoin ( args)

Definition at line 69 of file copy_dart.py.

69def normjoin(*args):
70 return os.path.normpath(os.path.join(*args))
71
72

◆ parseLibrary()

copy_dart.parseLibrary (   library)
 Parses a .dart source file that is the root of a library, and returns
  information about it: the name, the imports, included sources, and any
  code in the file.

Definition at line 29 of file copy_dart.py.

29def parseLibrary(library):
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
32 code in the file.
33 """
34 libraryname = None
35 imports = []
36 sources = []
37 natives = []
38 inlinecode = []
39 librarycomment = []
40 if exists(library):
41 # TODO(sigmund): stop parsing when import/source
42 for line in fileinput.input(library):
43 match = re_directive.match(line)
44 if match:
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))
55 else:
56 raise Exception(
57 'unknown directive %s in %s' % (directive, line))
58 else:
59 # Check for library comment.
60 if not libraryname and re_comment.match(line):
61 librarycomment.append(line)
62 else:
63 inlinecode.append(line)
64 fileinput.close()
65 return Library(libraryname, imports, sources, natives, inlinecode,
66 librarycomment)
67
68

Variable Documentation

◆ re_comment

copy_dart.re_comment = re.compile(r'^(///|/\*| \*).*$')

Definition at line 15 of file copy_dart.py.

◆ re_directive

copy_dart.re_directive = re.compile(r'^(library|import|part|native|resource)\s+(.*);$')

Definition at line 14 of file copy_dart.py.