Skip to content
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

Update run_clang_tidy.sh to support bazel targets with '@repository' prefixes #15604

Merged
merged 3 commits into from
Mar 23, 2021

Conversation

murray-stripe
Copy link
Contributor

Commit Message:

Support running run_clang_tidy.sh when Envoy is a sub-workspace within a
project (such as used when developing custom filters and nesting Envoy as a
git-submodule). This can be done by setting the compilation DB targets as an
environment variable:

COMP_DB_TARGETS="@envoy//source/... @envoy//test/... @envoy//tools/..."

Additional Description: In order to build from the SRCDIR (not ENVOY_SRCDIR), such as with the envoy-filter-example, need to be able to specify a repository on the targets built by gen_compilation_database.py. Simplest way to enable this is to allow for specifying the comp-db targets.

Risk Level: Low. Default maintains current behavior
Testing: Tested manually in docker container with setup similar to envoy-filter-example repo via:

SRCDIR='/src' COMP_DB_TARGETS="@envoy//source/... @envoy//test/... @envoy//tools/... //filters/..." bash -ex ./envoy/ci/do_ci.sh 'bazel.clang_tidy' '//filters/...'

Docs Changes: n/a
Release Notes: n/a
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Deprecated:]
[Optional API Considerations:]

Support running `run_clang_tidy.sh` when Envoy is a sub-workspace within a
project (such as used when developing custom filters and nesting Envoy as a
git-submodule). This can be done by setting the compilation DB targets as an
environment variable:
```bash
COMP_DB_TARGETS="@envoy//source/... @envoy//test/... @envoy//tools/..."
```
```

Signed-off-by: John Murray <[email protected]>

Signed-off-by: John Murray <[email protected]>
@murray-stripe murray-stripe changed the title Update run_clang_tidy.sh to support repository Update run_clang_tidy.sh to support bazel targets with '@repository' prefixes Mar 22, 2021
@lizan lizan self-assigned this Mar 22, 2021
lizan
lizan previously approved these changes Mar 22, 2021
@@ -26,7 +26,7 @@ echo "Generating compilation database..."

# bazel build need to be run to setup virtual includes, generating files which are consumed
# by clang-tidy
"${ENVOY_SRCDIR}/tools/gen_compilation_database.py" --include_headers
"${ENVOY_SRCDIR}/tools/gen_compilation_database.py" --include_headers ${COMP_DB_TARGETS:+${COMP_DB_TARGETS[@]}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im not sure but i think the array expansion wont work here - ill check further

Copy link
Member

@phlax phlax Mar 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arrays arent carried in the env vars so there isnt a way that "${COMP_DB_TARGETS[@]}" would ever be evaluated as one (unless either this script was sourced, or sourced another script that set this)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set this in an env-var with 4 targets and tested it (as above in PR description) and it worked. Are you saying that if I set and exported the value, you would not expect it to work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i created a file with the following:

#!/bin/bash

FOO=${COMP_DB_TARGETS:+${COMP_DB_TARGETS[@]}}

echo "$FOO"

and then did the following:

$ export COMP_DB_TARGETS="xyz"
$ ./runfoo
xyz
$ export COMP_DB_TARGETS=("abc" "xyz")
$ ./runfoo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if COMP_DB_TARGETS is an array it wont work

i think you need to do something like

read -ra COMP_DB_TARGETS <<< "$COMP_DB_TARGETS"

if you want to use an array

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and then you would also need to set it to a string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have this currently working in our internal CI system with the following:

COMP_DB_TARGETS="@envoy//source/... @envoy//test/... @envoy//tools/... //filters/..."
export COMP_DB_TARGETS

bash -ex ./envoy/ci/do_ci.sh 'bazel.clang_tidy' '//filters/...'

And then with -x on run_clang_tidy.sh I see:

+ /src/envoy/tools/gen_compilation_database.py --include_headers @envoy//source/... @envoy//test/... @envoy//tools/... //filters/...

Copy link
Member

@phlax phlax Mar 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its set to a string - my point is $COMP_DB_TARGETS[@] is wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, gotcha. I'll update to not do any array expansion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh i think you do want array expansion
i added a py script (similar to what is happening in this file)

export COMP_DB_TARGETS="abc xyz"
$ ./runfoo
abc xyz
['./runfoo.py', 'abc xyz']

if you want the args to be separate at least

Copy link
Member

@phlax phlax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you clarify that this works - in my (reduced) testing this would always evaluate to ""

@murray-stripe
Copy link
Contributor Author

@phlax confirmed that this works in our internal CI system. Currently defining the targets as a string, so probably don't need to use array expansion syntax.

Signed-off-by: John Murray <[email protected]>
Signed-off-by: John Murray <[email protected]>
@@ -26,7 +26,7 @@ echo "Generating compilation database..."

# bazel build need to be run to setup virtual includes, generating files which are consumed
# by clang-tidy
"${ENVOY_SRCDIR}/tools/gen_compilation_database.py" --include_headers
"${ENVOY_SRCDIR}/tools/gen_compilation_database.py" --include_headers ${COMP_DB_TARGETS:+$COMP_DB_TARGETS}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just ${COMP_DB_TARGETS} ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above comment about separate args

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shellcheck complains
image

but then quoting it will register as an empty-string target in the Python script.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I suppose the "expand only if it is defined" is the most appropriate thing to do in this case. I think? :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you need to what i suggested above with read -ra

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Legitimate question, what is the difference between that vs what I have currently?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a) works b) shellcheck is happy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but that's also the case with what I currently have (using :+ syntax). Happy to make the update if it's preferred for stylistic reasons, just trying to understand the rationale for future changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its the right way to do it

stepping through

  • in shell you set a string
  • in bash script split string into array
  • in python receive args as separate args

Copy link
Member

@phlax phlax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @murray-stripe lgtm

Copy link
Member

@phlax phlax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(oops, meant to approve)

@lizan lizan merged commit 531c6ac into envoyproxy:main Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants