|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +use cargo::CargoResult; |
| 19 | +use std::env; |
| 20 | +use std::path::Path; |
| 21 | + |
| 22 | +use cargo::util::context::GlobalContext; |
| 23 | + |
| 24 | +/// Verifies that we are tracking the right MSRV from datafusion. |
| 25 | +/// This is vastly inspired from <https://github.com/apache/datafusion/tree/10a437b826568c27b81d7d16a02b938a13d1a4ad/dev/depcheck> |
| 26 | +fn main() -> CargoResult<()> { |
| 27 | + let gctx = GlobalContext::default()?; |
| 28 | + // This is the path for the depcheck binary |
| 29 | + let path = env::var("CARGO_MANIFEST_DIR").unwrap(); |
| 30 | + let root_cargo_toml = Path::new(&path) |
| 31 | + // dev directory |
| 32 | + .parent() |
| 33 | + .expect("Can not find dev directory") |
| 34 | + // project root directory |
| 35 | + .parent() |
| 36 | + .expect("Can not find project root directory") |
| 37 | + .join("Cargo.toml"); |
| 38 | + |
| 39 | + println!( |
| 40 | + "Checking for MSRV dependencies in {}", |
| 41 | + root_cargo_toml.display() |
| 42 | + ); |
| 43 | + |
| 44 | + let workspace = cargo::core::Workspace::new(&root_cargo_toml, &gctx)?; |
| 45 | + let project_msrv = workspace.lowest_rust_version().unwrap(); // there should be a MSRV project wise |
| 46 | + |
| 47 | + let (_, resolve) = cargo::ops::resolve_ws(&workspace, false)?; |
| 48 | + let packages_with_rust_version: Vec<_> = resolve |
| 49 | + .iter() |
| 50 | + .filter(|id| id.name().starts_with("datafusion")) |
| 51 | + .map(|e| resolve.summary(e)) |
| 52 | + .map(|e| (e.name(), e.rust_version())) |
| 53 | + .collect(); |
| 54 | + |
| 55 | + println!("Current project MSRV: {}", project_msrv); |
| 56 | + |
| 57 | + for (package, version) in packages_with_rust_version { |
| 58 | + if let Some(v) = version { |
| 59 | + if !v.is_compatible_with(project_msrv.as_partial()) { |
| 60 | + panic!( |
| 61 | + "package {package} has {v} MSRV not compatible with current project MSRV {project_msrv}", |
| 62 | + ); |
| 63 | + } |
| 64 | + |
| 65 | + println!("{package} MSRV: {v}"); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + println!("No inconsistent MSRV found"); |
| 70 | + Ok(()) |
| 71 | +} |
0 commit comments