Skip to content

Commit 3f7a34d

Browse files
committed
Merge branch 'aeisenberg/about-codeql-packs' into aeisenberg/codeql-workspace-docs
2 parents 137b068 + 9e6e37a commit 3f7a34d

File tree

5 files changed

+18
-23
lines changed

5 files changed

+18
-23
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ 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 Container registry <https://github.com/orgs/codeql/packages>`__.`
19-
The `CodeQL repository <https://github.com/github/codeql>`__ contains sources for the standard CodeQL packs for all supported languages.
18+
The standard CodeQL packages for all supported languages are published in the `GitHub Container registry <https://github.com/orgs/codeql/packages>`__.
19+
The `CodeQL repository <https://github.com/github/codeql>`__ contains source files for the standard CodeQL packs for all supported languages.
2020

2121
.. _codeql-pack-structure:
2222

2323
CodeQL pack structure
2424
---------------------
2525

26-
A CodeQL pack must contain a file called ``qlpack.yml`` in its root directory. In the ``qlpack.yml`` file, the ``name:`` field must have a value that follows the format of ``<scope>/<pack>``, where ``<scope>`` is the GitHub organization or user account that the pack will be published to and ``<pack>`` is the name of the pack. Additionally, query packs contain a ``codeql-pack.lock.yml`` file that contains the resolved dependencies of the pack. This file is generated during a call to the ``codeql pack install`` command, is not meant to be edited by hand, and should be added to your version control system.
26+
A CodeQL pack must contain a file called ``qlpack.yml`` in its root directory. In the ``qlpack.yml`` file, the ``name:`` field must have a value that follows the format of ``<scope>/<pack>``, where ``<scope>`` is the GitHub organization or user account that the pack will be published to and ``<pack>`` is the name of the pack. Additionally, query packs and library packs with CodeQL tests contain a ``codeql-pack.lock.yml`` file that contains the resolved dependencies of the pack. This file is generated during a call to the ``codeql pack install`` command, is not meant to be edited by hand, and should be added to your version control system.
2727

2828
The other files and directories within the pack should be logically organized. For example, typically:
2929

@@ -38,13 +38,13 @@ When executing query-related commands, CodeQL first looks in siblings of the ins
3838
Then it checks the package cache for CodeQL packs which have been downloaded. This means that when you are developing queries locally, the local packages
3939
in the installation directory override packages of the same name in the package cache, so that you can test your local changes.
4040

41-
The metadata in each `qlpack.yml`` file tells
41+
The metadata in each ``qlpack.yml`` file tells
4242
CodeQL how to compile any queries in the pack, what libraries the pack depends on, and where to
4343
find query suite definitions.
4444

4545
The contents of the CodeQL pack (queries or libraries used in CodeQL analysis) is included in the same directory as ``qlpack.yml``, or its subdirectories.
4646

47-
The location of ``qlpack.yml`` defines the library path for the content of the CodeQL pack. That is, for all ``.ql`` and ``.qll`` files in the pack, CodeQL will resolve all import statements relative to the ``qlpack.yml`` at the pack's root.
47+
The directory containing the ``qlpack.yml`` file serves as the root directory for the content of the CodeQL pack. That is, for all ``.ql`` and ``.qll`` files in the pack, CodeQL will resolve all import statements relative to the directory containing the ``qlpack.yml`` file at the pack's root.
4848

4949
.. _codeqlpack-yml-properties:
5050

@@ -119,14 +119,14 @@ The following properties are supported in ``qlpack.yml`` files.
119119

120120
extractor: javascript
121121

122-
- All test packs
123-
- The CodeQL language extractor to use when the CLI creates a database in the pack. For more information about testing queries, see ":doc:`Testing custom queries <testing-custom-queries>`."
122+
- All packs containing CodeQL tests
123+
- The CodeQL language extractor to use when running the CodeQL tests in the pack. For more information about testing queries, see ":doc:`Testing custom queries <testing-custom-queries>`."
124124
* - ``tests``
125125
- .. code-block:: yaml
126126

127127
tests: .
128128

129-
- Optional for test packs. Ignored for non-test packs.
129+
- Optional for packs containing CodeQL tests. Ignored for packs without tests.
130130
- The path to a directory within the pack that contains tests, defined relative to the pack directory. Use ``.`` to specify the whole pack. Any queries in this directory are run as tests when ``test run`` is run with the ``--strict-test-discovery`` option. These queries are ignored by query suite definitions that use ``queries`` or ``qlpack`` instructions to ask for all queries in a particular pack. If this property is missing, then ``.`` is assumed.
131131
* - ``dbscheme``
132132
- .. code-block:: yaml
@@ -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 database upgrade scripts, defined relative to the pack directory. Database upgrades are used internally to ensure a database created with a different version of the CodeQL CLI is compatible with the current version.
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 that a database created with a different version of the CodeQL CLI is compatible with the current version of the CLI.
145145
* - ``authors``
146146
- .. code-block:: yaml
147147

@@ -176,7 +176,7 @@ The following properties are supported in ``qlpack.yml`` files.
176176
About ``codeql-pack.lock.yml`` files
177177
------------------------------------
178178

179-
``codeql-pack.lock.yml`` files store the versions of the resolved transitive dependencies of a CodeQL pack. This file is created by the ``codeql pack install`` if it does not already exist and should be added to your version control system. The ``dependencies`` section of the ``qlpack.yml`` file contains version ranges that are compatible with the pack. The ``codeql-pack.lock.yml`` file locks the versions to precise dependencies. This ensures that anyone running ``codeql pack install`` on this the pack will always retrieve the same versions of dependencies even if newer compatible versions exist. Only query packs can have ``codeql-pack.lock.yml`` files. This is because library packs are not compiled independently of query packs. Without being compiled, there is no need to specify precise versions of their dependencies.
179+
``codeql-pack.lock.yml`` files store the versions of the resolved transitive dependencies of a CodeQL pack. This file is created by the ``codeql pack install`` command if it does not already exist and should be added to your version control system. The ``dependencies`` section of the ``qlpack.yml`` file contains version ranges that are compatible with the pack. The ``codeql-pack.lock.yml`` file locks the versions to precise dependencies. This ensures that running ``codeql pack install`` on this the pack will always retrieve the same versions of dependencies even if newer compatible versions exist.
180180

181181
For example, if a ``qlpack.yml`` file contains the following dependencies:
182182

@@ -199,15 +199,16 @@ The ``codeql-pack.lock.yml`` file will contain something like the following:
199199
my-user/transitive-dependency:
200200
version: 1.2.4
201201
202-
203202
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. For more information about CodeQL workspaces and resolving dependencies from source, see ":doc:`About CodeQL Workspaces <about-codeql-workspaces>`."
204203

204+
In most cases, the ``codeql-pack.lock.yml`` file is only relevant for query packs since library packs are non-executable and usually do not need their transitive dependencies to be fixed. The exception to this is for library packs that contain tests. In this case, the ``codeql-pack.lock.yml`` file is used to ensure that the tests are always run with the same versions of dependencies to avoid spurious failures when there are mismatched dependencies.
205+
205206
.. _custom-codeql-packs:
206207

207208
Examples of custom CodeQL packs
208209
-------------------------------
209210

210-
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>`__.
211+
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>`__.
211212

212213
CodeQL packs for custom libraries
213214
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ You can also specify:
5959
- a path to a directory containing query files
6060
- a path to a query suite file
6161
- the name of a CodeQL query pack
62-
- with an optional version range
63-
- with an optional path to a query, directory, or query suite inside the pack
62+
- with an optional version range
63+
- with an optional path to a query, directory, or query suite inside the pack
6464

6565
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.
6666

@@ -171,12 +171,6 @@ For example, to execute all Python queries contained in the ``Functions`` direct
171171

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

174-
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::
175-
176-
codeql database analyze --download <python-database> codeql/python-queries:Functions/ --format=sarif-latest --output=python-analysis/python-results.sarif
177-
178-
Use the ``--download`` flag to download the query pack if it isn't yet available locally.
179-
180174
When the analysis has finished, a SARIF results file is generated. Specifying ``--format=sarif-latest`` ensures
181175
that the results are formatted according to the most recent SARIF specification
182176
supported by CodeQL.

docs/codeql/codeql-cli/query-reference-files.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Example
3939
A query reference file to test a JavaScript alert query:
4040
`DeadAngularJSEventListener.qlref <https://github.com/github/codeql/blob/main/javascript/ql/test/query-tests/AngularJS/DeadAngularJSEventListener/DeadAngularJSEventListener.qlref>`__
4141

42-
The `CodeQL pack <https://github.com/github/codeql/blob/main/javascript/ql/test/qlpack.yml>`__
42+
The ```qlpack.yml`` file <https://github.com/github/codeql/blob/main/javascript/ql/test/qlpack.yml>`__
4343
for the CodeQL pack at ``javascript/ql/test`` defines ``codeql/javascript-queries`` as
4444
a dependency. So the query reference file defines the location of the query relative
4545
to the ``codeql/javascript-queries`` CodeQL pack::

docs/codeql/codeql-cli/using-custom-queries-with-the-codeql-cli.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ library files, query suites, and important metadata. Their root directory must
6464
contain a file named ``qlpack.yml``. Your custom queries should be saved in the
6565
CodeQL pack root, or its subdirectories.
6666

67-
For each CodeQL pack, the ``qlpack.yml`` file includes information that tells CodeQL
67+
For each CodeQL pack, the ``qlpack.yml`` file includes information that tells the CodeQL CLI
6868
how to compile the queries, which other CodeQL packs and libraries the pack
6969
depends on, and where to find query suite definitions. For more information
7070
about what to include in this file, see ":ref:`About CodeQL packs <codeqlpack-yml-properties>`."

docs/codeql/reusables/test-qlpack.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
extractor: java
77
tests: .
88
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 published.
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 you from accidentally publishing them.

0 commit comments

Comments
 (0)