Skip to content

Commit d892304

Browse files
committed
Address comments from PR
1 parent 3890907 commit d892304

6 files changed

+70
-46
lines changed

docs/codeql/codeql-cli/about-codeql-packs.rst

Lines changed: 64 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ There are two types of CodeQL packs: query packs and library packs.
1515
You can use the package management commands in the CodeQL CLI to create CodeQL packs, add dependencies to packs, and install or update dependencies. For more information, see ":ref:`Creating and working with CodeQL packs <creating-and-working-with-codeql-packs>`." You can also publish and download CodeQL packs using the CodeQL CLI. For more information, see ":doc:`Publishing and using CodeQL packs <publishing-and-using-codeql-packs>`."
1616

1717

18-
The standard CodeQL packages for all supported languages are published in the `GitHub package registry <https://github.com/orgs/codeql/packages>`__.`
18+
The standard CodeQL packages for all supported languages are published in the `GitHub Container registry <https://github.com/orgs/codeql/packages>`__.`
1919
The `CodeQL repository <https://github.com/github/codeql>`__ contains sources for the standard CodeQL packs for all supported languages.
2020

2121
.. _codeql-pack-structure:
@@ -59,7 +59,7 @@ The following properties are supported in ``qlpack.yml`` files.
5959

6060
* - Property
6161
- Example
62-
- Required
62+
- Required by
6363
- Purpose
6464
* - ``name``
6565
- .. code-block:: yaml
@@ -82,14 +82,14 @@ The following properties are supported in ``qlpack.yml`` files.
8282
codeql/cpp-all: ^0.0.2
8383

8484
- Packs that define CodeQL package dependencies on other packs
85-
- A map from pack references to the semantic version range that is compatible with this pack. Supported from CLI version v2.6.0 and onwards.
85+
- A map from pack references to the semantic version range that is compatible with this pack. Supported for CLI versions v2.6.0 and later.
8686
* - ``defaultSuiteFile``
8787
- .. code-block:: yaml
8888

8989
defaultSuiteFile: cpp-code-scanning.qls
9090

9191
- Packs that export a set of default queries to run
92-
- The path to a query suite file containing all of the queries that are run by default when this pack is passed to the ``codeql database analyze`` command. Supported from CLI version v2.6.0 and onwards.
92+
- The path to a query suite file relative to the package root, containing all of the queries that are run by default when this pack is passed to the ``codeql database analyze`` command. Supported from CLI version v2.6.0 and onwards. Only one of ``defaultSuiteFile`` or ``defaultSuite`` can be defined.
9393
* - ``defaultSuite``
9494
- .. code-block:: yaml
9595

@@ -99,7 +99,7 @@ The following properties are supported in ``qlpack.yml`` files.
9999
precision: medium
100100

101101
- Packs that export a set of default queries to run
102-
- An inlined query suite containing all of the queries that are run by default when this pack is passed to the ``codeql database analyze`` command. Supported from CLI version v2.6.0 and onwards.
102+
- An inlined query suite containing all of the queries that are run by default when this pack is passed to the ``codeql database analyze`` command. Supported from CLI version v2.6.0 and onwards. Only one of ``defaultSuiteFile`` or ``defaultSuite`` can be defined.
103103
* - ``library``
104104
- .. code-block:: yaml
105105

@@ -113,7 +113,7 @@ The following properties are supported in ``qlpack.yml`` files.
113113
suites: octo-org-query-suites
114114

115115
- Optional
116-
- The path to a directory in the pack that contains the query suites you want to make known to the CLI, defined relative to the pack directory. CodeQL pack users can run "well-known" suites stored in this directory by specifying the pack name, without providing their full path. This is not supported for CodeQL packs downloaded from a package registry. For more information about query suites, see ":doc:`Creating CodeQL query suites <creating-codeql-query-suites>`."
116+
- The path to a directory in the pack that contains the query suites you want to make known to the CLI, defined relative to the pack directory. CodeQL pack users can run "well-known" suites stored in this directory by specifying the pack name, without providing their full path. This is not supported for CodeQL packs downloaded from the Container registry. For more information about query suites, see ":doc:`Creating CodeQL query suites <creating-codeql-query-suites>`."
117117
* - ``extractor``
118118
- .. code-block:: yaml
119119

@@ -141,7 +141,7 @@ The following properties are supported in ``qlpack.yml`` files.
141141
upgrades: .
142142

143143
- Core language packs only
144-
- The path to a directory within the pack that contains upgrade scripts, defined relative to the pack directory. The ``database upgrade`` action uses these scripts to upgrade databases that were created by an older version of an extractor or downgrade databases that were created by a newer version of the extractor so they're compatible with the current extractor (see `Upgrade scripts for a language <#upgrade-scripts-for-a-language>`__ below.)
144+
- The path to a directory within the pack that contains database upgrade scripts, defined relative to the pack directory. Database upgrades are used internally to ensure a databasae created with a different version of the CodeQL CLI is compatible with the current version.
145145
* - ``authors``
146146
- .. code-block:: yaml
147147

@@ -169,7 +169,7 @@ The following properties are supported in ``qlpack.yml`` files.
169169
libraryPathDependencies: codeql/javascript-all
170170

171171
- Optional, deprecated
172-
- Use the ``dependencies`` property instead. The names of any CodeQL packs that this CodeQL pack depends on, as a sequence. This gives the pack access to any libraries, database schema, and query suites defined in the dependency.
172+
- Use the ``dependencies`` property instead. The names of any CodeQL packs that this CodeQL pack depends on, as an array. This gives the pack access to any libraries, database schema, and query suites defined in the dependency.
173173

174174
.. _about-codeql-pack-lock:
175175

@@ -199,6 +199,9 @@ The ``codeql-pack.lock.yml`` file will contain something like the following:
199199
my-user/transitive-dependency:
200200
version: 1.2.4
201201
202+
..
203+
TODO: Add a link to the CodeQL CLI documentation for query resolution, specifically in regards to resolving from source
204+
202205
The ``codeql/cpp-all`` dependency is locked to version 0.1.4. The ``my-user/my-lib`` dependency is locked to version 0.2.4. The ``my-user/transitive-dependency``, which is a transitive dependency and is not specified in the ``qlpack.yml`` file, is locked to version 1.2.4. The ``other-dependency/from-source`` is absent from the lock file since it is resolved from source. This dependency must be available in the same CodeQL workspace as the pack.
203206

204207
.. _custom-codeql-packs:
@@ -208,26 +211,43 @@ Examples of custom CodeQL packs
208211

209212
When you write custom queries or tests, you should save them in custom CodeQL packs. For simplicity, try to organize each pack logically. For more information, see `CodeQL pack structure <#codeql-pack-structure>`__. Save files for queries and tests in separate packs and, where possible, organize custom packs into specific folders for each target language. This is particuarly useful if you intend to publish your CodeQL packs so they can be shared with others or used in GitHub `Code scanning <https://docs.github.com/en/code-security/secure-coding/automatically-scanning-your-code-for-vulnerabilities-and-errors/about-code-scanning>`__.
210213

214+
CodeQL packs for custom libraries
215+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
216+
217+
A custom CodeQL pack containing custom C++ libraries, with no queries or tests, may have a ``qlpack.yml`` file containing:
218+
219+
.. code-block:: yaml
220+
221+
name: my-github-user/my-custom-libraries
222+
version: 1.2.3
223+
library: true
224+
dependencies:
225+
codeql/cpp-all: ^0.1.2
226+
227+
where ``codeql/cpp-all`` is the name of the CodeQL pack for C/C++ analysis included in the CodeQL repository. The version range ``^0.1.2`` indicates that this pack is compatible with all versions of ``codeql/cpp-all`` that are greater than or equal to ``0.1.2`` and less than ``0.2.0``. Any CodeQL library file (a file with a ``.qll`` extension) defined in this pack will be available to queries defined in any query pack that includes this pack in its dependencies block.
228+
229+
The ``library`` property indicates that this pack is a library pack and does not contain any queries.
230+
211231
CodeQL packs for custom queries
212232
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
213233

214-
A custom CodeQL pack for queries must include a ``qlpack.yml`` file at the pack root, containing ``name``, ``version``, and ``dependencies`` properties. If the pack contains query suites, you can use the ``suites`` property to define their location. Query suites defined here are called "well-known" suites, and can be used on the command line by referring to their name only, rather than their full path. For more information about query suites, see ":doc:`Creating CodeQL query suites <creating-codeql-query-suites>`."
215-
216-
For example, a ``qlpack.yml`` file for a CodeQL pack featuring custom C++ queries
217-
and libraries may contain:
234+
A custom CodeQL pack containing custom C++ queries and libraries may have a ``qlpack.yml`` file containing:
218235

219236
.. code-block:: yaml
220237
221238
name: my-github-user/my-custom-queries
222239
version: 1.2.3
223240
dependencies:
224241
codeql/cpp-all: ^0.1.2
242+
my-github-user/my-custom-libraries: ^1.2.3
225243
suites: my-custom-suites
226244
227-
where ``codeql/cpp-all`` is the name of the CodeQL pack for C/C++ analysis included in the CodeQL repository. The version range ``^0.1.2`` indicates that this pack is compatible with all versions of ``codeql/cpp-all`` that are greater than or equal to ``0.1.2`` and less than ``0.2.0``.
245+
where ``codeql/cpp-all`` is the name of the CodeQL pack for C/C++ analysis included in the CodeQL repository. The version range ``^0.1.2`` indicates that this pack is compatible with all versions of ``codeql/cpp-all`` that are greater than or equal to ``0.1.2`` and less than ``0.2.0``. ``my-github-user/my-custom-libraries`` is the name of a CodeQL pack containing custom CodeQL libraries for C++. Any CodeQL library file (a file with a ``.qll`` extension) defined in this pack will be available to queries in the ``my-github-user/my-custom-queries`` pack.
246+
247+
The ``suites`` property indicates a directory where "well-known" query suites can be found. These suites can be used on the command line by referring to their name only, rather than their full path. For more information about query suites, see ":doc:`Creating CodeQL query suites <creating-codeql-query-suites>`."
228248

229-
CodeQL packs for custom test files
230-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
249+
CodeQL packs for custom tests
250+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
231251

232252
For custom CodeQL packs containing test files, you also need to include an
233253
``extractor`` property so that the ``test run`` command knows how to create test
@@ -246,23 +266,18 @@ Examples of CodeQL packs in the CodeQL repository
246266
Each of the languages in the CodeQL repository has four main CodeQL packs:
247267

248268
- Core library pack for the language, with the :ref:`database schema <codeql-database-schema>`
249-
used by the language, and CodeQL libraries, and queries at ``ql/<language>/ql/lib``
269+
used by the language, and CodeQL libraries, and queries at ``<language>/ql/lib``
250270
- Core query pack for the language that includes the default queries for the language, along
251-
with their query suites at ``ql/<language>/ql/src``
252-
- Tests for the core language libraries and queries at ``ql/<language>/ql/test``
253-
- Example queries for the language at ``ql/<language>/ql/examples``
271+
with their query suites at ``<language>/ql/src``
272+
- Tests for the core language libraries and queries at ``<language>/ql/test``
273+
- Example queries for the language at ``<language>/ql/examples``
254274

255275
Core library pack
256276
~~~~~~~~~~~~~~~~~
257277

258-
The ``qlpack.yml`` file for a core library pack uses the following properties:
259-
``name``, ``version``, ``dbscheme``.
260-
The ``dbscheme`` property should only be defined in the core QL
261-
pack for a language.
262-
263-
For example, the ``qlpack.yml`` file for `C/C++ analysis libraries
278+
Here is an example ``qlpack.yml`` file for `C/C++ analysis libraries
264279
<https://github.com/github/codeql/blob/main/cpp/ql/lib/qlpack.yml>`__
265-
contains:
280+
core language pack:
266281

267282
.. code-block:: yaml
268283
@@ -272,15 +287,18 @@ contains:
272287
library: true
273288
upgrades: upgrades
274289
290+
Some extra notes on the following properties:
291+
292+
- ``library``: Indicates that this is a library pack with no executable queries. It is only meant to be used as a dependency for other packs.
293+
- ``dbscheme`` and ``upgrades``: Properties internal to the CodeQL CLI and should only be defined in the core QL pack for a language.
294+
295+
275296
Core query pack
276297
~~~~~~~~~~~~~~~
277298

278-
The ``qlpack.yml`` file for a core query pack uses the following properties:
279-
``name``, ``version``, ``suites``, ``defaultSuiteFile``, ``dependencies`` .
280-
281-
For example, the ``qlpack.yml`` file for `C/C++ analysis queries
282-
<https://github.com/github/codeql/blob/main/cpp/ql/lib/qlpack.yml>`__
283-
contains:
299+
Here is an example ``qlpack.yml`` file for `C/C++ analysis queries
300+
<https://github.com/github/codeql/blob/main/cpp/ql/src/qlpack.yml>`__
301+
core query pack:
284302

285303
.. code-block:: yaml
286304
@@ -292,16 +310,18 @@ contains:
292310
suites: codeql-suites
293311
defaultSuiteFile: codeql-suites/cpp-code-scanning.qls
294312
295-
This query pack depends on ``codeql/cpp-all`` and ``codeql/suite-helpers``. Since these dependencies are resolved from source, it does not matter what version of the CodeQL pack they are compatible with.
313+
Some extra notes on the following properties:
314+
315+
- ``dependencies``: This query pack depends on ``codeql/cpp-all`` and ``codeql/suite-helpers``. Since these dependencies are resolved from source, it does not matter what version of the CodeQL pack they are compatible with.
316+
- ``suites``: Indicates the directory containing "well-known" query suites.
317+
- ``defaultSuiteFile``: The name of the default query suite file that is used when no query suite is specified.
296318

297319
Tests for the core CodeQL pack
298320
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
299321

300-
The ``qlpack.yml`` file for the tests for the core CodeQL packs use the following properties: ``name``, ``dependencies``, ``extractor``, ``tests``.
301-
302-
For example, the ``qlpack.yml`` file for `C/C++ analysis tests
303-
<https://github.com/github/codeql/blob/main/cpp/ql/test/qlpack.yml>`__
304-
contains:
322+
Here is an example ``qlpack.yml`` file for `C/C++ analysis tests
323+
<https://github.com/github/codeql/blob/main/cpp/ql/src/qlpack.yml>`__
324+
core test pack:
305325

306326
.. code-block:: yaml
307327
@@ -312,4 +332,9 @@ contains:
312332
extractor: cpp
313333
tests: .
314334
315-
The ``dependencies`` property always specifies the core CodeQL pack. The ``extractor`` property specifies that all the tests will use the same C++ extractor to create the database for the tests. The ``tests`` property specifies the location of the tests. In this case, the tests are in the root folder (and all sub-folders) of the pack. Note that there is no ``version`` property for the tests pack since this pack is not meant to be published.
335+
Some extra notes on the following properties:
336+
337+
- ``dependencies``: This pack depends on the core CodeQL query and library packs for C++.
338+
- ``extractor``: This specifies that all the tests will use the same C++ extractor to create the database for the tests.
339+
- ``tests``: This specifies the location of the tests. In this case, the tests are in the root folder (and all sub-folders) of the pack.
340+
- ``version``: There is no ``version`` property for the tests pack. This prevents test packs from accidentally being published.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ You can also specify:
5858
- a path to a directory containing query files
5959
- a path to a query suite file
6060
- the name of a CodeQL query pack
61-
- with an optional a version range
61+
- with an optional version range
6262
- with an optional path to a query, directory, or query suite inside the pack
6363

6464
If omitted, the default query suite for the language of the database being analyzed will be used. For more information, see the :ref:`examples <database-analyze-examples>` below.
@@ -250,7 +250,7 @@ For example, to execute all Python queries contained in the ``Functions`` direct
250250

251251
codeql database analyze <python-database> ../ql/python/ql/src/Functions/ --format=sarif-latest --output=python-analysis/python-results.sarif
252252

253-
If you do not have the codeql repository checked out, you can execute the same queries by specifying the query pack name and the path to the queries:
253+
If you do not have the CodeQL repository checked out, you can execute the same queries by specifying the query pack name and the path to the queries:
254254

255255
codeql database analyze --download <python-database> codeql/python-queries:Functions/ --format=sarif-latest --output=python-analysis/python-results.sarif
256256

docs/codeql/codeql-cli/creating-and-working-with-codeql-packs.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ If you already have a ``qlpack.yml`` file, you can edit it manually to convert i
4141

4242
#. Edit the ``name`` property so that it matches the format ``<scope>/<name>``, where ``<scope>`` is the name of the GitHub organization or user account that you will publish to.
4343
#. In the ``qlpack.yml`` file, include a ``version`` property with a semver identifier, as well as an optional ``dependencies`` block.
44-
#. Migrate the list of dependencies in ``libraryPathDependencies`` to the ``dependencies`` block. Specify the version range for each dependency. If the range is unimportant, or you are unsure of compatibility, you can specify ``"*"``, which indicates that any version is acceptable, with will default to the latest version when ``codeql pack install`` is run.
44+
#. Migrate the list of dependencies in ``libraryPathDependencies`` to the ``dependencies`` block. Specify the version range for each dependency. If the range is unimportant, or you are unsure of compatibility, you can specify ``"*"``, which indicates that any version is acceptable and will default to the latest version when ``codeql pack install`` is run.
4545

4646
For more information about the properties, see ":ref:`About CodeQL packs <about-codeql-packs>`."
4747

docs/codeql/codeql-cli/creating-codeql-query-suites.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ the reusable instructions to the current suite. For example::
240240
This will filter the queries in ``queries/cpp/custom`` to only include those that match the reusable conditions.
241241

242242
You can also create a suite definition using ``reusable-instructions.yml`` on
243-
queries in a different codeQL pack. If the ``.qls`` file is in the same CodeQL pack as
243+
queries in a different CodeQL pack. If the ``.qls`` file is in the same CodeQL pack as
244244
the queries, you can add a ``from`` field immediately after the ``apply``
245245
instruction::
246246

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Alternatively, you can download ``codeql.zip``, which contains the CLI for all s
9191
iv. Ensure the check-box labeled **Open "safe" files after downloading**.
9292
is unchecked.
9393

94-
1. Extract the zip archive
94+
2. Extract the zip archive
9595
~~~~~~~~~~~~~~~~~~~~~~~~~~
9696

9797
For Linux, Windows, and macOS users (version 10.14 "Mojave", and earlier)

docs/codeql/reusables/test-qlpack.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
.. code-block:: yaml
22
33
name: my-github-user/my-query-tests
4-
version: 0.0.0
54
dependencies:
65
my-github-user/my-custom-queries: ^1.2.3
76
extractor: java
87
tests: .
98
10-
This ``qlpack.yml`` file states that ``my-github-user/my-query-tests`` depends on ``my-github-user/my-custom-queries`` at a version greater than or equal to 1.2.3 and less than 2.0.0. It also declares that the CLI should use the Java ``extractor`` when creating test databases. The ``tests: .`` line declares that all ``.ql`` files in the pack should be run as tests when ``codeql test run`` is run with the ``--strict-test-discovery`` option.
9+
This ``qlpack.yml`` file states that ``my-github-user/my-query-tests`` depends on ``my-github-user/my-custom-queries`` at a version greater than or equal to 1.2.3 and less than 2.0.0. It also declares that the CLI should use the Java ``extractor`` when creating test databases. The ``tests: .`` line declares that all ``.ql`` files in the pack should be run as tests when ``codeql test run`` is run with the ``--strict-test-discovery`` option. Typically, test packs do not contain a ``version`` property. This prevents them from being inadvertently not published.

0 commit comments

Comments
 (0)