Skip to content

Fix ci-common.sh to parse features in a more robust way #856

@wks

Description

@wks

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:

vo_bit = [
    # VO bits for dead objects must have been cleared by the end of each GC.
    # Native MarkSweep only ensures this in eager sweeping mode.
    "eager_sweeping"
]

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:

cargo build --features vm_space,ro_space,code_space,vo_bit,# VO bits for dead objects must have been cleared by the end of each GC.,# Native MarkSweep only ensures this in eager sweeping 'mode.,"eager_sweeping",],is_mmtk_object,object_pinning,immix_non_moving,immix_smaller_block,immix_zero_on_release,sanity,analysis,nogc_lock_free,nogc_no_zeroing,single_worker,extreme_assertions,nogc_multi_space,work_packet_stats,malloc_counted_size'

which results in error:

error: Found argument 'VO' which wasn't expected, or isn't valid in this context

As a workaround, we can rewrite such comments. But I think we should parse Cargo.toml as TOML (or let cargo metadata to output JSON instead).

Using the command line tool jq, the following line

cargo metadata --format-version 1 | jq '.packages[] | select(.name? == "mmtk") | .features | keys | .[]' -r

prints a list of features:

analysis
code_space
default
eager_sweeping
extreme_assertions
immix_non_moving
immix_smaller_block
immix_zero_on_release
is_mmtk_object
jemalloc-sys
malloc_counted_size
malloc_jemalloc
malloc_mark_sweep
malloc_mimalloc
malloc_native_mimalloc
mimalloc-sys
nogc_lock_free
nogc_multi_space
nogc_no_zeroing
object_pinning
perf_counter
pfm
ro_space
sanity
single_worker
vm_space
vo_bit
work_packet_stats

And if we add the following section to Cargo.toml:

# Cargo doesn't care what we put into package.metadata
[package.metadata.mutex_groups]
malloc = ["malloc_mimalloc", "malloc_jemalloc", "malloc_native_mimalloc"]
marksweepallocation = ["eager_sweeping", "malloc_mark_sweep"]

Then the following command

cargo metadata --format-version 1 | jq '.packages[] | select(.name? == "mmtk") | .metadata.mutex_groups'

can print out the mutural exclusive groups in a JSON format:

{
  "malloc": [
    "malloc_mimalloc",
    "malloc_jemalloc",
    "malloc_native_mimalloc"
  ],
  "marksweepallocation": [
    "eager_sweeping",
    "malloc_mark_sweep"
  ]
}

and the following can parse it into a CSV:

$ cargo metadata --format-version 1 | jq '.packages[] | select(.name? == "mmtk") | .metadata.mutex_groups | .[] | @csv' -r
"malloc_mimalloc","malloc_jemalloc","malloc_native_mimalloc"
"eager_sweeping","malloc_mark_sweep"

Of course we can always use a Python script to parse JSON and generate all combinations of possible feature sets.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P-normalPriority: Normal.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions