-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Add "west gtags" extension #85984
Open
mbolivar
wants to merge
2
commits into
zephyrproject-rtos:main
Choose a base branch
from
mbolivar:west-gtags
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+152
−0
Open
Add "west gtags" extension #85984
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 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,98 @@ | ||
# Copyright (c) 2025 Qualcomm Innovation Center, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
"""gtags.py | ||
A west extension for creating tags files (GTAGS) for GNU Global. | ||
For more information on Global, see: https://www.gnu.org/software/global | ||
""" | ||
|
||
import argparse | ||
import os.path | ||
import subprocess | ||
import tempfile | ||
|
||
from west.commands import WestCommand | ||
|
||
|
||
class Gtags(WestCommand): | ||
def __init__(self): | ||
super().__init__( | ||
"gtags", | ||
"create a GNU Global tags file for the current workspace", | ||
"""\ | ||
Indexes source code files in the west workspace using GNU Global's | ||
"gtags" tool. For more information on Global and gtags, see: | ||
https://www.gnu.org/software/global/ | ||
The index can be useful to find definitions of functions, etc., | ||
especially across repository boundaries. One example is | ||
finding the definition of a vendor HAL function that is | ||
provided by a Zephyr module for the HAL. | ||
By default, this west command only indexes files that are | ||
tracked by git projects defined in the west. Inactive west | ||
projects are ignored by default. For more information on | ||
projects etc., see the west documentation.""", | ||
) | ||
|
||
def do_add_parser(self, parser_adder): | ||
parser = parser_adder.add_parser( | ||
self.name, | ||
help=self.help, | ||
description=self.description, | ||
formatter_class=argparse.RawDescriptionHelpFormatter, | ||
) | ||
|
||
parser.add_argument( | ||
"projects", | ||
nargs="*", | ||
metavar="PROJECT", | ||
help="""Name of west project to index, or | ||
its path. May be given more than once. Use | ||
"manifest" to refer to the manifest | ||
repository""", | ||
) | ||
|
||
return parser | ||
|
||
def do_run(self, args, unknown_args): | ||
all_files = [] | ||
for project in self.manifest.get_projects(args.projects): | ||
all_files.extend(self.files_in_project(project)) | ||
|
||
with tempfile.TemporaryDirectory(suffix="gtags") as d: | ||
gtags_files = os.path.join(d, "gtags.files") | ||
with open(gtags_files, "w") as f: | ||
# Due to what looks like a limitation in GNU Global, | ||
# this won't work if there are newlines in file names. | ||
# Unlike xargs and other commands, though, gtags | ||
# doesn't seem to have a way to accept a NUL-delimited | ||
# list of input file; its manpage says file names must | ||
# be delimited by newlines. | ||
f.write("\n".join(all_files)) | ||
subprocess.run( | ||
# Note that "gtags -f -" and passing files via stdin | ||
# could run into issues on windows, and there seem to | ||
# be win32 builds of global out there | ||
["gtags", "-f", gtags_files], | ||
cwd=self.manifest.topdir, | ||
check=True, | ||
) | ||
|
||
def files_in_project(self, project): | ||
if not project.is_cloned() or not self.manifest.is_active(project): | ||
return [] | ||
ls_files = ( | ||
project.git(["ls-files", "**"], capture_stdout=True).stdout.decode("utf-8").splitlines() | ||
) | ||
ret = [] | ||
for filename in ls_files: | ||
absolute = os.path.join(project.abspath, filename) | ||
# Filter out directories from the git ls-files output. | ||
# There didn't seem to be a way to tell it to do that by | ||
# itself. | ||
if os.path.isfile(absolute): | ||
ret.append(absolute) | ||
return ret |
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.
Would it make sense to allow unknown arguments and pass these to the
gtags
command being called?