Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Side by Side Diff: tools/isolate/isolate.py

Issue 9704099: Improve trace_inputs.py to output a format easy to convert to gypi. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix exception Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « testing/xvfb.py ('k') | tools/isolate/trace_inputs.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Does one of the following depending on the --mode argument: 6 """Does one of the following depending on the --mode argument:
7 check Verifies all the inputs exist, touches the file specified with 7 check Verifies all the inputs exist, touches the file specified with
8 --result and exits. 8 --result and exits.
9 hashtable Puts a manifest file and hard links each of the inputs into the 9 hashtable Puts a manifest file and hard links each of the inputs into the
10 output directory. 10 output directory.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 if not cmd: 97 if not cmd:
98 # Note that it is exactly the reverse of relative_cwd. 98 # Note that it is exactly the reverse of relative_cwd.
99 cmd = [os.path.join(os.path.relpath(indir, cwd), infiles[0])] 99 cmd = [os.path.join(os.path.relpath(indir, cwd), infiles[0])]
100 if cmd[0].endswith('.py'): 100 if cmd[0].endswith('.py'):
101 cmd.insert(0, sys.executable) 101 cmd.insert(0, sys.executable)
102 102
103 # Only hashtable mode really needs the sha-1. 103 # Only hashtable mode really needs the sha-1.
104 dictfiles = tree_creator.process_inputs( 104 dictfiles = tree_creator.process_inputs(
105 indir, infiles, mode == 'hashtable', read_only) 105 indir, infiles, mode == 'hashtable', read_only)
106 106
107 if not outdir: 107 result = mode_fn(
108 outdir = os.path.dirname(resultfile) 108 outdir, indir, dictfiles, read_only, cmd, relative_cwd,
109 result = mode_fn(outdir, indir, dictfiles, read_only, cmd, relative_cwd) 109 os.path.dirname(resultfile))
110 110
111 if result == 0: 111 if result == 0:
112 # Saves the resulting file. 112 # Saves the resulting file.
113 out = { 113 out = {
114 'command': cmd, 114 'command': cmd,
115 'relative_cwd': relative_cwd, 115 'relative_cwd': relative_cwd,
116 'files': dictfiles, 116 'files': dictfiles,
117 } 117 }
118 with open(resultfile, 'wb') as f: 118 with open(resultfile, 'wb') as f:
119 json.dump(out, f, indent=2, sort_keys=True) 119 json.dump(out, f, indent=2, sort_keys=True)
120 return result 120 return result
121 121
122 122
123 def MODEcheck(outdir, indir, dictfiles, read_only, cmd, relative_cwd): 123 def MODEcheck(
124 outdir, indir, dictfiles, read_only, cmd, relative_cwd, result_path):
124 """No-op.""" 125 """No-op."""
125 return 0 126 return 0
126 127
127 128
128 def MODEhashtable(outdir, indir, dictfiles, read_only, cmd, relative_cwd): 129 def MODEhashtable(
130 outdir, indir, dictfiles, read_only, cmd, relative_cwd, result_path):
129 """Ignores read_only, cmd and relative_cwd.""" 131 """Ignores read_only, cmd and relative_cwd."""
132 outdir = outdir or result_path
130 for relfile, properties in dictfiles.iteritems(): 133 for relfile, properties in dictfiles.iteritems():
131 infile = os.path.join(indir, relfile) 134 infile = os.path.join(indir, relfile)
132 outfile = os.path.join(outdir, properties['sha-1']) 135 outfile = os.path.join(outdir, properties['sha-1'])
133 if os.path.isfile(outfile): 136 if os.path.isfile(outfile):
134 # Just do a quick check that the file size matches. 137 # Just do a quick check that the file size matches.
135 if os.stat(infile).st_size == os.stat(outfile).st_size: 138 if os.stat(infile).st_size == os.stat(outfile).st_size:
136 continue 139 continue
137 # Otherwise, an exception will be raised. 140 # Otherwise, an exception will be raised.
138 tree_creator.link_file(outfile, infile, tree_creator.HARDLINK) 141 tree_creator.link_file(outfile, infile, tree_creator.HARDLINK)
139 return 0 142 return 0
140 143
141 144
142 def MODEremap(outdir, indir, dictfiles, read_only, cmd, relative_cwd): 145 def MODEremap(
143 """Ignores cmd and relative_cwd.""" 146 outdir, indir, dictfiles, read_only, cmd, relative_cwd, result_path):
147 """Ignores outdir, cmd and relative_cwd."""
144 if not outdir: 148 if not outdir:
145 outdir = tempfile.mkdtemp(prefix='isolate') 149 outdir = tempfile.mkdtemp(prefix='isolate')
150 print 'Remapping into %s' % outdir
151 if len(os.listdir(outdir)):
152 print 'Can\'t remap in a non-empty directory'
153 return 1
146 tree_creator.recreate_tree( 154 tree_creator.recreate_tree(
147 outdir, indir, dictfiles.keys(), tree_creator.HARDLINK) 155 outdir, indir, dictfiles.keys(), tree_creator.HARDLINK)
148 if read_only: 156 if read_only:
149 tree_creator.make_writable(outdir, True) 157 tree_creator.make_writable(outdir, True)
150 return 0 158 return 0
151 159
152 160
153 def MODErun(outdir, indir, dictfiles, read_only, cmd, relative_cwd): 161 def MODErun(
154 """Ignores outdir and always uses a temporary directory.""" 162 outdir, indir, dictfiles, read_only, cmd, relative_cwd, result_path):
155 outdir = None 163 """Always uses a temporary directory."""
156 try: 164 try:
157 outdir = tempfile.mkdtemp(prefix='isolate') 165 outdir = tempfile.mkdtemp(prefix='isolate')
158 tree_creator.recreate_tree( 166 tree_creator.recreate_tree(
159 outdir, indir, dictfiles.keys(), tree_creator.HARDLINK) 167 outdir, indir, dictfiles.keys(), tree_creator.HARDLINK)
160 cwd = os.path.join(outdir, relative_cwd) 168 cwd = os.path.join(outdir, relative_cwd)
161 if not os.path.isdir(cwd): 169 if not os.path.isdir(cwd):
162 os.makedirs(cwd) 170 os.makedirs(cwd)
163 if read_only: 171 if read_only:
164 tree_creator.make_writable(outdir, True) 172 tree_creator.make_writable(outdir, True)
165 173
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 options.mode, 250 options.mode,
243 options.read_only, 251 options.read_only,
244 cmd) 252 cmd)
245 except tree_creator.MappingError, e: 253 except tree_creator.MappingError, e:
246 print >> sys.stderr, str(e) 254 print >> sys.stderr, str(e)
247 return 1 255 return 1
248 256
249 257
250 if __name__ == '__main__': 258 if __name__ == '__main__':
251 sys.exit(main()) 259 sys.exit(main())
OLDNEW
« no previous file with comments | « testing/xvfb.py ('k') | tools/isolate/trace_inputs.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698