|
|
@ -14,6 +14,7 @@ |
|
|
|
# See the License for the specific language governing permissions and |
|
|
|
# See the License for the specific language governing permissions and |
|
|
|
# limitations under the License. |
|
|
|
# limitations under the License. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import print_function |
|
|
|
import argparse |
|
|
|
import argparse |
|
|
|
import os |
|
|
|
import os |
|
|
|
import os.path |
|
|
|
import os.path |
|
|
@ -62,22 +63,22 @@ class GuardValidator(object): |
|
|
|
'...\n') + ('#endif /* {2} */' |
|
|
|
'...\n') + ('#endif /* {2} */' |
|
|
|
if c_core_header else '#endif // {2}') |
|
|
|
if c_core_header else '#endif // {2}') |
|
|
|
if not match_txt: |
|
|
|
if not match_txt: |
|
|
|
print invalid_guards_msg_template.format(fpath, regexp.pattern, |
|
|
|
print(invalid_guards_msg_template.format(fpath, regexp.pattern, |
|
|
|
build_valid_guard(fpath)) |
|
|
|
build_valid_guard(fpath))) |
|
|
|
return fcontents |
|
|
|
return fcontents |
|
|
|
|
|
|
|
|
|
|
|
print( |
|
|
|
print(( |
|
|
|
'{}: Wrong preprocessor guards (RE {}):' |
|
|
|
'{}: Wrong preprocessor guards (RE {}):' |
|
|
|
'\n\tFound {}, expected {}').format(fpath, regexp.pattern, |
|
|
|
'\n\tFound {}, expected {}').format(fpath, regexp.pattern, |
|
|
|
match_txt, correct) |
|
|
|
match_txt, correct)) |
|
|
|
if fix: |
|
|
|
if fix: |
|
|
|
print 'Fixing {}...\n'.format(fpath) |
|
|
|
print('Fixing {}...\n'.format(fpath)) |
|
|
|
fixed_fcontents = re.sub(match_txt, correct, fcontents) |
|
|
|
fixed_fcontents = re.sub(match_txt, correct, fcontents) |
|
|
|
if fixed_fcontents: |
|
|
|
if fixed_fcontents: |
|
|
|
self.failed = False |
|
|
|
self.failed = False |
|
|
|
return fixed_fcontents |
|
|
|
return fixed_fcontents |
|
|
|
else: |
|
|
|
else: |
|
|
|
print |
|
|
|
print() |
|
|
|
return fcontents |
|
|
|
return fcontents |
|
|
|
|
|
|
|
|
|
|
|
def check(self, fpath, fix): |
|
|
|
def check(self, fpath, fix): |
|
|
@ -89,7 +90,7 @@ class GuardValidator(object): |
|
|
|
|
|
|
|
|
|
|
|
match = self.ifndef_re.search(fcontents) |
|
|
|
match = self.ifndef_re.search(fcontents) |
|
|
|
if not match: |
|
|
|
if not match: |
|
|
|
print 'something drastically wrong with: %s' % fpath |
|
|
|
print('something drastically wrong with: %s' % fpath) |
|
|
|
return False # failed |
|
|
|
return False # failed |
|
|
|
if match.lastindex is None: |
|
|
|
if match.lastindex is None: |
|
|
|
# No ifndef. Request manual addition with hints |
|
|
|
# No ifndef. Request manual addition with hints |
|
|
|