Skip to content

Commit a6836d8

Browse files
celinvaltedinski
authored andcommitted
Enable RMC on Ubuntu 18.04 rust-lang#393 (rust-lang#404)
Add support to Ubuntu 18.04 (rust-lang#393) Issue: Our python scripts use python 3.8+ while ubuntu 18.04 defaults to python 3.6. Changes: * Change our scripts to use constructs available in older python versions. * Modify workflows file to add ubuntu-18.04. * Make ubuntu scripts generic. * Change copyright check script to ignore directories and symbolic links to directories.
1 parent 5331504 commit a6836d8

File tree

9 files changed

+66
-11
lines changed

9 files changed

+66
-11
lines changed

.github/workflows/rmc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ${{ matrix.os }}
99
strategy:
1010
matrix:
11-
os: [macos-10.15, ubuntu-20.04]
11+
os: [macos-10.15, ubuntu-18.04, ubuntu-20.04]
1212
steps:
1313
- name: Checkout RMC
1414
uses: actions/checkout@v2
@@ -20,7 +20,7 @@ jobs:
2020

2121
- name: Install CBMC
2222
run: ./scripts/setup/${{ matrix.os }}/install_cbmc.sh
23-
23+
2424
- name: Install cbmc-viewer
2525
run: ./scripts/setup/install_viewer.sh 2.6
2626

scripts/check-cbmc-version.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import re
77
import sys
88
import subprocess
9+
from subprocess import PIPE
910

1011

1112
EXIT_CODE_SUCCESS = 0
@@ -16,8 +17,8 @@
1617
def cbmc_version():
1718
cmd = ["cbmc", "--version"]
1819
try:
19-
version = subprocess.run(cmd,
20-
capture_output=True, text=True, check=True)
20+
version = subprocess.run(cmd, stdout=PIPE, stderr=PIPE, check=True,
21+
universal_newlines=True)
2122
except (OSError, subprocess.SubprocessError) as error:
2223
print(error)
2324
print(f"Can't run command '{' '.join(cmd)}'")

scripts/check-cbmc-viewer-version.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import re
77
import sys
88
import subprocess
9+
from subprocess import PIPE
910

1011

1112
EXIT_CODE_SUCCESS = 0
@@ -16,8 +17,8 @@
1617
def cbmc_viewer_version():
1718
cmd = ["cbmc-viewer", "--version"]
1819
try:
19-
version = subprocess.run(cmd,
20-
capture_output=True, text=True, check=True)
20+
version = subprocess.run(cmd, stdout=PIPE, stderr=PIPE, check=True,
21+
universal_newlines=True)
2122
except (OSError, subprocess.SubprocessError) as error:
2223
print(error)
2324
print(f"Can't run command '{' '.join(cmd)}'")

scripts/ci/copyright_check.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
# SPDX-License-Identifier: Apache-2.0 OR MIT
44
import re
55
import sys
6+
import os.path as path
67

78
def copyright_check(filename):
9+
# Only check regular files (skip symbolic link to directories)
10+
if not path.isfile(filename):
11+
return True
12+
813
fo = open(filename)
914
lines = fo.readlines()
1015

scripts/rmc_flags.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
# Taken from https://github.com/python/cpython/blob/3.9/Lib/argparse.py#L858
99
# Cannot use `BooleanOptionalAction` with Python 3.8
1010
class BooleanOptionalAction(argparse.Action):
11+
""" Implements argparse.BooleanOptionalAction introduced on Python 3.9
12+
13+
This allows us to define an action as well as its negation to control a
14+
boolean option. For example, --default-checks and --no-default-checks
15+
options to control the same boolean property.
16+
"""
1117
def __init__(self,
1218
option_strings,
1319
dest,
@@ -47,6 +53,33 @@ def __call__(self, parser, namespace, values, option_string=None):
4753
def format_usage(self):
4854
return ' | '.join(self.option_strings)
4955

56+
class ExtendAction(argparse.Action):
57+
""" Implements the "extend" option added on Python 3.8.
58+
59+
Extend combines in one list all the arguments provided using the
60+
same option. For example, --c-lib <libA> --c-lib <libB> <libC> will
61+
generate a list [<libA>, <libB>, <libC>].
62+
"""
63+
def __init__(self,
64+
option_strings,
65+
dest,
66+
default=[],
67+
**kwargs):
68+
69+
if type(default) is not list:
70+
raise ValueError('default value for ExtendAction must be a list')
71+
72+
super().__init__(
73+
option_strings=option_strings,
74+
dest=dest,
75+
default=default,
76+
**kwargs)
77+
78+
def __call__(self, parser, namespace, values, option_string=None):
79+
items = getattr(namespace, self.dest, [])
80+
items.extend(values)
81+
setattr(namespace, self.dest, items)
82+
5083
# Add flags related to debugging output.
5184
def add_loudness_flags(make_group, add_flag, config):
5285
group = make_group(
@@ -62,7 +95,8 @@ def add_loudness_flags(make_group, add_flag, config):
6295
def add_linking_flags(make_group, add_flag, config):
6396
group = make_group("Linking flags",
6497
"Provide information about how to link the prover for RMC.")
65-
add_flag(group, "--c-lib", type=pl.Path, nargs="*", default=[], action="extend",
98+
add_flag(group, "--c-lib", type=pl.Path, nargs="*", default=[],
99+
action=ExtendAction,
66100
help="Link external C files referenced by Rust code")
67101
add_flag(group, "--function", default="main",
68102
help="Entry point for verification")

scripts/setup/ubuntu-18.04

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ubuntu

scripts/setup/ubuntu-20.04

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ubuntu

scripts/setup/ubuntu-20.04/install_cbmc.sh renamed to scripts/setup/ubuntu/install_cbmc.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
set -eu
66

7-
# Install CBMC 5.30.1 for Ubuntu 20.04
8-
9-
FILE="ubuntu-20.04-cbmc-5.30.1-Linux.deb"
7+
UBUNTU_VERSION=$(lsb_release -rs)
8+
FILE="ubuntu-${UBUNTU_VERSION}-cbmc-5.30.1-Linux.deb"
109
URL="https://github.com/diffblue/cbmc/releases/download/cbmc-5.30.1/$FILE"
1110

1211
set -x

scripts/setup/ubuntu-20.04/install_deps.sh renamed to scripts/setup/ubuntu/install_deps.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
set -eu
66

7+
# Dependencies.
78
DEPS=(
89
bison
910
cmake
@@ -20,19 +21,31 @@ DEPS=(
2021
ninja-build
2122
patch
2223
pkg-config
23-
python-is-python3
2424
python3-pip # Default in CI, but missing in AWS AMI
2525
software-properties-common
2626
wget
2727
zlib1g
2828
zlib1g-dev
2929
)
3030

31+
# Version specific dependencies.
32+
declare -A VERSION_DEPS
33+
VERSION_DEPS["20.04"]="python-is-python3"
34+
VERSION_DEPS["18.04"]=""
35+
3136
set -x
3237

3338
sudo apt-get --yes update
3439
sudo DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --yes "${DEPS[@]}"
3540

41+
UBUNTU_VERSION=$(lsb_release -rs)
42+
OTHER_DEPS="${VERSION_DEPS[${UBUNTU_VERSION}]:-""}"
43+
if [[ ! -z ${OTHER_DEPS} ]]
44+
then
45+
# This package was added on ubuntu 20.04.
46+
sudo DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --yes "${OTHER_DEPS[@]}"
47+
fi
48+
3649
# Add Python package dependencies
3750
PYTHON_DEPS=(
3851
toml # Used for parsing `cargo-rmc` config toml

0 commit comments

Comments
 (0)