| OLD | NEW |
| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 | 31 |
| 32 def relpath(path, root): | 32 def relpath(path, root): |
| 33 """os.path.relpath() that keeps trailing slash.""" | 33 """os.path.relpath() that keeps trailing slash.""" |
| 34 out = os.path.relpath(path, root) | 34 out = os.path.relpath(path, root) |
| 35 if path.endswith('/'): | 35 if path.endswith('/'): |
| 36 out += '/' | 36 out += '/' |
| 37 return out | 37 return out |
| 38 | 38 |
| 39 | 39 |
| 40 def to_relative(path, root, relative): |
| 41 """Converts any absolute path to a relative path, only if under root.""" |
| 42 if path.startswith(root): |
| 43 logging.info('%s starts with %s' % (path, root)) |
| 44 path = os.path.relpath(path, relative) |
| 45 else: |
| 46 logging.info('%s not under %s' % (path, root)) |
| 47 return path |
| 48 |
| 49 |
| 40 def separate_inputs_command(args, root, files): | 50 def separate_inputs_command(args, root, files): |
| 41 """Strips off the command line from the inputs. | 51 """Strips off the command line from the inputs. |
| 42 | 52 |
| 43 gyp provides input paths relative to cwd. Convert them to be relative to root. | 53 gyp provides input paths relative to cwd. Convert them to be relative to root. |
| 44 OptionParser kindly strips off '--' from sys.argv if it's provided and that's | 54 OptionParser kindly strips off '--' from sys.argv if it's provided and that's |
| 45 the first non-arg value. Manually look up if it was present in sys.argv. | 55 the first non-arg value. Manually look up if it was present in sys.argv. |
| 46 """ | 56 """ |
| 47 cmd = [] | 57 cmd = [] |
| 48 if '--' in args: | 58 if '--' in args: |
| 49 i = args.index('--') | 59 i = args.index('--') |
| (...skipping 21 matching lines...) Expand all Loading... |
| 71 | 81 |
| 72 infiles = tree_creator.expand_directories( | 82 infiles = tree_creator.expand_directories( |
| 73 indir, infiles, lambda x: re.match(r'.*\.(svn|pyc)$', x)) | 83 indir, infiles, lambda x: re.match(r'.*\.(svn|pyc)$', x)) |
| 74 | 84 |
| 75 # Note the relative current directory. | 85 # Note the relative current directory. |
| 76 # In general, this path will be the path containing the gyp file where the | 86 # In general, this path will be the path containing the gyp file where the |
| 77 # target was defined. This relative directory may be created implicitely if a | 87 # target was defined. This relative directory may be created implicitely if a |
| 78 # file from this directory is needed to run the test. Otherwise it won't be | 88 # file from this directory is needed to run the test. Otherwise it won't be |
| 79 # created and the process creation will fail. It's up to the caller to create | 89 # created and the process creation will fail. It's up to the caller to create |
| 80 # this directory manually before starting the test. | 90 # this directory manually before starting the test. |
| 81 relative_cwd = os.path.relpath(os.getcwd(), indir) | 91 cwd = os.getcwd() |
| 92 relative_cwd = os.path.relpath(cwd, indir) |
| 93 |
| 94 # Workaround make behavior of passing absolute paths. |
| 95 cmd = [to_relative(i, indir, cwd) for i in cmd] |
| 82 | 96 |
| 83 if not cmd: | 97 if not cmd: |
| 84 # Note that it is exactly the reverse of relative_cwd. | 98 # Note that it is exactly the reverse of relative_cwd. |
| 85 cmd = [os.path.join(os.path.relpath(indir, os.getcwd()), infiles[0])] | 99 cmd = [os.path.join(os.path.relpath(indir, cwd), infiles[0])] |
| 86 if cmd[0].endswith('.py'): | 100 if cmd[0].endswith('.py'): |
| 87 cmd.insert(0, sys.executable) | 101 cmd.insert(0, sys.executable) |
| 88 | 102 |
| 89 # Only hashtable mode really needs the sha-1. | 103 # Only hashtable mode really needs the sha-1. |
| 90 dictfiles = tree_creator.process_inputs( | 104 dictfiles = tree_creator.process_inputs( |
| 91 indir, infiles, mode == 'hashtable', read_only) | 105 indir, infiles, mode == 'hashtable', read_only) |
| 92 | 106 |
| 93 if not outdir: | 107 if not outdir: |
| 94 outdir = os.path.dirname(resultfile) | 108 outdir = os.path.dirname(resultfile) |
| 95 result = mode_fn(outdir, indir, dictfiles, read_only, cmd, relative_cwd) | 109 result = mode_fn(outdir, indir, dictfiles, read_only, cmd, relative_cwd) |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 options.mode, | 242 options.mode, |
| 229 options.read_only, | 243 options.read_only, |
| 230 cmd) | 244 cmd) |
| 231 except tree_creator.MappingError, e: | 245 except tree_creator.MappingError, e: |
| 232 print >> sys.stderr, str(e) | 246 print >> sys.stderr, str(e) |
| 233 return 1 | 247 return 1 |
| 234 | 248 |
| 235 | 249 |
| 236 if __name__ == '__main__': | 250 if __name__ == '__main__': |
| 237 sys.exit(main()) | 251 sys.exit(main()) |
| OLD | NEW |