Alexandre Rames | b78f139 | 2016-07-01 14:22:22 +0100 | [diff] [blame] | 1 | # Copyright 2014, VIXL authors |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 2 | # All rights reserved. |
| 3 | # |
| 4 | # Redistribution and use in source and binary forms, with or without |
| 5 | # modification, are permitted provided that the following conditions are met: |
| 6 | # |
| 7 | # * Redistributions of source code must retain the above copyright notice, |
| 8 | # this list of conditions and the following disclaimer. |
| 9 | # * Redistributions in binary form must reproduce the above copyright notice, |
| 10 | # this list of conditions and the following disclaimer in the documentation |
| 11 | # and/or other materials provided with the distribution. |
| 12 | # * Neither the name of ARM Limited nor the names of its contributors may be |
| 13 | # used to endorse or promote products derived from this software without |
| 14 | # specific prior written permission. |
| 15 | # |
| 16 | # THIS SOFTWARE IS PROVIDED BY ARM LIMITED AND CONTRIBUTORS "AS IS" AND ANY |
| 17 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | # DISCLAIMED. IN NO EVENT SHALL ARM LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 21 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
| 22 | # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 23 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 24 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 25 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | |
| 27 | import re |
| 28 | import util |
| 29 | import os.path |
Jacob Bramley | e52f29d | 2018-08-15 11:07:51 +0100 | [diff] [blame] | 30 | from pipes import quote |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 31 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 32 | def is_git_repository_root(path): |
Jacob Bramley | e52f29d | 2018-08-15 11:07:51 +0100 | [diff] [blame] | 33 | command = 'git -C ' + quote(path) + ' rev-parse --show-toplevel' |
| 34 | status, toplevel = util.getstatusoutput(command) |
| 35 | if status != 0: return False |
| 36 | return os.path.samefile(toplevel, path) |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 37 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 38 | def get_tracked_files(): |
armvixl | 330dc71 | 2014-11-25 10:38:32 +0000 | [diff] [blame] | 39 | command = 'git ls-tree HEAD -r --full-tree --name-only' |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 40 | |
armvixl | 330dc71 | 2014-11-25 10:38:32 +0000 | [diff] [blame] | 41 | status, tracked = util.getstatusoutput(command) |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 42 | if status != 0: util.abort('Failed to list tracked files.') |
| 43 | |
| 44 | return tracked |
| 45 | |
| 46 | |
| 47 | # Get untracked files in src/, test/, and tools/. |
| 48 | def get_untracked_files(): |
| 49 | status, output = util.getstatusoutput('git status -s') |
| 50 | if status != 0: util.abort('Failed to get git status.') |
| 51 | |
| 52 | untracked_regexp = re.compile('\?\?.*(src/|test/|tools/).*(.cc$|.h$)') |
| 53 | files_in_watched_folder = lambda n: untracked_regexp.search(n) != None |
| 54 | untracked_files = filter(files_in_watched_folder, output.split('\n')) |
| 55 | |
| 56 | return untracked_files |