123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- rust-trybuild works by running "cargo". But antioxidant-build-system tries
- to replace cargo by antioxidant. For now, add an "antioxidant" feature
- that adds stubs. If (when?) later antioxidant is extracted in a tool
- with a binary that can be run by rust-trybuild, the stubs can be replaced
- by a ‘real’ implementation targeting antioxidant and then sent upstream.
- Additionally, to avoid cycles, remove some dependencies when building for
- antioxidant.
- diff -r -U3 trybuild-1.0.54/Cargo.toml trybuild-1.0.54-new/Cargo.toml
- --- trybuild-1.0.54/Cargo.toml 1970-01-01 01:00:01.000000000 +0100
- +++ trybuild-1.0.54-new/Cargo.toml 2022-09-08 17:26:17.395202204 +0200
- @@ -48,3 +48,4 @@
-
- [features]
- diff = ["dissimilar"]
- +antioxidant = []
- diff -r -U3 trybuild-1.0.54/Cargo.toml.orig trybuild-1.0.54-new/Cargo.toml.orig
- --- trybuild-1.0.54/Cargo.toml.orig 1973-11-29 22:33:09.000000000 +0100
- +++ trybuild-1.0.54-new/Cargo.toml.orig 2022-09-08 17:20:40.399089289 +0200
- @@ -1,3 +1,4 @@
- +# Changed by Maxime Devos, 2022 (see: LICENSE-APACHE 4b)
- [package]
- name = "trybuild"
- version = "1.0.54"
- @@ -16,6 +17,7 @@
- # output. Currently unix-only. If you test this out, please provide any feedback
- # in https://github.com/dtolnay/trybuild/issues/41.
- diff = ["dissimilar"]
- +antioxidant = []
-
- [dependencies]
- dissimilar = { version = "1.0", optional = true }
- diff -r -U3 trybuild-1.0.54/src/directory.rs trybuild-1.0.54-new/src/directory.rs
- --- trybuild-1.0.54/src/directory.rs 1973-11-29 22:33:09.000000000 +0100
- +++ trybuild-1.0.54-new/src/directory.rs 2022-09-08 17:25:19.703186994 +0200
- @@ -1,11 +1,14 @@
- +// Changed by Maxime Devos, 2022 (see: LICENSE-APACHE 4b)
- +#[cfg(not(feature = "antioxidant"))]
- use serde::{Deserialize, Deserializer, Serialize};
- use std::borrow::Cow;
- use std::ffi::OsString;
- use std::io;
- use std::path::{Path, PathBuf};
-
- -#[derive(Clone, Debug, Serialize)]
- -#[serde(transparent)]
- +#[derive(Clone, Debug)]
- +#[cfg_attr(not(feature = "antioxidant"), derive(Clone, Debug, Serialize))]
- +#[cfg_attr(not(feature = "antioxidant"), serde(transparent))]
- pub struct Directory {
- path: PathBuf,
- }
- @@ -42,6 +45,7 @@
- }
- }
-
- +#[cfg(not(feature = "antioxidant"))]
- impl<'de> Deserialize<'de> for Directory {
- fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
- where
- diff -r -U3 trybuild-1.0.54/src/error.rs trybuild-1.0.54-new/src/error.rs
- --- trybuild-1.0.54/src/error.rs 1973-11-29 22:33:09.000000000 +0100
- +++ trybuild-1.0.54-new/src/error.rs 2022-09-08 17:24:53.919179665 +0200
- @@ -1,3 +1,5 @@
- +// Changed by Maxime Devos, 2022 (see: LICENSE-APACHE 4b)
- +#[cfg(not(feature = "antioxidant"))]
- use glob::{GlobError, PatternError};
- use std::env;
- use std::ffi::OsString;
- @@ -9,18 +11,23 @@
- pub enum Error {
- Cargo(io::Error),
- CargoFail,
- + #[cfg(not(feature = "antioxidant"))]
- Glob(GlobError),
- Io(io::Error),
- + #[cfg(not(feature = "antioxidant"))]
- Metadata(serde_json::Error),
- Mismatch,
- Open(PathBuf, io::Error),
- + #[cfg(not(feature = "antioxidant"))]
- Pattern(PatternError),
- PkgName(env::VarError),
- ProjectDir,
- ReadStderr(io::Error),
- RunFailed,
- ShouldNotHaveCompiled,
- + #[cfg(not(feature = "antioxidant"))]
- TomlDe(toml::de::Error),
- + #[cfg(not(feature = "antioxidant"))]
- TomlSer(toml::ser::Error),
- UpdateVar(OsString),
- WriteStderr(io::Error),
- @@ -35,11 +42,14 @@
- match self {
- Cargo(e) => write!(f, "failed to execute cargo: {}", e),
- CargoFail => write!(f, "cargo reported an error"),
- + #[cfg(not(feature = "antioxidant"))]
- Glob(e) => write!(f, "{}", e),
- Io(e) => write!(f, "{}", e),
- + #[cfg(not(feature = "antioxidant"))]
- Metadata(e) => write!(f, "failed to read cargo metadata: {}", e),
- Mismatch => write!(f, "compiler error does not match expected error"),
- Open(path, e) => write!(f, "{}: {}", path.display(), e),
- + #[cfg(not(feature = "antioxidant"))]
- Pattern(e) => write!(f, "{}", e),
- PkgName(e) => write!(f, "failed to detect CARGO_PKG_NAME: {}", e),
- ProjectDir => write!(f, "failed to determine name of project dir"),
- @@ -48,7 +58,9 @@
- ShouldNotHaveCompiled => {
- write!(f, "expected test case to fail to compile, but it succeeded")
- }
- + #[cfg(not(feature = "antioxidant"))]
- TomlDe(e) => write!(f, "{}", e),
- + #[cfg(not(feature = "antioxidant"))]
- TomlSer(e) => write!(f, "{}", e),
- UpdateVar(var) => write!(
- f,
- @@ -71,12 +83,14 @@
- }
- }
-
- +#[cfg(not(feature = "antioxidant"))]
- impl From<GlobError> for Error {
- fn from(err: GlobError) -> Self {
- Error::Glob(err)
- }
- }
-
- +#[cfg(not(feature = "antioxidant"))]
- impl From<PatternError> for Error {
- fn from(err: PatternError) -> Self {
- Error::Pattern(err)
- @@ -89,12 +103,14 @@
- }
- }
-
- +#[cfg(not(feature = "antioxidant"))]
- impl From<toml::de::Error> for Error {
- fn from(err: toml::de::Error) -> Self {
- Error::TomlDe(err)
- }
- }
-
- +#[cfg(not(feature = "antioxidant"))]
- impl From<toml::ser::Error> for Error {
- fn from(err: toml::ser::Error) -> Self {
- Error::TomlSer(err)
- diff -r -U3 trybuild-1.0.54/src/lib.rs trybuild-1.0.54-new/src/lib.rs
- --- trybuild-1.0.54/src/lib.rs 1973-11-29 22:33:09.000000000 +0100
- +++ trybuild-1.0.54-new/src/lib.rs 2022-09-08 17:25:00.383181533 +0200
- @@ -1,3 +1,5 @@
- +// Changed by Maxime Devos, 2022 (see: LICENSE-APACHE 4b)
- +
- //! [![github]](https://github.com/dtolnay/trybuild) [![crates-io]](https://crates.io/crates/trybuild) [![docs-rs]](https://docs.rs/trybuild)
- //!
- //! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
- @@ -228,21 +230,28 @@
- )]
- #![deny(clippy::clone_on_ref_ptr)]
-
- +#[cfg(not(feature = "antioxidant"))]
- #[macro_use]
- mod term;
-
- #[macro_use]
- mod path;
-
- +#[cfg(not(feature = "antioxidant"))]
- mod cargo;
- +#[cfg(not(feature = "antioxidant"))]
- mod dependencies;
- mod diff;
- mod directory;
- mod env;
- mod error;
- +#[cfg(not(feature = "antioxidant"))]
- mod features;
- +#[cfg(not(feature = "antioxidant"))]
- mod flock;
- +#[cfg(not(feature = "antioxidant"))]
- mod manifest;
- +#[cfg(not(feature = "antioxidant"))]
- mod message;
- mod normalize;
- mod run;
- @@ -284,6 +293,7 @@
- }
-
- pub fn pass<P: AsRef<Path>>(&self, path: P) {
- + #[cfg(not(feature = "antioxidant"))]
- self.runner.borrow_mut().tests.push(Test {
- path: path.as_ref().to_owned(),
- expected: Expected::Pass,
- @@ -291,6 +301,7 @@
- }
-
- pub fn compile_fail<P: AsRef<Path>>(&self, path: P) {
- + #[cfg(not(feature = "antioxidant"))]
- self.runner.borrow_mut().tests.push(Test {
- path: path.as_ref().to_owned(),
- expected: Expected::CompileFail,
- diff -r -U3 trybuild-1.0.54/src/run.rs trybuild-1.0.54-new/src/run.rs
- --- trybuild-1.0.54/src/run.rs 1973-11-29 22:33:09.000000000 +0100
- +++ trybuild-1.0.54-new/src/run.rs 2022-09-08 17:25:08.479183844 +0200
- @@ -1,13 +1,21 @@
- +// Changed by Maxime Devos, 2022 (see: LICENSE-APACHE 4b)
- +#[cfg(not(feature = "antioxidant"))]
- use crate::cargo::{self, Metadata};
- +#[cfg(not(feature = "antioxidant"))]
- use crate::dependencies::{self, Dependency};
- use crate::directory::Directory;
- use crate::env::Update;
- use crate::error::{Error, Result};
- +#[cfg(not(feature = "antioxidant"))]
- use crate::flock::Lock;
- +#[cfg(not(feature = "antioxidant"))]
- use crate::manifest::{Bin, Build, Config, Manifest, Name, Package, Workspace};
- +#[cfg(not(feature = "antioxidant"))]
- use crate::message::{self, Fail, Warn};
- use crate::normalize::{self, Context, Variations};
- -use crate::{features, rustflags, Expected, Runner, Test};
- +use crate::{rustflags, Expected, Runner, Test};
- +#[cfg(not(feature = "antioxidant"))]
- +use crate::features;
- use std::collections::BTreeMap as Map;
- use std::env;
- use std::ffi::{OsStr, OsString};
- @@ -27,6 +35,7 @@
- pub features: Option<Vec<String>>,
- pub workspace: Directory,
- pub path_dependencies: Vec<PathDependency>,
- + #[cfg(not(feature = "antioxidant"))]
- manifest: Manifest,
- }
-
- @@ -37,6 +46,10 @@
- }
-
- impl Runner {
- + #[cfg(feature = "antioxidant")]
- + pub fn run(&mut self) { }
- +
- + #[cfg(not(feature = "antioxidant"))]
- pub fn run(&mut self) {
- let mut tests = expand_globs(&self.tests);
- filter(&mut tests);
- @@ -75,6 +88,7 @@
- }
- }
-
- + #[cfg(not(feature = "antioxidant"))]
- fn prepare(&self, tests: &[ExpandedTest]) -> Result<Project> {
- let Metadata {
- target_directory: target_dir,
- @@ -149,6 +163,7 @@
- })
- }
-
- + #[cfg(not(feature = "antioxidant"))]
- fn write(&self, project: &Project) -> Result<()> {
- let manifest_toml = toml::to_string(&project.manifest)?;
-
- @@ -165,6 +180,7 @@
- Ok(())
- }
-
- + #[cfg(not(feature = "antioxidant"))]
- fn make_manifest(
- &self,
- crate_name: String,
- @@ -243,6 +259,7 @@
- manifest
- }
-
- + #[cfg(not(feature = "antioxidant"))]
- fn make_config(&self) -> Config {
- Config {
- build: Build {
- @@ -252,6 +269,7 @@
- }
- }
-
- +#[cfg(not(feature = "antioxidant"))]
- impl Test {
- fn run(&self, project: &Project, name: &Name) -> Result<()> {
- let show_expected = project.has_pass && project.has_compile_fail;
- @@ -380,6 +398,7 @@
- }
- }
-
- +#[cfg(not(feature = "antioxidant"))]
- #[derive(Debug)]
- struct ExpandedTest {
- name: Name,
- @@ -387,6 +406,7 @@
- error: Option<Error>,
- }
-
- +#[cfg(not(feature = "antioxidant"))]
- fn expand_globs(tests: &[Test]) -> Vec<ExpandedTest> {
- fn glob(pattern: &str) -> Result<Vec<PathBuf>> {
- let mut paths = glob::glob(pattern)?
- @@ -434,6 +454,7 @@
- vec
- }
-
- +#[cfg(not(feature = "antioxidant"))]
- impl ExpandedTest {
- fn run(self, project: &Project) -> Result<()> {
- match self.error {
- @@ -456,6 +477,7 @@
- // Cargo to run the test at all. The next argument starting with `trybuild=`
- // provides a filename filter. Only test cases whose filename contains the
- // filter string will be run.
- +#[cfg(not(feature = "antioxidant"))]
- #[allow(clippy::needless_collect)] // false positive https://github.com/rust-lang/rust-clippy/issues/5991
- fn filter(tests: &mut Vec<ExpandedTest>) {
- let filters = env::args_os()
|