Flutter Engine
The Flutter Engine
Functions
copy_tree Namespace Reference

Functions

def ParseArgs (args)
 
def ValidateArgs (args)
 
def CopyTree (src, dst, ignore=None)
 
def WriteDepfile (depfile, stamp, dep_list)
 
def Main (argv)
 

Function Documentation

◆ CopyTree()

def copy_tree.CopyTree (   src,
  dst,
  ignore = None 
)

Definition at line 51 of file copy_tree.py.

51def CopyTree(src, dst, ignore=None):
52 copied_files = []
53
54 # Recursive helper method to collect errors but keep processing.
55 def copy_tree(src, dst, ignore, errors):
56 names = os.listdir(src)
57 if ignore is not None:
58 ignored_names = ignore(src, names)
59 else:
60 ignored_names = set()
61
62 if not os.path.exists(dst):
63 os.makedirs(dst)
64 for name in names:
65 if name in ignored_names:
66 continue
67 srcname = os.path.join(src, name)
68 dstname = os.path.join(dst, name)
69 try:
70 if os.path.isdir(srcname):
71 copy_tree(srcname, dstname, ignore, errors)
72 else:
73 copied_files.append(srcname)
74 shutil.copy(srcname, dstname)
75 except (IOError, os.error) as why:
76 errors.append((srcname, dstname, str(why)))
77 try:
78 shutil.copystat(src, dst)
79 except WindowsError:
80 # Can't copy file access times on Windows.
81 pass
82 except OSError as why:
83 errors.append((src, dst, str(why)))
84
85 # Format errors from file copies.
86 def format_error(error):
87 if len(error) == 1:
88 return "Error: {msg}".format(msg=str(error[0]))
89 return "From: {src}\nTo: {dst}\n{msg}" \
90 .format(src=error[0], dst=error[1], msg=error[2])
91
92 errors = []
93 copy_tree(src, dst, ignore, errors)
94 if errors:
95 failures = "\n\n".join(format_error(error) for error in errors)
96 parts = ("Some file copies failed:", "=" * 78, failures)
97 msg = '\n'.join(parts)
98 raise RuntimeError(msg)
99
100 return copied_files
101
102
uint32_t uint32_t * format
def CopyTree(src, dst, ignore=None)
Definition: copy_tree.py:51
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
Definition: switches.h:76
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741

◆ Main()

def copy_tree.Main (   argv)

Definition at line 116 of file copy_tree.py.

116def Main(argv):
117 args = ParseArgs(argv)
118 if not ValidateArgs(args):
119 return -1
120
121 if args.exclude_patterns == None:
122 copied_files = CopyTree(args.copy_from, args.to)
123 else:
124 patterns = args.exclude_patterns.split(',')
125 copied_files = CopyTree(args.copy_from,
126 args.to,
127 ignore=shutil.ignore_patterns(*patterns))
128
129 if args.depfile and args.stamp:
130 WriteDepfile(args.depfile, args.stamp, copied_files)
131
132 if args.stamp:
133 open(args.stamp, 'w').close()
134
135 return 0
136
137
def ParseArgs(args)
Definition: copy_tree.py:14
def Main(argv)
Definition: copy_tree.py:116
def WriteDepfile(depfile, stamp, dep_list)
Definition: copy_tree.py:103
def ValidateArgs(args)
Definition: copy_tree.py:40

◆ ParseArgs()

def copy_tree.ParseArgs (   args)

Definition at line 14 of file copy_tree.py.

14def ParseArgs(args):
15 args = args[1:]
16 parser = argparse.ArgumentParser(
17 description='A script to copy a file tree somewhere')
18
19 parser.add_argument('--depfile',
20 '-d',
21 type=str,
22 help='Path to a depfile to write when copying.')
23 parser.add_argument(
24 '--exclude_patterns',
25 '-e',
26 type=str,
27 help='Patterns to exclude [passed to shutil.copytree]')
28 parser.add_argument(
29 '--from', '-f', dest="copy_from", type=str, help='Source directory')
30 parser.add_argument(
31 '--stamp',
32 '-s',
33 type=str,
34 help='The path to a stamp file to output when finished.')
35 parser.add_argument('--to', '-t', type=str, help='Destination directory')
36
37 return parser.parse_args(args)
38
39

◆ ValidateArgs()

def copy_tree.ValidateArgs (   args)

Definition at line 40 of file copy_tree.py.

40def ValidateArgs(args):
41 if not args.copy_from or not os.path.isdir(args.copy_from):
42 print("--from argument must refer to a directory")
43 return False
44 if not args.to:
45 print("--to is required")
46 return False
47 return True
48
49
50# Returns a list of the files under 'src' that were copied.
def print(*args, **kwargs)
Definition: run_tests.py:49

◆ WriteDepfile()

def copy_tree.WriteDepfile (   depfile,
  stamp,
  dep_list 
)

Definition at line 103 of file copy_tree.py.

103def WriteDepfile(depfile, stamp, dep_list):
104 os.makedirs(os.path.dirname(depfile), exist_ok=True)
105 # Paths in the depfile must be relative to the root build output directory,
106 # which is the cwd that ninja invokes the script from.
107 cwd = os.getcwd()
108 relstamp = os.path.relpath(stamp, cwd)
109 reldep_list = [os.path.relpath(d, cwd) for d in dep_list]
110 # Depfile paths must use an escape sequence for space characters.
111 reldep_list = [path.replace(" ", r"\ ") for path in reldep_list]
112 with open(depfile, 'w') as f:
113 print("{0}: {1}".format(relstamp, " ".join(reldep_list)), file=f)
114
115