-
Notifications
You must be signed in to change notification settings - Fork 383
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
[tools] Add compilation database generator for Bazel #3226
Conversation
@@ -0,0 +1,255 @@ | |||
#!/usr/bin/env python3 |
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.
It would be better to rename this module and the upper directory to bazel_to_compile_commands
. It is more expressive than just compile_commands
.
Also it would be good to put this script into the bin
folder during the package phase similar to this:
Lines 49 to 57 in e02baa7
build_tu_collector: | |
$(MAKE) -C $(ROOT)/tools/tu_collector build | |
package_tu_collector: build_tu_collector package_dir_structure | |
# Copy tu_collector files. | |
cp -rp $(CC_TOOLS)/tu_collector/build/tu_collector/tu_collector $(CC_BUILD_LIB_DIR) && \ | |
chmod u+x $(CC_BUILD_LIB_DIR)/tu_collector/tu_collector.py && \ | |
cd $(CC_BUILD_DIR) && \ | |
ln -sf ../lib/python3/tu_collector/tu_collector.py bin/tu_collector |
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.
Thanks for reviewing @csordasmarton!
I'll check and update the patch as soon as I have time.
Meanwhile I have a few questions:
- Regarding the module name I think
bazel_to_compile_commands
has kind of wrong meaning, it is not a converter.
Probablybazel_compile_commands
would be better. Agree? - I put this module into
bazel
folder, is it OK? - How can find information about verification infrastructure you use?
Are there any guidelines? Check list?
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.
- Yes, you are right,
bazel_compile_commands
will be good. - You can put this into the
bazel
folder (tools/bazel/bazel_compile_commands/bazel_compile_commands.py
) - No, there isn't any guidline for this. This is how we built our others tools (https://github.com/Ericsson/codechecker/tree/master/tools, https://github.com/Ericsson/codechecker/tree/master/analyzer/tools). And it is good to be consistent in the whole repository.
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.
Done:
- Renamed to
bazel_compile_commands
- Using
bazel
folder - Added copying to
bin
folder
long_description = fh.read() | ||
|
||
setuptools.setup( | ||
name="bazel-compile-commands", |
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.
name="bazel-compile-commands", | |
name="bazel-to-compile-commands", |
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.
Done
parser.add_argument("-v", "--verbosity", | ||
default=0, | ||
action="count", | ||
help="increase output verbosity (e.g., -v or -vv)") |
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.
In other commands this option has no value, it will enabled the debug logging. Maybe we can use the same logic here too:
codechecker/tools/tu_collector/tu_collector/tu_collector.py
Lines 567 to 577 in e02baa7
parser.add_argument('-v', '--verbose', | |
action='store_true', | |
dest='verbose', | |
help="Enable debug level logging.") | |
args = parser.parse_args() | |
# --- Checking the existence of input files. --- # | |
if 'verbose' in args and args.verbose: | |
LOG.setLevel(logging.DEBUG) |
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.
Done:
- Verbosity option (
-v
or--verbose
) works the same way as intu_collector
tools/bazel/README.md
Outdated
make venv | ||
source $PWD/venv/bin/activate | ||
|
||
# Build and install plist-to-html package. |
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.
# Build and install plist-to-html package. | |
# Build and install bazel-to-compile-commands package. |
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.
Done
|
||
bazel_info = split_to_list(build_command)[0] + " info " |
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.
bazel_info = split_to_list(build_command)[0] + " info " | |
cmd = shlex.split(build_command) | |
bazel_info = cmd[0] + " info " |
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.
Yes, I agree that we can use shlex.split
however split_to_list
is more convenient and safer.
I would keep it if you dont mind.
logging.info("Bazel work dir: %s", bazel_work_dir) | ||
|
||
logging.info("Bazel build options: %s", build_command) | ||
data = bazel_aquery(build_command) |
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.
Use the cmd
here, so this function will expect a list instead of a string. And there will be no need to call the split function on the argument.
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.
Yes, I agree that we can use shlex.split
however split_to_list
is more convenient and safer.
I would keep it if you dont mind.
""" | ||
Run shell command | ||
""" | ||
cmd = split_to_list(command) |
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.
On the call side pass the command as a list of string and there will be no need to split the argument here.
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.
Yes, I agree that we can use shlex.split
however split_to_list
is more convenient and safer.
I would keep it if you dont mind.
if out: | ||
data = json.loads(out) | ||
return data | ||
else: | ||
return False |
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.
Now the function may return with None
(see the code above L101), a dictionary or a Boolean (False) value. Couldn't we return here with None if the output is empty?
if out: | |
data = json.loads(out) | |
return data | |
else: | |
return False | |
if out: | |
return json.loads(out) |
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.
Done
|
||
def get_full_path(file, directories): | ||
""" | ||
Return full path for a file and try to prepend directories |
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.
This function will return not only with the full path but the parent diectory too. It would be better to return only with the full path or None and use the os.path.dirname
to get the parent directory for the file if its not None on the call side.
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.
Done:
- Changed the name and docstring of the function since
get_full_path
is meisleading
Please also fix the commit message: |
6223890
to
22a168b
Compare
22a168b
to
54ecd04
Compare
d91df39
to
84e4174
Compare
Hi @csordasmarton, I've updated the patch upon comments. |
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.
I have some small comments otherwise its LGTM!
tools/bazel/.noserc
Outdated
stop=1 | ||
|
||
# do not capture stdout | ||
nocapture=1 |
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.
nocapture=1 | |
#nocapture=1 |
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.
Done
parser.add_argument("-b", "--build", | ||
help="bazel build command arguments") | ||
parser.add_argument("-v", "--verbosity", | ||
default=0, |
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.
I think the default log level should be 1 because if I run this command there will be no output at all and it can confuse the users: did this command run successfully or not?
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.
OK
Done
84e4174
to
e981664
Compare
The tool takes bazel build command as an input parameter and executes Bazel Action Query (bazel aquery) to extract all compile commands then saves them to compile_commands.json file.
e981664
to
3a3a928
Compare
Hi @csordasmarton, |
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.
It's LGTM! Thank you for your time that you implemented it 😊
Do you plan to add anything to this PR or can we merge it?
Thanks for review @csordasmarton! |
The tool takes bazel build command as an input parameter
and executes Bazel Action Query (bazel aquery)
to extract all compile commands then saves them
to compile_commands.json file.