Skip to content

Commit 95355b5

Browse files
committed
Docs: Add back removed section on getting started
Adds a second getting started, specifically for checking out the codeql repo as a way to get the core queries. This ensures that people wanting to work in the traditional way still have the old docs available.
1 parent 01b5881 commit 95355b5

File tree

3 files changed

+139
-10
lines changed

3 files changed

+139
-10
lines changed

docs/codeql/codeql-cli/analyzing-databases-with-the-codeql-cli.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ You can also specify:
5353

5454
- ``...<query-specifications>``: a list of queries to run over your database. This
5555
is a list of arguments. Where each argument can be:
56+
5657
- a path to a query file
5758
- a path to a directory containing query files
5859
- a path to a query suite file
5960
- the name of a CodeQL query pack
60-
If omitted, the default query suite for the language
61-
of the database being analyzed will be usedFor more information, see the
62-
:ref:`examples <database-analyze-examples>` below.
61+
If omitted, the default query suite for the language
62+
of the database being analyzed will be usedFor more information, see the
63+
:ref:`examples <database-analyze-examples>` below.
6364

6465
- ``--sarif-category``: an identifying category for the results. Used when
6566
you want to upload more than one set of results for a commit.
@@ -68,12 +69,12 @@ You can also specify:
6869
see `Configuring CodeQL CLI in your CI system <https://docs.github.com/en/code-security/secure-coding/using-codeql-code-scanning-with-your-existing-ci-system/configuring-codeql-cli-in-your-ci-system>`__ in the GitHub documentation.
6970

7071
- ``--sarif-add-query-help``: (supported in version 2.7.1 onwards) adds any custom query help written
71-
in markdown to SARIF files (v2.1.0 or later) generated by the analysis. Query help stored in ``.qhelp`` files must be
72-
converted to ``.md`` before running the analysis. For further information,
73-
see ":ref:`Including query help for custom CodeQL queries in SARIF files <including-query-help-for-custom-codeql-queries-in-sarif-files>`."
72+
in markdown to SARIF files (v2.1.0 or later) generated by the analysis. Query help stored in ``.qhelp`` files must be
73+
converted to ``.md`` before running the analysis. For further information,
74+
see ":ref:`Including query help for custom CodeQL queries in SARIF files <including-query-help-for-custom-codeql-queries-in-sarif-files>`."
7475

7576
- ``--download``: a boolean flag that will allow the CLI to download any referenced CodeQL packages that are not available locally.
76-
If this flag is missing and a referenced CodeQL package is not available locally, the command will fail.
77+
If this flag is missing and a referenced CodeQL package is not available locally, the command will fail.
7778

7879
- .. include:: ../reusables/threads-query-execution.rst
7980

@@ -129,7 +130,7 @@ Running a CodeQL pack
129130
To run an existing CodeQL query pack from the GitHub Container registry, you can specify one or more
130131
pack names and use the ``--download`` flag::
131132

132-
codeql database analyze --download <database> microsoft/[email protected] github/secutiry-queries --format=sarifv2.1.0 --output=query-results.sarif
133+
codeql database analyze <database> microsoft/[email protected] github/secutiry-queries --format=sarifv2.1.0 --output=query-results.sarif --download
133134

134135
The ``analyze`` command above runs the default suite from ``microsoft/coding-standards v1.0.0`` and the latest version of ``github/secutiry-queries`` on the specified database.
135136
For further information about default suites, see ":ref:`Publishing and using CodeQL packs <publishing-and-using-codeql-packs>`".

docs/codeql/codeql-cli/getting-started-with-the-codeql-cli.rst

Lines changed: 124 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ to display in GitHub as code scanning alerts, see
3030
`Installing CodeQL CLI in your CI system <https://docs.github.com/en/code-security/secure-coding/using-codeql-code-scanning-with-your-existing-ci-system/installing-codeql-cli-in-your-ci-system>`__
3131
in the GitHub documentation.
3232

33+
.. _download-cli:
34+
3335
1. Download the CodeQL CLI zip package
3436
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3537

@@ -107,6 +109,8 @@ simply extract the zip archive.
107109
iii. ``/usr/bin/xattr -c codeql*.zip``
108110
iv. ``unzip codeql*.zip``
109111

112+
.. _launch-codeql-cli:
113+
110114
3. Launch ``codeql``
111115
~~~~~~~~~~~~~~~~~~~~
112116

@@ -139,7 +143,7 @@ up to create and analyze databases:
139143
- Run ``codeql resolve languages`` to show which languages are
140144
available for database creation. This will list the languages supported by
141145
default in your CodeQL CLI package.
142-
- (Optional) You can download some ":ref"`CodeQL packs <about-codeql-packs>` containing pre-compiled queries you would like to run.
146+
- (Optional) You can download some ":ref`CodeQL packs <about-codeql-packs>`" containing pre-compiled queries you would like to run.
143147
To do this, run ``codeql pack download <pack-name> [...pack-name]``, where ``pack-name`` is the name of
144148
the pack you want to download. The core query packs are a good place to start. They are:
145149

@@ -150,9 +154,127 @@ up to create and analyze databases:
150154
- ``codeql/python-queries``
151155
- ``codeql/ruby-queries``
152156

153-
Alternatively, you can download query packs during the analysis by using the `--download` flag of the `codeql database analyze`
157+
Alternatively, you can download query packs during the analysis by using the ``--download`` flag of the ``codeql database analyze``
154158
command.
155159

160+
161+
Checking out the CodeQL source code directly
162+
--------------------------------------------
163+
164+
Some users prefer working with CodeQL query sources directly in order to work on or contribute to the Open Source shared queries. In
165+
order to do this, the following steps are recommended. Note that the following instructions are a slightly more complicated alternative
166+
to working with CodeQL packages as explained above.
167+
168+
1. Download the CodeQL CLI zip
169+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
170+
171+
Follow :ref:`step 1 from the previous section<download-cli>`.
172+
173+
2. Create a new CodeQL directory
174+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
175+
176+
Create a new directory where you can place the CLI and any queries and libraries
177+
you want to use. For example, ``$HOME/codeql-home``.
178+
179+
The CLI's built-in search operations automatically look in all of its sibling
180+
directories for the files used in database creation and analysis. Keeping these
181+
components in their own directory prevents the CLI searching unrelated sibling
182+
directories while ensuring all files are available without specifying any
183+
further options on the command line.
184+
185+
.. _local-copy-codeql-queries:
186+
187+
3. Obtain a local copy of the CodeQL queries
188+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
189+
190+
The `CodeQL repository <https://github.com/github/codeql>`__ contains
191+
the queries and libraries required for CodeQL analysis of C/C++, C#, Java,
192+
JavaScript/TypeScript, Python, and Ruby.
193+
Clone a copy of this repository into ``codeql-home``.
194+
195+
By default, the root of the cloned repository will be called ``codeql``.
196+
Rename this folder ``codeql-repo`` to avoid conflicting with the CodeQL
197+
CLI that you will extract in step 4. If you use git on the command line, you can
198+
clone and rename the repository in a single step by running
199+
``git clone [email protected]:github/codeql.git codeql-repo`` in the ``codeql-home`` folder.
200+
201+
The CodeQL libraries and queries for Go analysis live in the `CodeQL for Go
202+
repository <https://github.com/github/codeql-go/>`__. Clone a copy of this
203+
repository into ``codeql-home``.
204+
205+
The cloned repositories should have a sibling relationship.
206+
For example, if the root of the cloned CodeQL repository is
207+
``$HOME/codeql-home/codeql-repo``, then the root of the cloned CodeQL for Go
208+
repository should be ``$HOME/codeql-home/codeql-go``.
209+
210+
Within these repositories, the queries and libraries are organized into QL
211+
packs. Along with the queries themselves, QL packs contain important metadata
212+
that tells the CodeQL CLI how to process the query files. For more information,
213+
see ":doc:`About QL packs <about-ql-packs>`."
214+
215+
.. pull-quote:: Important
216+
217+
There are different versions of the CodeQL queries available for different
218+
users. Check out the correct version for your use case:
219+
220+
- For the queries used on `LGTM.com <https://lgtm.com>`__, check out the
221+
``lgtm.com`` branch. You should use this branch for databases you've built
222+
using the CodeQL CLI, fetched from code scanning on GitHub, or recently downloaded from LGTM.com.
223+
The queries on the ``lgtm.com`` branch are more likely to be compatible
224+
with the ``latest`` CLI, so you'll be less likely to have to upgrade
225+
newly-created databases than if you use the ``main`` branch. Older databases
226+
may need to be upgraded before you can analyze them.
227+
228+
- For the most up to date CodeQL queries, check out the ``main`` branch.
229+
This branch represents the very latest version of CodeQL's analysis. Even
230+
databases created using the most recent version of the CLI may have to be
231+
upgraded before you can analyze them. For more information, see
232+
":doc:`Upgrading CodeQL databases <upgrading-codeql-databases>`."
233+
234+
- For the queries used in a particular LGTM Enterprise release, check out the
235+
branch tagged with the relevant release number. For example, the branch
236+
tagged ``v1.27.0`` corresponds to LGTM Enterprise 1.27. You must use this
237+
version if you want to upload data to LGTM Enterprise. For further
238+
information, see `Preparing CodeQL databases to upload to LGTM
239+
<https://help.semmle.com/lgtm-enterprise/admin/help/prepare-database-upload.html>`__
240+
in the LGTM admin help.
241+
242+
4. Extract the zip archive
243+
--------------------------
244+
245+
For Linux, Windows, and macOS users (version 10.14 "Mojave", and earlier)
246+
simply
247+
extract the zip archive into the directory you created in step 2.
248+
249+
For example, if the path to your copy of the CodeQL repository is
250+
``$HOME/codeql-home/codeql-repo``, then extract the CLI into
251+
``$HOME/codeql-home/``.
252+
253+
254+
5. Launch ``codeql``
255+
~~~~~~~~~~~~~~~~~~~~
256+
257+
See :ref:`step 3 from the previous section<launch-codeql-cli>`.
258+
259+
6. Verify your CodeQL CLI setup
260+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
261+
262+
CodeQL CLI has subcommands you can execute to verify that you are correctly set
263+
up to create and analyze databases:
264+
265+
- Run ``codeql resolve languages`` to show which languages are
266+
available for database creation. This will list the languages supported by
267+
default in your CodeQL CLI package.
268+
- Run ``codeql resolve qlpacks`` to show which QL packs the CLI can find. This
269+
will display the names of the QL packs included in the CodeQL repositories:
270+
``codeql-cpp``, ``codeql-csharp``, ``codeql-go``,
271+
``codeql-java``, ``codeql-javascript``, and ``codeql-python``. The CodeQL
272+
repositories also contain 'upgrade' packs and 'legacy' packs. Upgrade packs
273+
are used by the CLI when you want to upgrade a database so that it can be
274+
analyzed with a newer version of the CodeQL toolchain than was used to create
275+
it. Legacy packs ensure that custom queries and libraries created using older
276+
products are compatible with your version of CodeQL.
277+
156278
.. _using-two-versions-of-the-codeql-cli:
157279

158280
Using two versions of the CodeQL CLI

docs/codeql/codeql-cli/upgrading-codeql-databases.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ Databases become out of date when:
1414
- For databases downloaded from LGTM.com, the CodeQL tools used by LGTM.com to create
1515
that revision of the code are older than your copy of the CodeQL queries.
1616

17+
If you have a local checkout of the ``github/codeql`` repository, please note that
18+
the ``main`` branch of the CodeQL queries is updated more often than both the
19+
CLI and LGTM.com, so databases are most likely to become out of date if you use
20+
the queries on this branch. For more information about the different versions of
21+
the CodeQL queries, see ":ref:`Getting started with the CodeQL CLI <local-copy-codeql-queries>`."
22+
1723
Out-of-date databases must be upgraded before they can be analyzed. This topic
1824
shows you how to upgrade a CodeQL database using the ``database upgrade``
1925
subcommand.

0 commit comments

Comments
 (0)