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 clang tidy Contributing guide #106672

Merged

Conversation

MichelleCDjunaidi
Copy link
Contributor

Update the documentation to direct new users to the Github instead of the discontinued Phabricator archive. Also details more ways and information regarding clang-query usage. Partially resolves/disclaims #106656 and #106663 as per discussion in https://discourse.llvm.org/t/inconsistency-between-hasdescendant-in-clang-query-and-clang-libtooling-matchers/80799/.

Also updates the out-of-tree guide.

For context, I recently went through the Contributing guide while writing #102299, and many of these updates were from my experience trying to follow the guide. e.g. I was trying to link the shared library of an out-of-tree check as SHARED in CMake and encountered duplicate symbols like _ZTIN5clang4tidy14ClangTidyCheckE. It wasn't until I saw 84f137a that I found out I had to use MODULE. I also encountered the clang-query difference which was a surprise as the documentation said the two matchers were "virtually identical". Also, the -header-filter thing tripped me out until I found #25590 and #91400. Usually, when people say restrict and filter, they mean filter out (since -header-filter instead includes/filters in said headers).

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Aug 30, 2024

@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-tidy

Author: None (MichelleCDjunaidi)

Changes

Update the documentation to direct new users to the Github instead of the discontinued Phabricator archive. Also details more ways and information regarding clang-query usage. Partially resolves/disclaims #106656 and #106663 as per discussion in https://discourse.llvm.org/t/inconsistency-between-hasdescendant-in-clang-query-and-clang-libtooling-matchers/80799/.

Also updates the out-of-tree guide.

For context, I recently went through the Contributing guide while writing #102299, and many of these updates were from my experience trying to follow the guide. e.g. I was trying to link the shared library of an out-of-tree check as SHARED in CMake and encountered duplicate symbols like _ZTIN5clang4tidy14ClangTidyCheckE. It wasn't until I saw 84f137a that I found out I had to use MODULE. I also encountered the clang-query difference which was a surprise as the documentation said the two matchers were "virtually identical". Also, the -header-filter thing tripped me out until I found #25590 and #91400. Usually, when people say restrict and filter, they mean filter out (since -header-filter instead includes/filters in said headers).


Full diff: https://github.com/llvm/llvm-project/pull/106672.diff

1 Files Affected:

  • (modified) clang-tools-extra/docs/clang-tidy/Contributing.rst (+40-14)
diff --git a/clang-tools-extra/docs/clang-tidy/Contributing.rst b/clang-tools-extra/docs/clang-tidy/Contributing.rst
index 92074bd4dae8ba..e92e86621c684d 100644
--- a/clang-tools-extra/docs/clang-tidy/Contributing.rst
+++ b/clang-tools-extra/docs/clang-tidy/Contributing.rst
@@ -130,11 +130,12 @@ So you have an idea of a useful check for :program:`clang-tidy`.
 First, if you're not familiar with LLVM development, read through the `Getting
 Started with LLVM`_ document for instructions on setting up your workflow and
 the `LLVM Coding Standards`_ document to familiarize yourself with the coding
-style used in the project. For code reviews we mostly use `LLVM Phabricator`_.
+style used in the project. For code reviews we currently use `LLVM Github`_,
+though historically we used Phabricator.
 
 .. _Getting Started with LLVM: https://llvm.org/docs/GettingStarted.html
 .. _LLVM Coding Standards: https://llvm.org/docs/CodingStandards.html
-.. _LLVM Phabricator: https://llvm.org/docs/Phabricator.html
+.. _LLVM Github: https://github.com/llvm/llvm-project
 
 Next, you need to decide which module the check belongs to. Modules
 are located in subdirectories of `clang-tidy/
@@ -336,13 +337,24 @@ a starting point for your test cases.  A rough outline of the process looks like
 The quickest way to prototype your matcher is to use :program:`clang-query` to
 interactively build up your matcher.  For complicated matchers, build up a matching
 expression incrementally and use :program:`clang-query`'s ``let`` command to save named
-matching expressions to simplify your matcher.  Just like breaking up a huge function
-into smaller chunks with intention-revealing names can help you understand a complex
-algorithm, breaking up a matcher into smaller matchers with intention-revealing names
-can help you understand a complicated matcher.  Once you have a working matcher, the
-C++ API will be virtually identical to your interactively constructed matcher.  You can
-use local variables to preserve your intention-revealing names that you applied to
-nested matchers.
+matching expressions to simplify your matcher.
+
+.. code-block:: console
+  clang-query> let c1 cxxRecordDecl()
+  clang-query> match c1
+
+Alternatively, pressing tab after a previous matcher's open brace would also show which 
+matchers can be chained with the previous matcher, though some matchers that work may not 
+be listed.
+
+Just like breaking up a huge function into smaller chunks with intention-revealing names 
+can help you understand a complex algorithm, breaking up a matcher into smaller matchers 
+with intention-revealing names can help you understand a complicated matcher.  
+
+Once you have a working clang-query matcher, the C++ API will be the same or similar to your 
+interactively constructed matcher (there will be cases where they differ slightly). 
+You can use local variables to preserve your intention-revealing names that you applied 
+to nested matchers.
 
 Creating private matchers
 ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -646,10 +658,13 @@ directory.  The path to this directory is available in a lit test with the varia
 Out-of-tree check plugins
 -------------------------
 
+
 Developing an out-of-tree check as a plugin largely follows the steps
-outlined above. The plugin is a shared library whose code lives outside
+outlined above, including creating a new module and doing the hacks to 
+register the module. The plugin is a shared library whose code lives outside
 the clang-tidy build system. Build and link this shared library against
-LLVM as done for other kinds of Clang plugins.
+LLVM as done for other kinds of Clang plugins. If using CMake, use the keyword
+MODULE while invoking add_library or llvm_add_library.
 
 The plugin can be loaded by passing `-load` to `clang-tidy` in addition to the
 names of the checks to enable.
@@ -664,6 +679,17 @@ compiled against the version of clang-tidy that will be loading the plugin.
 The plugins can use threads, TLS, or any other facilities available to in-tree
 code which is accessible from the external headers.
 
+Note that testing checks out of tree might involve getting ``llvm-lit`` from an 
+installed version of LLVM through the `Stand-alone Builds`_ section. Alternatively,
+get `lit`_ following the `test-suite guide`_ and get the `FileCheck`_ binary, and
+write a version of `check_clang_tidy.py`_ to suit your needs.
+
+.. _Stand-alone Builds: https://llvm.org/docs/GettingStarted.html
+.. _test-suite guide: https://llvm.org/docs/TestSuiteGuide.html
+.. _lit: https://llvm.org/docs/CommandGuide/lit.html
+.. _FileCheck: https://llvm.org/docs/CommandGuide/FileCheck.html
+.. _check_clang_tidy.py: https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+
 Running clang-tidy on LLVM
 --------------------------
 
@@ -690,8 +716,8 @@ warnings and errors. The script provides multiple configuration flags.
   that the file names are matched against.
   ``run-clang-tidy.py clang-tidy/.*Check\.cpp`` will only analyze clang-tidy
   checks. It may also be necessary to restrict the header files that warnings
-  are displayed from using the ``-header-filter`` flag. It has the same behavior
-  as the corresponding :program:`clang-tidy` flag.
+  are displayed from using the ``-exclude-header-filter`` flag. It has the same 
+  behavior as the corresponding :program:`clang-tidy` flag.
 
 * To apply suggested fixes ``-fix`` can be passed as an argument. This gathers
   all changes in a temporary directory and applies them. Passing ``-format``
@@ -758,4 +784,4 @@ There is only one argument that controls profile storage:
 
   * If you run :program:`clang-tidy` from within ``/foo`` directory, and specify
     ``-store-check-profile=.``, then the profile will still be saved to
-    ``/foo/<ISO8601-like timestamp>-example.cpp.json``
+    ``/foo/<ISO8601-like timestamp>-example.cpp.json``
\ No newline at end of file

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

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

Thank you for working on this, the changes mostly LGTM aside from some minor nits.

Copy link
Contributor

@5chmidti 5chmidti left a comment

Choose a reason for hiding this comment

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

Thanks for clearing things up in the docs

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

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

LGTM!

@AaronBallman
Copy link
Collaborator

Do you need someone to land the changes on your behalf?

@MichelleCDjunaidi
Copy link
Contributor Author

MichelleCDjunaidi commented Aug 30, 2024

Yeah, I don't have write permissions, so I need someone to land the changes on my behalf. Thank you so much! @AaronBallman

@AaronBallman AaronBallman merged commit 362d37a into llvm:main Aug 30, 2024
5 of 6 checks passed
@AaronBallman
Copy link
Collaborator

Yeah, I don't have write permissions, so I need someone to land the changes on my behalf. Thank you so much! @AaronBallman

Thank you! We always appreciate improved documentation!

Copy link

@MichelleCDjunaidi Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@MichelleCDjunaidi
Copy link
Contributor Author

MichelleCDjunaidi commented Aug 30, 2024

From another pull #106675, why is this failing the build-bot? Any ideas? Do I have to create a new PR just to fix this? @AaronBallman

-- Build files have been written to: /home/runner/work/llvm-project/llvm-project/clang-tools-extra-build
ninja: Entering directory `clang-tools-extra-build'
[1/2] Generating man Sphinx documentation for clang-tools into "/home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs/man"
FAILED: tools/clang/tools/extra/docs/CMakeFiles/docs-clang-tools-man /home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs/CMakeFiles/docs-clang-tools-man 
cd /home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs && /usr/local/bin/cmake -E env /opt/hostedtoolcache/Python/3.11.9/x64/bin/sphinx-build -b man -d /home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs/_doctrees-clang-tools-man -q -t builder-man -D version=20 -D release=20.0.0git -tPreRelease -W /home/runner/work/llvm-project/llvm-project/clang-tools-extra/docs /home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs/man

Warning, treated as error:

Warning, treated as error:
/home/runner/work/llvm-project/llvm-project/clang-tools-extra/docs/clang-tidy/Contributing.rst:342:Error in "code-block" directive:
maximum 1 argument(s) allowed, 8 supplied.

.. code-block:: console
  clang-query> let c1 cxxRecordDecl()
  clang-query> match c1
[2/2] Generating html Sphinx documentation for clang-tools into "/home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs/html"
FAILED: tools/clang/tools/extra/docs/CMakeFiles/docs-clang-tools-html /home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs/CMakeFiles/docs-clang-tools-html 
cd /home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs && /usr/local/bin/cmake -E env /opt/hostedtoolcache/Python/3.11.9/x64/bin/sphinx-build -b html -d /home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs/_doctrees-clang-tools-html -q -t builder-html -D version=20 -D release=20.0.0git -tPreRelease -W /home/runner/work/llvm-project/llvm-project/clang-tools-extra/docs /home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs/html

Warning, treated as error:
/home/runner/work/llvm-project/llvm-project/clang-tools-extra/docs/clang-tidy/Contributing.rst:342:Error in "code-block" directive:
maximum 1 argument(s) allowed, 8 supplied.

.. code-block:: console
  clang-query> let c1 cxxRecordDecl()
  clang-query> match c1
ninja: build stopped: subcommand failed.

@AaronBallman
Copy link
Collaborator

From another pull #106675, why is this failing the build-bot? Any ideas? Do I have to create a new PR just to fix this? @AaronBallman

-- Build files have been written to: /home/runner/work/llvm-project/llvm-project/clang-tools-extra-build
ninja: Entering directory `clang-tools-extra-build'
[1/2] Generating man Sphinx documentation for clang-tools into "/home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs/man"
FAILED: tools/clang/tools/extra/docs/CMakeFiles/docs-clang-tools-man /home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs/CMakeFiles/docs-clang-tools-man 
cd /home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs && /usr/local/bin/cmake -E env /opt/hostedtoolcache/Python/3.11.9/x64/bin/sphinx-build -b man -d /home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs/_doctrees-clang-tools-man -q -t builder-man -D version=20 -D release=20.0.0git -tPreRelease -W /home/runner/work/llvm-project/llvm-project/clang-tools-extra/docs /home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs/man

Warning, treated as error:

Warning, treated as error:
/home/runner/work/llvm-project/llvm-project/clang-tools-extra/docs/clang-tidy/Contributing.rst:342:Error in "code-block" directive:
maximum 1 argument(s) allowed, 8 supplied.

.. code-block:: console
  clang-query> let c1 cxxRecordDecl()
  clang-query> match c1
[2/2] Generating html Sphinx documentation for clang-tools into "/home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs/html"
FAILED: tools/clang/tools/extra/docs/CMakeFiles/docs-clang-tools-html /home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs/CMakeFiles/docs-clang-tools-html 
cd /home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs && /usr/local/bin/cmake -E env /opt/hostedtoolcache/Python/3.11.9/x64/bin/sphinx-build -b html -d /home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs/_doctrees-clang-tools-html -q -t builder-html -D version=20 -D release=20.0.0git -tPreRelease -W /home/runner/work/llvm-project/llvm-project/clang-tools-extra/docs /home/runner/work/llvm-project/llvm-project/clang-tools-extra-build/tools/clang/tools/extra/docs/html

Warning, treated as error:
/home/runner/work/llvm-project/llvm-project/clang-tools-extra/docs/clang-tidy/Contributing.rst:342:Error in "code-block" directive:
maximum 1 argument(s) allowed, 8 supplied.

.. code-block:: console
  clang-query> let c1 cxxRecordDecl()
  clang-query> match c1
ninja: build stopped: subcommand failed.

Sorry for missing that before landing, I'll fix it up.

@AaronBallman
Copy link
Collaborator

This should now be resolved in 9712255

@LegalizeAdulthood
Copy link
Contributor

Alternatively, pressing the tab key after a previous matcher's open parentheses would also

Did you try this on Windows? Because in my experience all these TAB-complete actions depend on GNU readline which doesn't work on Windows.

@MichelleCDjunaidi
Copy link
Contributor Author

@LegalizeAdulthood Thanks for bringing this up because it slipped my mind to test it on Windows! I honestly have only tested it on Linux, and I currently don't have access to my laptop for the week.

If anyone reads this and tests it out, please tell the results. I'll open a new PR to add the Windows exception if it doesn't work. (Or if there's a better workflow that LLVM uses, do tell.)

@AaronBallman
Copy link
Collaborator

If anyone reads this and tests it out, please tell the results. I'll open a new PR to add the Windows exception if it doesn't work. (Or if there's a better workflow that LLVM uses, do tell.)

Correct, it doesn't work out of the box on Windows.

@MichelleCDjunaidi
Copy link
Contributor Author

I see; thanks for notifying me! Does anyone know of the workaround on Windows, or should I try to find it after I have access to my laptop?

@AaronBallman
Copy link
Collaborator

There is no workaround on Windows currently; the issue is that tab autocompletion is handled via

::el_set(Data->EL, EL_ADDFN, "tab_complete", "Tab completion function",
and that's not available on Windows; we don't have any fallback code for it.

There is https://sourceforge.net/projects/mingweditline/ (no idea how well it would work in practice), so perhaps there's a different library we could consume on Windows to provide the functionality.

@MichelleCDjunaidi
Copy link
Contributor Author

Hmm, in that case, would it be better to note the Windows exception in the documentation and open up an issue tracker for the tab issue instead, since the bug and fix (due to it affecting all tab-related operations on Windows) is out of scope for this documentation PR?

Also, what's the workflow for adding to a merger PR? Just make a new PR, correct?

@AaronBallman
Copy link
Collaborator

Hmm, in that case, would it be better to note the Windows exception in the documentation and open up an issue tracker for the tab issue instead, since the bug and fix (due to it affecting all tab-related operations on Windows) is out of scope for this documentation PR?

I think that approach makes sense!

Also, what's the workflow for adding to a merger PR? Just make a new PR, correct?

Correct, making a new PR is the way to go.

@MichelleCDjunaidi
Copy link
Contributor Author

Will open the issue soon (since mobile Github is accessible), but the additional new PR will be in a few days (no access to laptop currently)

@MichelleCDjunaidi
Copy link
Contributor Author

MichelleCDjunaidi commented Sep 10, 2024

PR opened on the linetab issue.

AaronBallman pushed a commit that referenced this pull request Sep 11, 2024
…uto-complete (#107956)

As per
#106672
and #107377, the
documentation should be updated to note that the current bug on Windows
involving ``LineEditor`` causing Tab key related features to not work.

Fixes #107377
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants