-
Notifications
You must be signed in to change notification settings - Fork 140
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
Linter integration #1143
Linter integration #1143
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ BAZEL=${BAZEL:-bazel} | |
BUILDIFIER=${BUILDIFIER:-buildifier} | ||
BUILDOZER=${BUILDOZER:-buildozer} | ||
CLANG_FORMAT=${CLANG_FORMAT:-clang-format} | ||
AUTOPEP8=${AUTOPEP8:-autopep8} | ||
|
||
if test -t 1; then | ||
ncolors=$(tput colors) | ||
|
@@ -85,12 +86,41 @@ function run_buildozer() { | |
} | ||
|
||
function run_enumerate_tests() { | ||
TARGETS="$($BAZEL query --deleted_packages=//gapii/fuchsia --output label 'kind(".*_test rule", //...)' | sort -t: -k1,1 | awk '{print " \""$0"\","}')" | ||
# Get all the test targets in all packages except gapii/fuschia | ||
TARGETS=$($BAZEL query --deleted_packages=//gapii/fuchsia --output label 'kind(".*_test rule", //...)') | ||
|
||
# Exclude linting targets from tests | ||
TARGETS=$(echo "$TARGETS" | grep -v ":lint_") | ||
|
||
# Sort the test targets alphabetically | ||
TARGETS=$(echo "$TARGETS" | sort -t: -k1,1) | ||
|
||
# Indent the test target names to match the BUILD.bazel file | ||
TARGETS=$(echo "$TARGETS" | awk '{print " \""$0"\","}') | ||
|
||
OUT=$(mktemp) | ||
cp BUILD.bazel $OUT | ||
cat $OUT | awk -v "targets=${TARGETS//$'\n'/\\n}" 'begin {a=0} /__END_TESTS/ {a=0} { if (a==0) print $0;} /__BEGIN_TESTS/ { a=1; print targets }' > BUILD.bazel | ||
} | ||
|
||
function run_enumerate_lints() { | ||
# Get all the linting test targets in Vulkan generator | ||
TARGETS=$($BAZEL query 'attr(generator_function, py_lint, //vulkan_generator/...)') | ||
|
||
# Exclude the sub targets to prevent repetation | ||
TARGETS=$(echo "$TARGETS" | grep -v "_flake8" | grep -v "_mypy" | grep -v "_pylint") | ||
|
||
# Sort the linting targets alphabetically | ||
TARGETS=$(echo "$TARGETS" | sort -t: -k1,1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we factor this common stuff out somehow? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thought of but almost every function there is a singular presubmit case. So the benefit of splitting it have not justified break the pattern for me. Instead I put them in a way to make the process clearer for both case. |
||
|
||
# Indent the linting target names to match the BUILD.bazel file | ||
TARGETS=$(echo "$TARGETS" | awk '{print " \""$0"\","}') | ||
|
||
OUT=$(mktemp) | ||
cp BUILD.bazel $OUT | ||
cat $OUT | awk -v "targets=${TARGETS//$'\n'/\\n}" 'begin {a=0} /__END_LINT/ {a=0} { if (a==0) print $0;} /__BEGIN_LINT/ { a=1; print targets }' > BUILD.bazel | ||
} | ||
|
||
function run_gazelle() { | ||
echo # TODO: figure out a way to make bazel not print anything. | ||
$BAZEL run gazelle | ||
|
@@ -102,30 +132,40 @@ function run_gofmt() { | |
find . -name "*.go" | xargs $GOFMT -w | ||
} | ||
|
||
function run_autopep8() { | ||
$AUTOPEP8 --global-config=tools/build/python/pep8 -r --in-place vulkan_generator | ||
} | ||
|
||
# Ensure we are clean to start out with. | ||
check "git workspace must be clean" true | ||
|
||
# Check copyright headers | ||
# # Check copyright headers | ||
check copyright-headers run_copyright_headers | ||
|
||
# Check clang-format. | ||
check clang-format run_clang_format | ||
|
||
# Check buildifier. | ||
# # Check buildifier. | ||
check buildifier run_buildifier | ||
|
||
# Check bazel style. | ||
# # Check bazel style. | ||
check "buildozer fix" run_buildozer | ||
|
||
# Check that the //:tests target contains all tests. | ||
check "//:tests contains all tests" run_enumerate_tests | ||
|
||
# Check that "//:lint" target contains all lints | ||
check "//:lint contains all lints" run_enumerate_lints | ||
|
||
# Check gazelle. | ||
check "gazelle" run_gazelle | ||
|
||
# Check gofmt. This needs to be done AFTER Gazelle, such that Bazel has | ||
# installed its Go SDK (as a dependency to run Gazelle). | ||
check gofmt run_gofmt | ||
|
||
# Check python Formatter(autopep8) | ||
check autopep8 run_autopep8 | ||
|
||
# Check clang-format. | ||
check clang-format run_clang_format | ||
|
||
echo | ||
echo "${green}All check completed successfully.$normal" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (C) 2022 Google Inc. | ||
# | ||
# Licensed 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. | ||
|
||
|
||
[flake8] | ||
ignore=E501 # Max line length is already checked by pylint |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright (C) 2022 Google Inc. | ||
# | ||
# Licensed 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 sys | ||
from flake8.main import cli as flake8_cli | ||
|
||
|
||
if __name__ == "__main__": | ||
flake8_cli.main(sys.argv[1:]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright (C) 2022 Google Inc. | ||
# | ||
# Licensed 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 sys | ||
from mypy import main as mypy_main | ||
|
||
|
||
if __name__ == "__main__": | ||
mypy_main.main(None, sys.stdout, sys.stderr, sys.argv[1:], clean_exit=True) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (C) 2022 Google Inc. | ||
# | ||
# Licensed 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. | ||
|
||
|
||
[mypy] | ||
show_column_numbers=True | ||
pretty=False | ||
follow_imports=silent | ||
|
||
# Unless you are 110% sure, *NEVER* change this option | ||
# It will break both the type system and import discovery of mypy | ||
ignore_missing_imports=False |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright (C) 2022 Google Inc. | ||
# | ||
# Licensed 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. | ||
|
||
[pep8] | ||
max-line-length = 120 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
pytest==7.1.2 | ||
pylint==2.13.8 | ||
mypy==0.950 | ||
flake8==4.0.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,4 +47,7 @@ py_binary( | |
py_lint( | ||
name = "lint", | ||
srcs = glob(["*.py"]), | ||
deps = [ | ||
"//vulkan_generator", | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,7 @@ py_library( | |
py_lint( | ||
name = "lint", | ||
srcs = glob(["*.py"]), | ||
deps = [ | ||
"codegen_utils", | ||
], | ||
) |
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.
Do we need a comment saying do not remove?
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.
Well, it is very easy to remove a test from bazel and not catch its missing. I just want to ensure that no one comes and says "why this is here" and remove it without thinking the implications. Having it there has no harm.