Skip to content

Commit 3890907

Browse files
committed
Update other articles to with details about packaging
In this commit: - Replace _QL pack_ with _CodeQL pack_ - Replace `about-ql-pack` references with `about-codeql-packs` - Replace examples using `libraryPathDependencies with `dependencies` - Update some examples to specify the optional `version` field - Update description of query specifiers to note that a path within a pack is valid.
1 parent d737b57 commit 3890907

17 files changed

+303
-240
lines changed

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

Lines changed: 77 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
About CodeQL packs
44
==================
55

6+
.. include:: ../reusables/beta-note-package-management.rst
7+
68
CodeQL packs are used to create, share, depend on, and run CodeQL queries and libraries. You can publish your own CodeQL packs and download packs created by others. CodeQL packs contain queries, library files, query suites, and metadata.
79

810
There are two types of CodeQL packs: query packs and library packs.
@@ -60,71 +62,114 @@ The following properties are supported in ``qlpack.yml`` files.
6062
- Required
6163
- Purpose
6264
* - ``name``
63-
- ``name: octo-org/security-queries``
65+
- .. code-block:: yaml
66+
67+
name: octo-org/security-queries
68+
6469
- All packs
65-
- The scope, where the CodeQL pack is published, and the name of the pack defined using alphanumeric characters and hyphens. It must be unique as CodeQL cannot differentiate between CodeQL packs with identical names. Use the pack name to specify queries to run using ``database analyze`` and to define dependencies between QL packs (see examples below).
70+
- The scope, where the CodeQL pack is published, and the name of the pack defined using alphanumeric characters and hyphens. It must be unique as CodeQL cannot differentiate between CodeQL packs with identical names. Use the pack name to specify queries to run using ``database analyze`` and to define dependencies between CodeQL packs (see examples below).
6671
* - ``version``
67-
- ``version: 0.0.0``
72+
- .. code-block:: yaml
73+
74+
version: 0.0.0
75+
6876
- All packs
6977
- A semantic version for this CodeQL pack that must adhere to the `SemVer v2.0.0 specification <https://semver.org/spec/v2.0.0.html>`__.
7078
* - ``dependencies``
7179
- .. code-block:: yaml
7280

73-
dependencies:
74-
codeql/cpp-all: ^0.0.2
81+
dependencies:
82+
codeql/cpp-all: ^0.0.2
7583

7684
- Packs that define CodeQL package dependencies on other packs
7785
- 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.
7886
* - ``defaultSuiteFile``
79-
- ``defaultSuiteFile: cpp-code-scanning.qls``
87+
- .. code-block:: yaml
88+
89+
defaultSuiteFile: cpp-code-scanning.qls
90+
8091
- Packs that export a set of default queries to run
8192
- 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.
8293
* - ``defaultSuite``
8394
- .. code-block:: yaml
8495

85-
defaultSuite:
86-
queries: .
87-
exclude:
88-
precision: medium
96+
defaultSuite:
97+
queries: .
98+
exclude:
99+
precision: medium
89100

90101
- Packs that export a set of default queries to run
91102
- 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.
92103
* - ``library``
93-
- ``library: true``
104+
- .. code-block:: yaml
105+
106+
library: true
107+
94108
- Library packs
95109
- A boolean value that indicates whether this pack is a library pack. Library packs do not contain queries and are not compiled. Query packs can ignore this field or explicitly set it to ``false``.
96110
* - ``suites``
97-
- ``suites: octo-org-query-suites``
111+
- .. code-block:: yaml
112+
113+
suites: octo-org-query-suites
114+
98115
- Optional
99-
- 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. QL 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 a package registry. For more information about query suites, see ":doc:`Creating CodeQL query suites <creating-codeql-query-suites>`."
100117
* - ``extractor``
101-
- ``javascript``
118+
- .. code-block:: yaml
119+
120+
extractor: javascript
121+
102122
- All test packs
103123
- 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>`."
104124
* - ``tests``
105-
- ``.``
106-
- Optional for test packs
107-
- 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.
108-
* - ``dbscheme`` TODO: Internal only. Delete?
109-
- ``semmlecode.python.dbscheme``
125+
- .. code-block:: yaml
126+
127+
tests: .
128+
129+
- Optional for test packs. Ignored for non-test packs.
130+
- 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.
131+
* - ``dbscheme``
132+
- .. code-block:: yaml
133+
134+
dbscheme: semmlecode.python.dbscheme
135+
110136
- Core language packs only
111137
- The path to the :ref:`database schema <codeql-database-schema>` for all libraries and queries written for this CodeQL language (see example below).
112-
* - ``upgrades`` TODO: Internal only. Delete?
113-
- ``.``
138+
* - ``upgrades``
139+
- .. code-block:: yaml
140+
141+
upgrades: .
142+
114143
- Core language packs only
115144
- 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.)
116145
* - ``authors``
117-
- ``example@github.com``
146+
- .. code-block:: yaml
147+
148+
authors: author1@github.com,author2@github.com
149+
118150
- All packs
119151
- Metadata that will be displayed on the packaging search page in the packages section of the account that the CodeQL pack is published to.
120-
* - ``licenses``
121-
- ``(LGPL-2.1 AND MIT)``
152+
* - ``license``
153+
- .. code-block:: yaml
154+
155+
license: MIT
156+
122157
- All packs
123158
- Metadata that will be displayed on the packaging search page in the packages section of the account that the CodeQL pack is published to. For a list of allowed licenses, see `SPDX License List <https://spdx.org/licenses/>`__ in the SPDX Specification.
124159
* - ``description``
125-
- ``Human-readable description of the contents of the CodeQL pack.``
160+
- .. code-block:: yaml
161+
162+
description: Human-readable description of the contents of the CodeQL pack.
163+
126164
- All packs
127165
- Metadata that will be displayed on the packaging search page in the packages section of the account that the CodeQL pack is published to.
166+
* - ``libraryPathDependencies``
167+
- .. code-block:: yaml
168+
169+
libraryPathDependencies: codeql/javascript-all
170+
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.
128173

129174
.. _about-codeql-pack-lock:
130175

@@ -166,9 +211,9 @@ When you write custom queries or tests, you should save them in custom CodeQL pa
166211
CodeQL packs for custom queries
167212
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
168213

169-
A custom QL 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>`."
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>`."
170215

171-
For example, a ``qlpack.yml`` file for a QL pack featuring custom C++ queries
216+
For example, a ``qlpack.yml`` file for a CodeQL pack featuring custom C++ queries
172217
and libraries may contain:
173218

174219
.. code-block:: yaml
@@ -179,7 +224,7 @@ and libraries may contain:
179224
codeql/cpp-all: ^0.1.2
180225
suites: my-custom-suites
181226
182-
where ``codeql/cpp-all`` is the name of the QL 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``.
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``.
183228

184229
CodeQL packs for custom test files
185230
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -249,10 +294,10 @@ contains:
249294
250295
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.
251296

252-
Tests for the core QL pack
253-
~~~~~~~~~~~~~~~~~~~~~~~~~~
297+
Tests for the core CodeQL pack
298+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
254299

255-
The ``qlpack.yml`` file for the tests for the core QL packs use the following properties: ``name``, ``dependencies``, ``extractor``, ``tests``.
300+
The ``qlpack.yml`` file for the tests for the core CodeQL packs use the following properties: ``name``, ``dependencies``, ``extractor``, ``tests``.
256301

257302
For example, the ``qlpack.yml`` file for `C/C++ analysis tests
258303
<https://github.com/github/codeql/blob/main/cpp/ql/test/qlpack.yml>`__
@@ -267,4 +312,4 @@ contains:
267312
extractor: cpp
268313
tests: .
269314
270-
The ``dependencies`` property always specifies the core QL 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.
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.

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ 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-
If omitted, the default query suite for the language
62-
of the database being analyzed will be used. For more information, see the
63-
:ref:`examples <database-analyze-examples>` below.
61+
- with an optional a version range
62+
- with an optional path to a query, directory, or query suite inside the pack
63+
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.
6465

6566
- ``--sarif-category``: an identifying category for the results. Used when
6667
you want to upload more than one set of results for a commit.
@@ -192,10 +193,10 @@ For more information, see `Analyzing a CodeQL database <https://docs.github.com/
192193
or `Code scanning API <https://docs.github.com/en/rest/reference/code-scanning>`__ in the GitHub documentation.
193194

194195
CodeQL query suites are ``.qls`` files that use directives to select queries to run
195-
based on certain metadata properties. The standard QL packs have metadata that specify
196+
based on certain metadata properties. The standard CodeQL packs have metadata that specify
196197
the location of the query suites used by code scanning, so the CodeQL CLI knows where to find these
197198
suite files automatically, and you don't have to specify the full path on the command line.
198-
For more information, see ":ref:`About QL packs <standard-ql-packs>`."
199+
For more information, see ":ref:`About CodeQL packs <standard-ql-packs>`."
199200

200201
The standard query suites are stored at the following paths in
201202
the CodeQL repository::
@@ -239,18 +240,23 @@ recursively, so any queries contained in subfolders will also be executed.
239240

240241
Important
241242

242-
You shouldn't specify the root of a :doc:`QL pack
243-
<about-ql-packs>` when executing ``database analyze``
243+
You shouldn't specify the root of a :doc:`CodeQL pack
244+
<about-codeql-packs>` when executing ``database analyze``
244245
as it contains some special queries that aren't designed to be used with
245246
the command. Rather, to run a wide range of useful queries, run one of the
246247
LGTM.com query suites.
247248

248-
For example, to execute all Python queries contained in the ``Functions``
249-
directory you would run::
249+
For example, to execute all Python queries contained in the ``Functions`` directory you would run::
250250

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

253-
A SARIF results file is generated. Specifying ``--format=sarif-latest`` ensures
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:
254+
255+
codeql database analyze --download <python-database> codeql/python-queries:Functions/ --format=sarif-latest --output=python-analysis/python-results.sarif
256+
257+
Use the ``--download`` flag to download the query pack if it isn't yet available locally.
258+
259+
After evaluating, a SARIF results file is generated. Specifying ``--format=sarif-latest`` ensures
254260
that the results are formatted according to the most recent SARIF specification
255261
supported by CodeQL.
256262

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@
33
CodeQL CLI reference
44
====================
55

6-
Learn more about the files you can use when running CodeQL processes and the results format and exit codes that CodeQL generates.
6+
Learn more about the files you can use when running CodeQL processes and the results format and exit codes that CodeQL generates.
77

88
.. toctree::
99
:titlesonly:
1010
:hidden:
1111

1212
about-codeql-packs
13-
about-ql-packs
1413
query-reference-files
1514
sarif-output
1615
exit-codes
1716
extractor-options
1817

19-
- :doc:`About CodeQL packs <about-codeql-packs>`: CodeQL packs are created with the CodeQL CLI and are used to create, depend on, publish, and run CodeQL queries and libraries.
20-
- :doc:`About QL packs <about-ql-packs>`: QL packs are used to organize the files used in CodeQL analysis. They
21-
contain queries, library files, query suites, and important metadata.
18+
- :doc:`About CodeQL packs <about-codeql-packs>`: CodeQL packs are created with the CodeQL CLI and are used to create, depend on, publish, and run CodeQL queries, libraries, and query suites.
2219
- :doc:`Query reference files <query-reference-files>`: A query reference file is text file that defines the location of one query to test.
2320
- :doc:`SARIF output <sarif-output>`: CodeQL supports SARIF as an output format for sharing static analysis results.
2421
- :doc:`Exit codes <exit-codes>`: The CodeQL CLI reports the status of each command it runs as an exit code.

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,26 @@ You must specify:
3434

3535
The ``codeql pack init`` command creates the directory structure and configuration files for a CodeQL pack. By default, the command creates a query pack. If you want to create a library pack, you must edit the ``qlpack.yml`` file to explicitly declare the file as a library pack by including the ``library:true`` property.
3636

37-
Modifying an existing QL pack to create a CodeQL pack
38-
-----------------------------------------------------
37+
Modifying an existing legacy CodeQL pack to create a CodeQL pack
38+
----------------------------------------------------------------
39+
3940
If you already have a ``qlpack.yml`` file, you can edit it manually to convert it into a CodeQL pack.
4041

4142
#. 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.
4243
#. 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.
4345

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

4648
Adding and installing dependencies to a CodeQL pack
4749
---------------------------------------------------
48-
You can add dependencies on CodeQL packs using the command ``codeql pack add``. You must specify the scope, name, and version range.
50+
You can add dependencies on CodeQL packs using the command ``codeql pack add``. You must specify the scope, name, and (optionally) a compatible version range.
4951

5052
::
5153

5254
codeql pack add <scope>/<name>@x.x.x <scope>/<other-name>
5355

54-
The version range is optional. If you leave off the version range, the latest version will be added. Otherwise, the latest version that satisfies the requested range will be added.
56+
If you leave off the version range, the latest version will be added. Otherwise, the latest version that satisfies the requested range will be added.
5557

5658
This command updates the ``qlpack.yml`` file with the requested dependencies and downloads them into the package cache. Please note that this command will reformat the file and remove all comments.
5759

@@ -67,7 +69,8 @@ This command downloads all dependencies to the shared cache on the local disk.
6769

6870
Note
6971

70-
Running the ``codeql pack add`` and ``codeql pack install`` commands will generate or update the ``qlpack.lock.yml`` file. This file should be checked-in to version control. The ``qlpack.lock.yml`` file contains the precise version numbers used by the pack.
72+
Running the ``codeql pack add`` and ``codeql pack install`` commands will generate or update the ``codeql-pack.lock.yml`` file. This file should be checked-in to version control. The ``codeql-pack.lock.yml`` file contains the precise version numbers used by the pack.
73+
For more information, see ":ref:`About codeql-pack.lock.yml files <about-codeql-pack-lock>`."
7174

7275
.. pull-quote::
7376

0 commit comments

Comments
 (0)