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

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

Issue 10383154: Fix mode=hashtable without --outdir to create the directory at the right place. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 | « no previous file | tools/isolate/isolate_smoke_test.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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 278
279 @classmethod 279 @classmethod
280 def load(cls, data): 280 def load(cls, data):
281 """Loads a flattened version.""" 281 """Loads a flattened version."""
282 data = data.copy() 282 data = data.copy()
283 out = cls() 283 out = cls()
284 for member in out.MEMBERS: 284 for member in out.MEMBERS:
285 if member in data: 285 if member in data:
286 value = data.pop(member) 286 value = data.pop(member)
287 setattr(out, member, value) 287 setattr(out, member, value)
288 assert not data, data 288 # Temporary
289 logging.warning('Dropping data: %s' % data)
290 #assert not data, data
289 return out 291 return out
290 292
291 @classmethod 293 @classmethod
292 def load_file(cls, filename): 294 def load_file(cls, filename):
293 """Loads the data from a file or return an empty instance.""" 295 """Loads the data from a file or return an empty instance."""
294 out = cls() 296 out = cls()
295 try: 297 try:
296 with open(filename, 'r') as f: 298 with open(filename, 'r') as f:
297 out = cls.load(json.load(f)) 299 out = cls.load(json.load(f))
298 logging.debug('Loaded %s(%s)' % (cls.__name__, filename)) 300 logging.debug('Loaded %s(%s)' % (cls.__name__, filename))
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 self.result = result 387 self.result = result
386 # Contains the data to ease developer's use-case but that is not strictly 388 # Contains the data to ease developer's use-case but that is not strictly
387 # necessary. 389 # necessary.
388 self.saved_state = saved_state 390 self.saved_state = saved_state
389 self.out_dir = out_dir 391 self.out_dir = out_dir
390 392
391 @classmethod 393 @classmethod
392 def load_files(cls, result_file, out_dir): 394 def load_files(cls, result_file, out_dir):
393 """Loads state from disk.""" 395 """Loads state from disk."""
394 assert os.path.isabs(result_file), result_file 396 assert os.path.isabs(result_file), result_file
395 assert result_file.rsplit('.', 1)[1] == 'result', result_file
396 return cls( 397 return cls(
397 result_file, 398 result_file,
398 Result.load_file(result_file), 399 Result.load_file(result_file),
399 SavedState.load_file(result_to_state(result_file)), 400 SavedState.load_file(result_to_state(result_file)),
400 out_dir) 401 out_dir)
401 402
402 def load_isolate(self, isolate_file, variables, error): 403 def load_isolate(self, isolate_file, variables, error):
403 """Updates self.result and self.saved_state with information loaded from a 404 """Updates self.result and self.saved_state with information loaded from a
404 .isolate file. 405 .isolate file.
405 406
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 return out 493 return out
493 494
494 495
495 def MODEcheck(_outdir, _state): 496 def MODEcheck(_outdir, _state):
496 """No-op.""" 497 """No-op."""
497 return 0 498 return 0
498 499
499 500
500 def MODEhashtable(outdir, state): 501 def MODEhashtable(outdir, state):
501 outdir = ( 502 outdir = (
502 outdir or os.path.join(os.path.dirname(state.resultdir), 'hashtable')) 503 outdir or os.path.join(state.resultdir, 'hashtable'))
503 if not os.path.isdir(outdir): 504 if not os.path.isdir(outdir):
504 os.makedirs(outdir) 505 os.makedirs(outdir)
505 for relfile, properties in state.result.files.iteritems(): 506 for relfile, properties in state.result.files.iteritems():
506 infile = os.path.join(state.root_dir, relfile) 507 infile = os.path.join(state.root_dir, relfile)
507 outfile = os.path.join(outdir, properties['sha-1']) 508 outfile = os.path.join(outdir, properties['sha-1'])
508 if os.path.isfile(outfile): 509 if os.path.isfile(outfile):
509 # Just do a quick check that the file size matches. No need to stat() 510 # Just do a quick check that the file size matches. No need to stat()
510 # again the input file, grab the value from the dict. 511 # again the input file, grab the value from the dict.
511 out_size = os.stat(outfile).st_size 512 out_size = os.stat(outfile).st_size
512 in_size = ( 513 in_size = (
513 state.result.files[infile].get('size') or 514 state.result.files[relfile].get('size') or
514 os.stat(infile).st_size) 515 os.stat(infile).st_size)
515 if in_size == out_size: 516 if in_size == out_size:
516 continue 517 continue
517 # Otherwise, an exception will be raised. 518 # Otherwise, an exception will be raised.
519 print 'Mapping %s -> %s' % (outfile, infile)
518 run_test_from_archive.link_file( 520 run_test_from_archive.link_file(
519 outfile, infile, run_test_from_archive.HARDLINK) 521 outfile, infile, run_test_from_archive.HARDLINK)
520 return 0 522 return 0
521 523
522 524
523 def MODEremap(outdir, state): 525 def MODEremap(outdir, state):
524 if not outdir: 526 if not outdir:
525 outdir = tempfile.mkdtemp(prefix='isolate') 527 outdir = tempfile.mkdtemp(prefix='isolate')
526 else: 528 else:
527 if not os.path.isdir(outdir): 529 if not os.path.isdir(outdir):
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 result_file, 745 result_file,
744 input_file, 746 input_file,
745 options.mode, 747 options.mode,
746 variables, 748 variables,
747 out_dir, 749 out_dir,
748 parser.error) 750 parser.error)
749 751
750 752
751 if __name__ == '__main__': 753 if __name__ == '__main__':
752 sys.exit(main()) 754 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | tools/isolate/isolate_smoke_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698