Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright (c) 2014 Google Inc. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | """ |
| 8 | Make sure overwriting read-only files works as expected (via win-tool). |
| 9 | """ |
| 10 | |
| 11 | import TestGyp |
| 12 | |
| 13 | import filecmp |
| 14 | import os |
| 15 | import stat |
| 16 | import sys |
| 17 | |
| 18 | if sys.platform == 'win32': |
| 19 | test = TestGyp.TestGyp(formats=['ninja']) |
| 20 | |
| 21 | # First, create the source files. |
| 22 | os.makedirs('subdir') |
| 23 | read_only_files = ['read-only-file', 'subdir/A', 'subdir/B', 'subdir/C'] |
| 24 | for f in read_only_files: |
| 25 | test.write(f, 'source_contents') |
| 26 | test.chmod(f, stat.S_IREAD) |
| 27 | if os.access(f, os.W_OK): |
| 28 | test.fail_test() |
| 29 | |
| 30 | # Second, create the read-only destination files. Note that we are creating |
| 31 | # them where the ninja and win-tool will try to copy them to, in order to test |
| 32 | # that copies overwrite the files. |
| 33 | os.makedirs(test.built_file_path('dest/subdir')) |
| 34 | for f in read_only_files: |
| 35 | f = os.path.join('dest', f) |
| 36 | test.write(test.built_file_path(f), 'SHOULD BE OVERWRITTEN') |
| 37 | test.chmod(test.built_file_path(f), stat.S_IREAD) |
| 38 | # Ensure not writable. |
| 39 | if os.access(test.built_file_path(f), os.W_OK): |
| 40 | test.fail_test() |
| 41 | |
| 42 | test.run_gyp('copies_readonly_files.gyp') |
| 43 | test.build('copies_readonly_files.gyp') |
| 44 | |
| 45 | # Check the destination files were overwritten by ninja. |
| 46 | for f in read_only_files: |
| 47 | f = os.path.join('dest', f) |
| 48 | test.must_contain(test.built_file_path(f), 'source_contents') |
| 49 | |
| 50 | # This will fail if the files are not the same mode or contents. |
| 51 | for f in read_only_files: |
| 52 | if not filecmp.cmp(f, test.built_file_path(os.path.join('dest', f))): |
| 53 | test.fail_test() |
| 54 | |
| 55 | test.pass_test() |