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

Ignore anonymous tags in symbols_ctags #9

Merged
merged 6 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ This utility is designed to work on Linux and POSIX OS with these utilities:
- xgettext that comes with GNU gettext.
- universal ctags, version 5.9 or higher, built with JSON support.

On Debian systems run this::
On Debian systems run this::

sudo apt-get install universal-ctags gettext

On MacOS systems run this::
pombredanne marked this conversation as resolved.
Show resolved Hide resolved

brew install universal-ctags gettext

To get started:
~~~~~~~~~~~~~~~~
Expand Down
54 changes: 30 additions & 24 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,36 @@ jobs:
sudo apt-get install universal-ctags gettext
venv/bin/pytest -n 2 -vvs

# - template: etc/ci/azure-posix.yml
# parameters:
# job_name: macos11_cpython
# image_name: macOS-11
# python_versions: ['3.8', '3.9', '3.10', '3.11', '3.12']
# test_suites:
# all: venv/bin/pytest -n 2 -vvs
#
# - template: etc/ci/azure-posix.yml
# parameters:
# job_name: macos12_cpython
# image_name: macOS-12
# python_versions: ['3.8', '3.9', '3.10', '3.11', '3.12']
# test_suites:
# all: venv/bin/pytest -n 2 -vvs
#
# - template: etc/ci/azure-posix.yml
# parameters:
# job_name: macos13_cpython
# image_name: macOS-13
# python_versions: ['3.8', '3.9', '3.10', '3.11', '3.12']
# test_suites:
# all: venv/bin/pytest -n 2 -vvs
#
- template: etc/ci/azure-posix.yml
parameters:
job_name: macos11_cpython
image_name: macOS-11
python_versions: ['3.8', '3.9', '3.10', '3.11', '3.12']
test_suites:
all: |
brew install universal-ctags gettext
venv/bin/pytest -n 2 -vvs

- template: etc/ci/azure-posix.yml
parameters:
job_name: macos12_cpython
image_name: macOS-12
python_versions: ['3.8', '3.9', '3.10', '3.11', '3.12']
test_suites:
all: |
brew install universal-ctags gettext
venv/bin/pytest -n 2 -vvs

- template: etc/ci/azure-posix.yml
parameters:
job_name: macos13_cpython
image_name: macOS-13
python_versions: ['3.8', '3.9', '3.10', '3.11', '3.12']
test_suites:
all: |
brew install universal-ctags gettext
venv/bin/pytest -n 2 -vvs

# - template: etc/ci/azure-win.yml
# parameters:
# job_name: win2019_cpython
Expand Down
11 changes: 9 additions & 2 deletions src/source_inpector/symbols_ctags.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import json
import logging
import re

import attr
from commoncode import command
Expand All @@ -32,7 +33,7 @@ class CtagsSymbolScannerPlugin(ScanPlugin):
"""

resource_attributes = dict(
symbols=attr.ib(default=attr.Factory(list), repr=False),
source_symbols=attr.ib(default=attr.Factory(list), repr=False),
)

options = [
Expand All @@ -57,7 +58,7 @@ def get_symbols(location, **kwargs):
"""
Return a mapping of symbols for a source file at ``location``.
"""
return dict(symbols=list(collect_symbols(location=location)))
return dict(source_symbols=list(collect_symbols(location=location)))


def collect_symbols(location):
Expand Down Expand Up @@ -87,12 +88,18 @@ def collect_symbols(location):
"typeref",
}

ignored_anon_tag = re.compile(r"__anon[0-9a-f]+")

for line in result.splitlines(False):
line = line.strip()
if not line:
continue
tag = json.loads(line)

# Ignore the anonymous tags.
if "name" in tag and ignored_anon_tag.match(tag["name"]):
keshav-space marked this conversation as resolved.
Show resolved Hide resolved
continue

# only keep some fields
# see ctags --output-format=json --list-fields for a full list
yield {k: v for k, v in tag.items() if k in supported_fields}
Expand Down
28 changes: 1 addition & 27 deletions tests/data/symbols_ctags/if_ath.c-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"path": "if_ath.c",
"type": "file",
"symbols": [
"source_symbols": [
{
"name": "AR5K_AR5212_STA_ID1",
"pattern": "/^#define AR5K_AR5212_STA_ID1 /",
Expand Down Expand Up @@ -566,32 +566,6 @@
"file": true,
"kind": "macro"
},
{
"name": "anonymous",
"pattern": "/^enum {$/",
"file": true,
"kind": "enum"
},
{
"name": "anonymous",
"pattern": "/^enum {$/",
"file": true,
"kind": "enum"
},
{
"name": "anonymous",
"pattern": "/^\tstatic const struct {$/",
"file": true,
"kind": "struct",
"scope": "ath_setcurmode",
"scopeKind": "function"
},
{
"name": "anonymous",
"pattern": "/^enum {$/",
"file": true,
"kind": "enum"
},
{
"name": "ar_device",
"pattern": "/^ar_device(int devid)$/",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/symbols_ctags/test3.cpp-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"path": "test3.cpp",
"type": "file",
"symbols": [
"source_symbols": [
{
"name": "EIP_IN_SIGNAL_FRAME",
"pattern": "/^#define EIP_IN_SIGNAL_FRAME /",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_symbols_ctags.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def clean_ctags(json_scan_file):
with open(json_scan_file) as inp:
scan = json.load(inp)
for file in scan["files"]:
for sym in file["symbols"]:
for sym in file["source_symbols"]:
# these change on each machine/version
scope = sym.get("scope")
if scope and "__anon" in scope:
Expand Down
Loading