rust-trybuild-antioxidant-stubs.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. rust-trybuild works by running "cargo". But antioxidant-build-system tries
  2. to replace cargo by antioxidant. For now, add an "antioxidant" feature
  3. that adds stubs. If (when?) later antioxidant is extracted in a tool
  4. with a binary that can be run by rust-trybuild, the stubs can be replaced
  5. by a ‘real’ implementation targeting antioxidant and then sent upstream.
  6. Additionally, to avoid cycles, remove some dependencies when building for
  7. antioxidant.
  8. diff -r -U3 trybuild-1.0.54/Cargo.toml trybuild-1.0.54-new/Cargo.toml
  9. --- trybuild-1.0.54/Cargo.toml 1970-01-01 01:00:01.000000000 +0100
  10. +++ trybuild-1.0.54-new/Cargo.toml 2022-09-08 17:26:17.395202204 +0200
  11. @@ -48,3 +48,4 @@
  12. [features]
  13. diff = ["dissimilar"]
  14. +antioxidant = []
  15. diff -r -U3 trybuild-1.0.54/Cargo.toml.orig trybuild-1.0.54-new/Cargo.toml.orig
  16. --- trybuild-1.0.54/Cargo.toml.orig 1973-11-29 22:33:09.000000000 +0100
  17. +++ trybuild-1.0.54-new/Cargo.toml.orig 2022-09-08 17:20:40.399089289 +0200
  18. @@ -1,3 +1,4 @@
  19. +# Changed by Maxime Devos, 2022 (see: LICENSE-APACHE 4b)
  20. [package]
  21. name = "trybuild"
  22. version = "1.0.54"
  23. @@ -16,6 +17,7 @@
  24. # output. Currently unix-only. If you test this out, please provide any feedback
  25. # in https://github.com/dtolnay/trybuild/issues/41.
  26. diff = ["dissimilar"]
  27. +antioxidant = []
  28. [dependencies]
  29. dissimilar = { version = "1.0", optional = true }
  30. diff -r -U3 trybuild-1.0.54/src/directory.rs trybuild-1.0.54-new/src/directory.rs
  31. --- trybuild-1.0.54/src/directory.rs 1973-11-29 22:33:09.000000000 +0100
  32. +++ trybuild-1.0.54-new/src/directory.rs 2022-09-08 17:25:19.703186994 +0200
  33. @@ -1,11 +1,14 @@
  34. +// Changed by Maxime Devos, 2022 (see: LICENSE-APACHE 4b)
  35. +#[cfg(not(feature = "antioxidant"))]
  36. use serde::{Deserialize, Deserializer, Serialize};
  37. use std::borrow::Cow;
  38. use std::ffi::OsString;
  39. use std::io;
  40. use std::path::{Path, PathBuf};
  41. -#[derive(Clone, Debug, Serialize)]
  42. -#[serde(transparent)]
  43. +#[derive(Clone, Debug)]
  44. +#[cfg_attr(not(feature = "antioxidant"), derive(Clone, Debug, Serialize))]
  45. +#[cfg_attr(not(feature = "antioxidant"), serde(transparent))]
  46. pub struct Directory {
  47. path: PathBuf,
  48. }
  49. @@ -42,6 +45,7 @@
  50. }
  51. }
  52. +#[cfg(not(feature = "antioxidant"))]
  53. impl<'de> Deserialize<'de> for Directory {
  54. fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
  55. where
  56. diff -r -U3 trybuild-1.0.54/src/error.rs trybuild-1.0.54-new/src/error.rs
  57. --- trybuild-1.0.54/src/error.rs 1973-11-29 22:33:09.000000000 +0100
  58. +++ trybuild-1.0.54-new/src/error.rs 2022-09-08 17:24:53.919179665 +0200
  59. @@ -1,3 +1,5 @@
  60. +// Changed by Maxime Devos, 2022 (see: LICENSE-APACHE 4b)
  61. +#[cfg(not(feature = "antioxidant"))]
  62. use glob::{GlobError, PatternError};
  63. use std::env;
  64. use std::ffi::OsString;
  65. @@ -9,18 +11,23 @@
  66. pub enum Error {
  67. Cargo(io::Error),
  68. CargoFail,
  69. + #[cfg(not(feature = "antioxidant"))]
  70. Glob(GlobError),
  71. Io(io::Error),
  72. + #[cfg(not(feature = "antioxidant"))]
  73. Metadata(serde_json::Error),
  74. Mismatch,
  75. Open(PathBuf, io::Error),
  76. + #[cfg(not(feature = "antioxidant"))]
  77. Pattern(PatternError),
  78. PkgName(env::VarError),
  79. ProjectDir,
  80. ReadStderr(io::Error),
  81. RunFailed,
  82. ShouldNotHaveCompiled,
  83. + #[cfg(not(feature = "antioxidant"))]
  84. TomlDe(toml::de::Error),
  85. + #[cfg(not(feature = "antioxidant"))]
  86. TomlSer(toml::ser::Error),
  87. UpdateVar(OsString),
  88. WriteStderr(io::Error),
  89. @@ -35,11 +42,14 @@
  90. match self {
  91. Cargo(e) => write!(f, "failed to execute cargo: {}", e),
  92. CargoFail => write!(f, "cargo reported an error"),
  93. + #[cfg(not(feature = "antioxidant"))]
  94. Glob(e) => write!(f, "{}", e),
  95. Io(e) => write!(f, "{}", e),
  96. + #[cfg(not(feature = "antioxidant"))]
  97. Metadata(e) => write!(f, "failed to read cargo metadata: {}", e),
  98. Mismatch => write!(f, "compiler error does not match expected error"),
  99. Open(path, e) => write!(f, "{}: {}", path.display(), e),
  100. + #[cfg(not(feature = "antioxidant"))]
  101. Pattern(e) => write!(f, "{}", e),
  102. PkgName(e) => write!(f, "failed to detect CARGO_PKG_NAME: {}", e),
  103. ProjectDir => write!(f, "failed to determine name of project dir"),
  104. @@ -48,7 +58,9 @@
  105. ShouldNotHaveCompiled => {
  106. write!(f, "expected test case to fail to compile, but it succeeded")
  107. }
  108. + #[cfg(not(feature = "antioxidant"))]
  109. TomlDe(e) => write!(f, "{}", e),
  110. + #[cfg(not(feature = "antioxidant"))]
  111. TomlSer(e) => write!(f, "{}", e),
  112. UpdateVar(var) => write!(
  113. f,
  114. @@ -71,12 +83,14 @@
  115. }
  116. }
  117. +#[cfg(not(feature = "antioxidant"))]
  118. impl From<GlobError> for Error {
  119. fn from(err: GlobError) -> Self {
  120. Error::Glob(err)
  121. }
  122. }
  123. +#[cfg(not(feature = "antioxidant"))]
  124. impl From<PatternError> for Error {
  125. fn from(err: PatternError) -> Self {
  126. Error::Pattern(err)
  127. @@ -89,12 +103,14 @@
  128. }
  129. }
  130. +#[cfg(not(feature = "antioxidant"))]
  131. impl From<toml::de::Error> for Error {
  132. fn from(err: toml::de::Error) -> Self {
  133. Error::TomlDe(err)
  134. }
  135. }
  136. +#[cfg(not(feature = "antioxidant"))]
  137. impl From<toml::ser::Error> for Error {
  138. fn from(err: toml::ser::Error) -> Self {
  139. Error::TomlSer(err)
  140. diff -r -U3 trybuild-1.0.54/src/lib.rs trybuild-1.0.54-new/src/lib.rs
  141. --- trybuild-1.0.54/src/lib.rs 1973-11-29 22:33:09.000000000 +0100
  142. +++ trybuild-1.0.54-new/src/lib.rs 2022-09-08 17:25:00.383181533 +0200
  143. @@ -1,3 +1,5 @@
  144. +// Changed by Maxime Devos, 2022 (see: LICENSE-APACHE 4b)
  145. +
  146. //! [![github]](https://github.com/dtolnay/trybuild)&ensp;[![crates-io]](https://crates.io/crates/trybuild)&ensp;[![docs-rs]](https://docs.rs/trybuild)
  147. //!
  148. //! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
  149. @@ -228,21 +230,28 @@
  150. )]
  151. #![deny(clippy::clone_on_ref_ptr)]
  152. +#[cfg(not(feature = "antioxidant"))]
  153. #[macro_use]
  154. mod term;
  155. #[macro_use]
  156. mod path;
  157. +#[cfg(not(feature = "antioxidant"))]
  158. mod cargo;
  159. +#[cfg(not(feature = "antioxidant"))]
  160. mod dependencies;
  161. mod diff;
  162. mod directory;
  163. mod env;
  164. mod error;
  165. +#[cfg(not(feature = "antioxidant"))]
  166. mod features;
  167. +#[cfg(not(feature = "antioxidant"))]
  168. mod flock;
  169. +#[cfg(not(feature = "antioxidant"))]
  170. mod manifest;
  171. +#[cfg(not(feature = "antioxidant"))]
  172. mod message;
  173. mod normalize;
  174. mod run;
  175. @@ -284,6 +293,7 @@
  176. }
  177. pub fn pass<P: AsRef<Path>>(&self, path: P) {
  178. + #[cfg(not(feature = "antioxidant"))]
  179. self.runner.borrow_mut().tests.push(Test {
  180. path: path.as_ref().to_owned(),
  181. expected: Expected::Pass,
  182. @@ -291,6 +301,7 @@
  183. }
  184. pub fn compile_fail<P: AsRef<Path>>(&self, path: P) {
  185. + #[cfg(not(feature = "antioxidant"))]
  186. self.runner.borrow_mut().tests.push(Test {
  187. path: path.as_ref().to_owned(),
  188. expected: Expected::CompileFail,
  189. diff -r -U3 trybuild-1.0.54/src/run.rs trybuild-1.0.54-new/src/run.rs
  190. --- trybuild-1.0.54/src/run.rs 1973-11-29 22:33:09.000000000 +0100
  191. +++ trybuild-1.0.54-new/src/run.rs 2022-09-08 17:25:08.479183844 +0200
  192. @@ -1,13 +1,21 @@
  193. +// Changed by Maxime Devos, 2022 (see: LICENSE-APACHE 4b)
  194. +#[cfg(not(feature = "antioxidant"))]
  195. use crate::cargo::{self, Metadata};
  196. +#[cfg(not(feature = "antioxidant"))]
  197. use crate::dependencies::{self, Dependency};
  198. use crate::directory::Directory;
  199. use crate::env::Update;
  200. use crate::error::{Error, Result};
  201. +#[cfg(not(feature = "antioxidant"))]
  202. use crate::flock::Lock;
  203. +#[cfg(not(feature = "antioxidant"))]
  204. use crate::manifest::{Bin, Build, Config, Manifest, Name, Package, Workspace};
  205. +#[cfg(not(feature = "antioxidant"))]
  206. use crate::message::{self, Fail, Warn};
  207. use crate::normalize::{self, Context, Variations};
  208. -use crate::{features, rustflags, Expected, Runner, Test};
  209. +use crate::{rustflags, Expected, Runner, Test};
  210. +#[cfg(not(feature = "antioxidant"))]
  211. +use crate::features;
  212. use std::collections::BTreeMap as Map;
  213. use std::env;
  214. use std::ffi::{OsStr, OsString};
  215. @@ -27,6 +35,7 @@
  216. pub features: Option<Vec<String>>,
  217. pub workspace: Directory,
  218. pub path_dependencies: Vec<PathDependency>,
  219. + #[cfg(not(feature = "antioxidant"))]
  220. manifest: Manifest,
  221. }
  222. @@ -37,6 +46,10 @@
  223. }
  224. impl Runner {
  225. + #[cfg(feature = "antioxidant")]
  226. + pub fn run(&mut self) { }
  227. +
  228. + #[cfg(not(feature = "antioxidant"))]
  229. pub fn run(&mut self) {
  230. let mut tests = expand_globs(&self.tests);
  231. filter(&mut tests);
  232. @@ -75,6 +88,7 @@
  233. }
  234. }
  235. + #[cfg(not(feature = "antioxidant"))]
  236. fn prepare(&self, tests: &[ExpandedTest]) -> Result<Project> {
  237. let Metadata {
  238. target_directory: target_dir,
  239. @@ -149,6 +163,7 @@
  240. })
  241. }
  242. + #[cfg(not(feature = "antioxidant"))]
  243. fn write(&self, project: &Project) -> Result<()> {
  244. let manifest_toml = toml::to_string(&project.manifest)?;
  245. @@ -165,6 +180,7 @@
  246. Ok(())
  247. }
  248. + #[cfg(not(feature = "antioxidant"))]
  249. fn make_manifest(
  250. &self,
  251. crate_name: String,
  252. @@ -243,6 +259,7 @@
  253. manifest
  254. }
  255. + #[cfg(not(feature = "antioxidant"))]
  256. fn make_config(&self) -> Config {
  257. Config {
  258. build: Build {
  259. @@ -252,6 +269,7 @@
  260. }
  261. }
  262. +#[cfg(not(feature = "antioxidant"))]
  263. impl Test {
  264. fn run(&self, project: &Project, name: &Name) -> Result<()> {
  265. let show_expected = project.has_pass && project.has_compile_fail;
  266. @@ -380,6 +398,7 @@
  267. }
  268. }
  269. +#[cfg(not(feature = "antioxidant"))]
  270. #[derive(Debug)]
  271. struct ExpandedTest {
  272. name: Name,
  273. @@ -387,6 +406,7 @@
  274. error: Option<Error>,
  275. }
  276. +#[cfg(not(feature = "antioxidant"))]
  277. fn expand_globs(tests: &[Test]) -> Vec<ExpandedTest> {
  278. fn glob(pattern: &str) -> Result<Vec<PathBuf>> {
  279. let mut paths = glob::glob(pattern)?
  280. @@ -434,6 +454,7 @@
  281. vec
  282. }
  283. +#[cfg(not(feature = "antioxidant"))]
  284. impl ExpandedTest {
  285. fn run(self, project: &Project) -> Result<()> {
  286. match self.error {
  287. @@ -456,6 +477,7 @@
  288. // Cargo to run the test at all. The next argument starting with `trybuild=`
  289. // provides a filename filter. Only test cases whose filename contains the
  290. // filter string will be run.
  291. +#[cfg(not(feature = "antioxidant"))]
  292. #[allow(clippy::needless_collect)] // false positive https://github.com/rust-lang/rust-clippy/issues/5991
  293. fn filter(tests: &mut Vec<ExpandedTest>) {
  294. let filters = env::args_os()