opgpcard: Replace flagfile with environment variable
- A flagfile requires manual management with touch and rm, replace it with an environment variable that can be set more conveniently. - Removing tools/tests/opgpcard.rs is not necessary, the file it links to is always generated in build.rs, either with subplot tests or without. But it is always there, so cargo test does not fail for that reason.
This commit is contained in:
parent
db34132dda
commit
dfb7f3275d
4 changed files with 22 additions and 21 deletions
|
@ -145,8 +145,7 @@ subplot:
|
||||||
script:
|
script:
|
||||||
# make sure a virtual card is available, so that the subplot tests are
|
# make sure a virtual card is available, so that the subplot tests are
|
||||||
# generated
|
# generated
|
||||||
- touch tools/virtual-card-available
|
- CARD_BASED_TESTS=true cargo test
|
||||||
- cargo test
|
|
||||||
cache:
|
cache:
|
||||||
# inherit all general cache settings
|
# inherit all general cache settings
|
||||||
<<: *general_cache_config
|
<<: *general_cache_config
|
||||||
|
|
|
@ -9,21 +9,23 @@ fn main() {
|
||||||
// card is available. This is a kludge until Subplot can do
|
// card is available. This is a kludge until Subplot can do
|
||||||
// conditional scenarios
|
// conditional scenarios
|
||||||
// (https://gitlab.com/subplot/subplot/-/issues/20).
|
// (https://gitlab.com/subplot/subplot/-/issues/20).
|
||||||
let flagfile = Path::new("virtual-card-available");
|
match option_env!("CARD_BASED_TESTS") {
|
||||||
if flagfile.exists() {
|
Some(_) => {
|
||||||
subplot_build::codegen("subplot/opgpcard.subplot")
|
subplot_build::codegen("subplot/opgpcard.subplot")
|
||||||
.expect("failed to generate code with Subplot");
|
.expect("failed to generate code with Subplot");
|
||||||
println!("cargo:warning=generating subplot tests");
|
println!("cargo:warning=generated subplot tests");
|
||||||
} else {
|
}
|
||||||
// If we're not generating code from the subplot, we should at
|
None => {
|
||||||
// least create an empty file so that the tests/opgpcard.rs
|
// If we're not generating code from the subplot, we should at
|
||||||
// file can include it. Otherwise the build will fail.
|
// least create an empty file so that the tests/opgpcard.rs
|
||||||
println!("cargo:warning=flagfile not found");
|
// file can include it. Otherwise the build will fail.
|
||||||
let out_dir = std::env::var("OUT_DIR").unwrap();
|
println!("cargo:warning=did not generate subplot tests");
|
||||||
let include = Path::new(&out_dir).join("opgpcard.rs");
|
let out_dir = std::env::var("OUT_DIR").unwrap();
|
||||||
eprintln!("build.rs: include={}", include.display());
|
let include = Path::new(&out_dir).join("opgpcard.rs");
|
||||||
if !include.exists() {
|
eprintln!("build.rs: include={}", include.display());
|
||||||
File::create(include).unwrap();
|
if !include.exists() {
|
||||||
|
File::create(include).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,12 @@ docker run --rm -it \
|
||||||
-v root:/root \
|
-v root:/root \
|
||||||
-v cargo:/cargo \
|
-v cargo:/cargo \
|
||||||
-v $(pwd):/src \
|
-v $(pwd):/src \
|
||||||
|
-e CARD_BASED_TESTS=true \
|
||||||
registry.gitlab.com/openpgp-card/virtual-cards/smartpgp-builddeps sh -c '
|
registry.gitlab.com/openpgp-card/virtual-cards/smartpgp-builddeps sh -c '
|
||||||
sed -i "s/timeout=20/timeout=60/" /home/jcardsim/run-card.sh &&
|
sed -i "s/timeout=20/timeout=60/" /home/jcardsim/run-card.sh &&
|
||||||
/etc/init.d/pcscd start &&
|
/etc/init.d/pcscd start &&
|
||||||
su - -c "sh /home/jcardsim/run-card.sh >/dev/null" jcardsim &&
|
su - -c "sh /home/jcardsim/run-card.sh >/dev/null" jcardsim &&
|
||||||
cd /src/tools &&
|
cd /src/tools &&
|
||||||
if ! [ -e virtual-card-available ]; then rm -f tests/opgpcard.rs; fi &&
|
|
||||||
CARGO_TARGET_DIR=/cargo/ cargo update &&
|
CARGO_TARGET_DIR=/cargo/ cargo update &&
|
||||||
CARGO_TARGET_DIR=/cargo/ cargo build -vv &&
|
CARGO_TARGET_DIR=/cargo/ cargo build -vv &&
|
||||||
CARGO_TARGET_DIR=/cargo/ cargo test'
|
CARGO_TARGET_DIR=/cargo/ cargo test'
|
||||||
|
|
|
@ -17,9 +17,9 @@ The verification scenarios in this document assume the availability of
|
||||||
a virtual smart card. Specifically one described in
|
a virtual smart card. Specifically one described in
|
||||||
<https://gitlab.com/openpgp-card/virtual-cards>. The
|
<https://gitlab.com/openpgp-card/virtual-cards>. The
|
||||||
`openpgp-card/tools` crate is set up to generate tests only if the
|
`openpgp-card/tools` crate is set up to generate tests only if the
|
||||||
file `tools/virtual-card-available` exists, and the `openpgp-card`
|
environment variable `CARD_BASED_TESTS` is set (to any value),
|
||||||
repository `.gitlab-ci.yml` file is set up to create that file when
|
and the `openpgp-card` repository `.gitlab-ci.yml` file is set up to
|
||||||
the repository is tested in GitLab CI.
|
set that environment variable when the repository is tested in GitLab CI.
|
||||||
|
|
||||||
This means that if you run `cargo test`, no test code is normally
|
This means that if you run `cargo test`, no test code is normally
|
||||||
generated from this document. To run the tests locally, outside of
|
generated from this document. To run the tests locally, outside of
|
||||||
|
|
Loading…
Reference in a new issue