Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: updates for cargo-llvm-cov 0.5 #2619

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ jobs:
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- run: python -m pip install -U pip nox
- run: cargo xtask coverage --output-lcov coverage.lcov
- run: nox -s coverage
- uses: codecov/codecov-action@v2
with:
file: coverage.lcov
Expand Down
130 changes: 103 additions & 27 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,56 @@
import os
import re
import subprocess
import sys
import time
from glob import glob
from pathlib import Path
from typing import Any, Dict, List

import nox

nox.options.sessions = ["test", "clippy", "fmt"]


@nox.session(venv_backend="none")
def test(session: nox.Session):
test_rust(session)
test_py(session)
def test(session: nox.Session, env: Dict[str, str] = None) -> None:
test_rust(session, env=env)
test_py(session, env=env)


@nox.session(name="test-rust", venv_backend="none")
def test_rust(session: nox.Session):
session.run("cargo", "test", external=True)
session.run("cargo", "test", "--features=abi3", external=True)
session.run("cargo", "test", "--features=full", external=True)
session.run("cargo", "test", "--features=abi3 full", external=True)
def test_rust(session: nox.Session, env: Dict[str, str] = None):
_run(session, *_cargo_test_package("pyo3-build-config"), env=env, external=True)
_run(session, *_cargo_test_package("pyo3-macros-backend"), env=env, external=True)
_run(session, *_cargo_test_package("pyo3-macros"), env=env, external=True)
_run(session, *_cargo_test_package("pyo3-ffi"), env=env, external=True)
_run(session, "cargo", "test", env=env, external=True)
_run(session, "cargo", "test", "--features=abi3", env=env, external=True)
_run(session, "cargo", "test", "--features=full", env=env, external=True)
_run(session, "cargo", "test", "--features=abi3 full", env=env, external=True)


@nox.session(name="test-py", venv_backend="none")
def test_py(session):
session.run("nox", "-f", "pytests/noxfile.py", external=True)
def test_py(session: nox.Session, env: Dict[str, str] = None) -> None:
_run(session, "nox", "-f", "pytests/noxfile.py", env=env, external=True)
for example in glob("examples/*/noxfile.py"):
session.run("nox", "-f", example, external=True)
_run(session, "nox", "-f", example, env=env, external=True)


@nox.session(venv_backend="none")
def coverage(session: nox.Session) -> None:
env = _get_coverage_env()
test(session, env=env)
_run(
session,
*_LLVM_COV_COMMAND,
"report",
"--lcov",
"--output-path",
"coverage.lcov",
env=env,
external=True,
)


@nox.session
Expand All @@ -39,19 +61,20 @@ def fmt(session: nox.Session):

@nox.session(name="fmt-rust", venv_backend="none")
def fmt_rust(session: nox.Session):
session.run("cargo", "fmt", "--all", "--check", external=True)
_run(session, "cargo", "fmt", "--all", "--check", external=True)


@nox.session(name="fmt-py")
def fmt_py(session: nox.Session):
session.install("black==22.3.0")
session.run("black", ".", "--check")
_run(session, "black", ".", "--check")


@nox.session(venv_backend="none")
def clippy(session: nox.Session) -> None:
for feature_set in ["full", "abi3 full"]:
session.run(
_run(
session,
"cargo",
"clippy",
f"--features={feature_set}",
Expand All @@ -65,31 +88,43 @@ def clippy(session: nox.Session) -> None:

@nox.session(venv_backend="none")
def publish(session: nox.Session) -> None:
session.run(
_run(
session,
"cargo",
"publish",
"--manifest-path",
"pyo3-build-config/Cargo.toml",
external=True,
)
time.sleep(10)
session.run(
_run(
session,
"cargo",
"publish",
"--manifest-path",
"pyo3-macros-backend/Cargo.toml",
external=True,
)
time.sleep(10)
session.run(
"cargo", "publish", "--manifest-path", "pyo3-macros/Cargo.toml", external=True
_run(
session,
"cargo",
"publish",
"--manifest-path",
"pyo3-macros/Cargo.toml",
external=True,
)
time.sleep(10)
session.run(
"cargo", "publish", "--manifest-path", "pyo3-ffi/Cargo.toml", external=True
_run(
session,
"cargo",
"publish",
"--manifest-path",
"pyo3-ffi/Cargo.toml",
external=True,
)
time.sleep(10)
session.run("cargo", "publish", external=True)
_run(session, "cargo", "publish", external=True)


@nox.session(venv_backend="none")
Expand Down Expand Up @@ -156,7 +191,8 @@ def __init__(self):
@nox.session(name="build-emscripten", venv_backend="none")
def build_emscripten(session: nox.Session):
info = EmscriptenInfo()
session.run(
_run(
session,
"make",
"-C",
str(info.emscripten_dir),
Expand Down Expand Up @@ -192,20 +228,24 @@ def test_emscripten(session: nox.Session):
)
session.env["CARGO_BUILD_TARGET"] = target
session.env["PYO3_CROSS_LIB_DIR"] = pythonlibdir
session.run("rustup", "target", "add", target, "--toolchain", "stable")
session.run(
"bash", "-c", f"source {info.builddir/'emsdk/emsdk_env.sh'} && cargo test"
_run(session, "rustup", "target", "add", target, "--toolchain", "stable")
_run(
session,
"bash",
"-c",
f"source {info.builddir/'emsdk/emsdk_env.sh'} && cargo test",
)


@nox.session(name="build-guide", venv_backend="none")
def build_guide(session: nox.Session):
session.run("mdbook", "build", "-d", "../target/guide", "guide", *session.posargs)
_run(session, "mdbook", "build", "-d", "../target/guide", "guide", *session.posargs)


@nox.session(name="address-sanitizer", venv_backend="none")
def address_sanitizer(session: nox.Session):
session.run(
_run(
session,
"cargo",
"+nightly",
"test",
Expand All @@ -230,3 +270,39 @@ def _get_rust_target() -> str:


_HOST_LINE_START = "host: "

_LLVM_COV_COMMAND = [
"cargo",
"llvm-cov",
"--package=pyo3",
"--package=pyo3-build-config",
"--package=pyo3-macros-backend",
"--package=pyo3-macros",
"--package=pyo3-ffi",
]


def _cargo_test_package(package: str) -> List[str]:
return ["cargo", "test", "--manifest-path", f"{package}/Cargo.toml"]


def _get_coverage_env() -> Dict[str, str]:
env = {}
output = subprocess.check_output([*_LLVM_COV_COMMAND, "show-env"], text=True)

for line in output.strip().splitlines():
(key, value) = line.split("=", maxsplit=1)
env[key] = value.strip('"')

# Ensure that examples/ and pytests/ all build to the correct target directory to collect
# coverage artifacts.
env["CARGO_TARGET_DIR"] = env["CARGO_LLVM_COV_TARGET_DIR"]

return env


def _run(session: nox.Session, *args: Any, **kwargs: Any) -> None:
"""Wrapper for _run(session, which creates nice groups on GitHub Actions."""
if "GITHUB_ACTIONS" in os.environ:
print("::group::", end=None)
session.run(*args, **kwargs)
4 changes: 2 additions & 2 deletions xtask/src/llvm_cov.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{collections::HashMap, process::Command};
pub fn run(opts: CoverageOpts) -> Result<()> {
let env = get_coverage_env()?;

cli::run(llvm_cov_command(&["clean", "--workspace"]).envs(&env))?;
cli::run(llvm_cov_command(&["clean"]).envs(&env))?;

cli::run(
Command::new("cargo")
Expand Down Expand Up @@ -46,7 +46,7 @@ pub fn run(opts: CoverageOpts) -> Result<()> {
crate::pytests::run(&env)?;

cli::run(
llvm_cov_command(&["--no-run", "--lcov", "--output-path", &opts.output_lcov]).envs(&env),
llvm_cov_command(&["report", "--lcov", "--output-path", &opts.output_lcov]).envs(&env),
)?;

Ok(())
Expand Down