Skip to content

Add fprime-util sloc: context-aware SLOC counting with FPP support - #30

Closed
devin-ai-integration[bot] wants to merge 8 commits into
develfrom
devin/1787857259-sloc-counter
Closed

devin-ai-integration[bot] wants to merge 8 commits into
develfrom
devin/1787857259-sloc-counter

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Related Issue(s)
Has Unit Tests (y/n) y
Documentation Included (y/n) y (help text)

Change Description

Adds a new fprime-util sloc command that counts source lines of code using pygount, plus a Pygments lexer plugin so .fpp/.fppi files are recognized.

  • Module discovery (src/fprime/util/sloc.py): any directory whose CMakeLists.txt contains register_fprime_*, add_library, or add_executable is a module; files are attributed to the nearest owning module. Build caches (CMakeCache.txt, .fprime-build-dir, build-fprime*), hidden dirs, and git submodules (unless --include-submodules) are excluded from source scans.
  • Context-aware behavior:
    • component/module dir → counts that module only (no build cache required)
    • deployment dir → counts the deployment and its linked dependencies, including autocoded (AC) files from the build cache (cache required)
    • project/framework root → full segmentation into fprime, each library_locations library, and the project, with per-section totals and a grand total (no cache required)
    • --recursive → counts recursively from the current directory (cache required)
  • FPP lexer (src/fprime/fpp/lexer.py): RegexLexer handling # comments, @ annotations, strings, numbers, FPP keywords/types; registered via a pygments.lexers entry point in pyproject.toml so pygount picks it up automatically.
  • Reporting: aligned CLI table (per-module rows, section totals, grand total, UT and AC columns, by-language summary), plus optional --markdown-report and --json-report.
  • Unit test code (under test/tests/ut directories) is reported in a separate UT column; AC counts appear only when a build cache is used.

Rationale

Projects need repeatable SLOC accounting for F Prime framework, libraries, and project code — segmented by module and section, working with or without a generated build cache, and including autocoded output when available.

Testing/Review Recommendations

  • pytest test/fprime/util/test_sloc.py (module discovery, cache exclusion, UT separation, rollups, renderers) — full suite: 162 passed.
  • Verified against the fprime repo: component mode (Svc/CmdDispatcher), full root scan (~27 s), a built TestDeploymentsProject/Ref deployment with AC counts, --recursive with a cache, and the clean error when --recursive/deployment lacks a cache.
  • black --check (25.1.0, matching CI) is clean.
  • Review focus: deployment dependency resolution (parses link.txt/build.ninja for lib<name>.* tokens) and the set of languages excluded from counting.

Future Work

  • Possible tuning of AC file attribution for non-standard build cache layouts.
  • Upstream PR to nasa/fprime-tools when ready.

Link to Devin session: https://nasa-jpl-demo.devinenterprise.com/sessions/2196176199c144bbb4dd358947bfc228
Open in Devin Desktop: https://nasa-jpl-demo.devinenterprise.com/desktop/session/2196176199c144bbb4dd358947bfc228?variant=devin


Devin Review

Co-Authored-By: michael.d.starch <michael.d.starch@jpl.nasa.gov>
@devin-ai-integration

Copy link
Copy Markdown
Author
Original prompt from michael.d.starch

Would you please build me a tool that does SLOC counts of F Prime? Here is what we need to do:

  1. Segment F Prime into modules: a module is anything with a register_fprime* call, add_library, or add_executable
  2. Run pygount on the module and get SLOC counts
  3. Add a plugin to pygount to support fpp and fppi files
  4. Handle separate sections for fprime libraries (currently in setting.ini) and fprime
  5. Total for each library and fprime core
  6. Total for the top level repo/project
  7. Total the results for the whole repository including libraries
  8. Produce CLI output and a nice report format.
  9. If a build folder is provided we should total the AC files too. If not provided, ignore the build directories (build caches).

Please create a plan to do this and ask any follow questions. This must be able to run regardless if a build cache is generated or not.

Thanks!

@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Comment thread src/fprime/util/sloc.py
tokens.update(
LIBRARY_TOKEN_PATTERN.findall(link_file.read_text(errors="replace"))
)
except Exception:
devin-ai-integration[bot]

This comment was marked as resolved.

Co-Authored-By: michael.d.starch <michael.d.starch@jpl.nasa.gov>
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration Bot and others added 4 commits August 27, 2026 19:39
…losure

Co-Authored-By: michael.d.starch <michael.d.starch@jpl.nasa.gov>
…error, exclude build-artifacts

Co-Authored-By: michael.d.starch <michael.d.starch@jpl.nasa.gov>
… per-language other buckets

Co-Authored-By: michael.d.starch <michael.d.starch@jpl.nasa.gov>
Co-Authored-By: michael.d.starch <michael.d.starch@jpl.nasa.gov>
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration Bot and others added 2 commits August 27, 2026 22:01
Co-Authored-By: michael.d.starch <michael.d.starch@jpl.nasa.gov>
Co-Authored-By: michael.d.starch <michael.d.starch@jpl.nasa.gov>
@devin-ai-integration

Copy link
Copy Markdown
Author

Closing fork PR; work is being submitted upstream to nasa/fprime-tools.

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.

1 participant