-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-1722: [C++] Add linting script to find C++/CLI incompatibilities #2225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
11635d3
Add lint_cpp_cli.py script, fix issues found
wesm ceb2dd7
Use common env variables in travis_lint.sh
wesm 7adcc27
Work around confounding toolchain variables in travis_lint.sh
wesm 8d94d7f
Fix cpplint error
wesm 43c2cce
Fix bug in lint script, fix other C++/CLI issues
wesm 824ef0b
Location of generated Plasma flatbuffers files changed, did not reali…
wesm 3b5a16a
Remove print statements
wesm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| #!/usr/bin/env python | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| import argparse | ||
| import re | ||
| import os | ||
|
|
||
| parser = argparse.ArgumentParser( | ||
| description="Check for illegal headers for C++/CLI applications") | ||
| parser.add_argument("source_path", | ||
| help="Path to source code") | ||
| arguments = parser.parse_args() | ||
|
|
||
|
|
||
| _STRIP_COMMENT_REGEX = re.compile('(.+)?(?=//)') | ||
|
|
||
|
|
||
| def _strip_comments(line): | ||
| m = _STRIP_COMMENT_REGEX.match(line) | ||
| if not m: | ||
| return line | ||
| else: | ||
| return m.group(0) | ||
|
|
||
|
|
||
| def lint_file(path): | ||
| fail_rules = [ | ||
| (lambda x: '<mutex>' in x, 'Uses <mutex>'), | ||
| (lambda x: 'nullptr' in x, 'Uses nullptr') | ||
| ] | ||
|
|
||
| with open(path) as f: | ||
| for i, line in enumerate(f): | ||
| stripped_line = _strip_comments(line) | ||
| for rule, why in fail_rules: | ||
| if rule(stripped_line): | ||
| raise Exception('File {0} failed C++/CLI lint check: {1}\n' | ||
| 'Line {2}: {3}' | ||
| .format(path, why, i + 1, line)) | ||
|
|
||
|
|
||
| EXCLUSIONS = [ | ||
| 'arrow/util/macros.h', | ||
| 'arrow/util/parallel.h', | ||
| 'arrow/io/hdfs-internal.h' | ||
| ] | ||
|
|
||
|
|
||
| for dirpath, _, filenames in os.walk(arguments.source_path): | ||
| for filename in filenames: | ||
| full_path = os.path.join(dirpath, filename) | ||
|
|
||
| exclude = False | ||
| for exclusion in EXCLUSIONS: | ||
| if exclusion in full_path: | ||
| exclude = True | ||
| break | ||
|
|
||
| if exclude: | ||
| continue | ||
|
|
||
| # Only run on header files | ||
| if filename.endswith('.h'): | ||
| lint_file(full_path) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'(.+?)?(?=//)'will be better fora // b // ccase but it's too trivial. We will never write such code :-)