You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/codeql/codeql-cli/about-codeql-packs.rst
+64-39Lines changed: 64 additions & 39 deletions
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ There are two types of CodeQL packs: query packs and library packs.
15
15
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>`."
16
16
17
17
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>`__.`
19
19
The `CodeQL repository <https://github.com/github/codeql>`__ contains sources for the standard CodeQL packs for all supported languages.
20
20
21
21
.. _codeql-pack-structure:
@@ -59,7 +59,7 @@ The following properties are supported in ``qlpack.yml`` files.
59
59
60
60
* - Property
61
61
- Example
62
-
- Required
62
+
- Required by
63
63
- Purpose
64
64
* - ``name``
65
65
- .. code-block:: yaml
@@ -82,14 +82,14 @@ The following properties are supported in ``qlpack.yml`` files.
82
82
codeql/cpp-all: ^0.0.2
83
83
84
84
- 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.
86
86
* - ``defaultSuiteFile``
87
87
- .. code-block:: yaml
88
88
89
89
defaultSuiteFile: cpp-code-scanning.qls
90
90
91
91
- 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.
93
93
* - ``defaultSuite``
94
94
- .. code-block:: yaml
95
95
@@ -99,7 +99,7 @@ The following properties are supported in ``qlpack.yml`` files.
99
99
precision: medium
100
100
101
101
- 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.
103
103
* - ``library``
104
104
- .. code-block:: yaml
105
105
@@ -113,7 +113,7 @@ The following properties are supported in ``qlpack.yml`` files.
113
113
suites: octo-org-query-suites
114
114
115
115
- 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>`."
117
117
* - ``extractor``
118
118
- .. code-block:: yaml
119
119
@@ -141,7 +141,7 @@ The following properties are supported in ``qlpack.yml`` files.
141
141
upgrades: .
142
142
143
143
- 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.
145
145
* - ``authors``
146
146
- .. code-block:: yaml
147
147
@@ -169,7 +169,7 @@ The following properties are supported in ``qlpack.yml`` files.
169
169
libraryPathDependencies: codeql/javascript-all
170
170
171
171
- 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.
173
173
174
174
.. _about-codeql-pack-lock:
175
175
@@ -199,6 +199,9 @@ The ``codeql-pack.lock.yml`` file will contain something like the following:
199
199
my-user/transitive-dependency:
200
200
version: 1.2.4
201
201
202
+
..
203
+
TODO: Add a link to the CodeQL CLI documentation for query resolution, specifically in regards to resolving from source
204
+
202
205
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.
203
206
204
207
.. _custom-codeql-packs:
@@ -208,26 +211,43 @@ Examples of custom CodeQL packs
208
211
209
212
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>`__.
210
213
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
+
211
231
CodeQL packs for custom queries
212
232
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
213
233
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:
218
235
219
236
.. code-block:: yaml
220
237
221
238
name: my-github-user/my-custom-queries
222
239
version: 1.2.3
223
240
dependencies:
224
241
codeql/cpp-all: ^0.1.2
242
+
my-github-user/my-custom-libraries: ^1.2.3
225
243
suites: my-custom-suites
226
244
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>`."
228
248
229
-
CodeQL packs for custom test files
230
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
249
+
CodeQL packs for custom tests
250
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
231
251
232
252
For custom CodeQL packs containing test files, you also need to include an
233
253
``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
246
266
Each of the languages in the CodeQL repository has four main CodeQL packs:
247
267
248
268
- 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``
250
270
- 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``
254
274
255
275
Core library pack
256
276
~~~~~~~~~~~~~~~~~
257
277
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
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.
296
318
297
319
Tests for the core CodeQL pack
298
320
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
299
321
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
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.
Copy file name to clipboardExpand all lines: docs/codeql/codeql-cli/analyzing-databases-with-the-codeql-cli.rst
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,7 @@ You can also specify:
58
58
- a path to a directory containing query files
59
59
- a path to a query suite file
60
60
- the name of a CodeQL query pack
61
-
- with an optional a version range
61
+
- with an optional version range
62
62
- with an optional path to a query, directory, or query suite inside the pack
63
63
64
64
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
Copy file name to clipboardExpand all lines: docs/codeql/codeql-cli/creating-and-working-with-codeql-packs.rst
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ If you already have a ``qlpack.yml`` file, you can edit it manually to convert i
41
41
42
42
#. 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.
43
43
#. 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.
45
45
46
46
For more information about the properties, see ":ref:`About CodeQL packs <about-codeql-packs>`."
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