Open wks opened 1 year ago
The PR https://github.com/mmtk/mmtk-core/pull/916 introduced a Python script to edit Cargo.toml
to override the mmtk
dependency, and it works.
The Python script uses the tomlkit
module for modifying TOML while preserving its formatting and comments (although it is unnecessary because the testing is one-shot and automated). tomlkit
is in the apt-get repo of Ubuntu 22.04 (python3-tomlkit
) so we can install it as needed in the CI scripts.
If we only need to read Cargo.toml
, we can use the built-in tomllib
module introduced since Python 3.11 because the built-in tomllib
module is read-only -- it cannot write TOML.
An alternative to writing a custom Python script is using command-line utilities to query TOML contents. jq
does not support TOML natively. A recent version of fq
supports TOML, but the version of fq
in the apt-get repo of Ubuntu 22.04 is too old. The yq
utility is a wrapper of jq and it supports TOML. It is not part of the apt-get repo of Ubuntu 22.04, but it can be installed via pip
.
Currently,
ci-common.sh
gets a list of features of mmtk-core by grepping the Cargo.toml file as text. This method is brittle w.r.t. formatting. For example, if I define a feature dependency with comment, like this:The current
ci-common.sh
will consider all lines not starting with#
(including comment lines that have indents) as features. As a reault, it will attempt to execute the following command in the command line:which results in error:
As a workaround, we can rewrite such comments. But I think we should parse
Cargo.toml
as TOML (or letcargo metadata
to output JSON instead).Using the command line tool
jq
, the following lineprints a list of features:
And if we add the following section to
Cargo.toml
:Then the following command
can print out the mutural exclusive groups in a JSON format:
and the following can parse it into a CSV:
Of course we can always use a Python script to parse JSON and generate all combinations of possible feature sets.