mirror of
https://github.com/trailbaseio/trailbase.git
synced 2026-02-14 21:49:14 -06:00
Remove vendored rustc_tools_util.
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -4,6 +4,3 @@
|
||||
[submodule "vendor/sqlean/bundled/sqlean"]
|
||||
path = vendor/sqlean/bundled/sqlean
|
||||
url = https://github.com/trailbaseio/sqlean
|
||||
[submodule "vendor/serde_rusqlite"]
|
||||
path = vendor/serde_rusqlite
|
||||
url = https://github.com/trailbaseio/serde_rusqlite.git
|
||||
|
||||
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -4946,7 +4946,9 @@ checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
|
||||
|
||||
[[package]]
|
||||
name = "rustc_tools_util"
|
||||
version = "0.4.0"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a3b75158011a63889ba12084cf1224baad7bcad50f6ee7c842f772b74aa148ed"
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
|
||||
@@ -54,7 +54,6 @@ rusqlite = { version = "^0.33.0", default-features = false, features = [
|
||||
"hooks",
|
||||
"preupdate_hook",
|
||||
] }
|
||||
rustc_tools_util = { path = "vendor/rustc_tools_util", version = "0.4.0" }
|
||||
trailbase-sqlean = { path = "vendor/sqlean", version = "0.0.2" }
|
||||
trailbase-extension = { path = "trailbase-extension", version = "0.1.1" }
|
||||
trailbase-sqlite = { path = "trailbase-sqlite", version = "0.1.1" }
|
||||
|
||||
@@ -59,7 +59,7 @@ regex = "1.11.0"
|
||||
reqwest = { version = "0.12.8", default-features = false, features = ["rustls-tls", "json"] }
|
||||
rusqlite = { workspace = true }
|
||||
rust-embed = { version = "8.4.0", default-features = false, features = ["mime-guess"] }
|
||||
rustc_tools_util = { workspace = true }
|
||||
rustc_tools_util = "^0.4.2"
|
||||
rustyscript = { version = "^0.11.0", optional = true, features = ["web", "fs"] }
|
||||
serde = { version = "^1.0.203", features = ["derive"] }
|
||||
serde_json = "^1.0.117"
|
||||
@@ -91,7 +91,7 @@ env_logger = "^0.11.3"
|
||||
log = "^0.4.21"
|
||||
prost-build = "0.13.1"
|
||||
prost-reflect-build = "0.14.0"
|
||||
rustc_tools_util = { workspace = true }
|
||||
rustc_tools_util = "^0.4.2"
|
||||
|
||||
[dev-dependencies]
|
||||
anyhow = "^1.0.86"
|
||||
|
||||
1
vendor/rustc_tools_util/.gitignore
vendored
1
vendor/rustc_tools_util/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
Cargo.lock
|
||||
15
vendor/rustc_tools_util/CHANGELOG.md
vendored
15
vendor/rustc_tools_util/CHANGELOG.md
vendored
@@ -1,15 +0,0 @@
|
||||
# Changelog
|
||||
|
||||
## Version 0.4.0
|
||||
|
||||
* The commit hashes are now always 10 characters long [#13222](https://github.com/rust-lang/rust-clippy/pull/13222)
|
||||
* `get_commit_date` and `get_commit_hash` now return `None` if the `git` command fails instead of `Some("")`
|
||||
[#13217](https://github.com/rust-lang/rust-clippy/pull/13217)
|
||||
* `setup_version_info` will now re-run when the git commit changes
|
||||
[#13329](https://github.com/rust-lang/rust-clippy/pull/13329)
|
||||
* New `rerun_if_git_changes` function was added [#13329](https://github.com/rust-lang/rust-clippy/pull/13329)
|
||||
|
||||
## Version 0.3.0
|
||||
|
||||
* Added `setup_version_info!();` macro for automated scripts.
|
||||
* `get_version_info!()` no longer requires the user to import `rustc_tools_util::VersionInfo` and `std::env`
|
||||
12
vendor/rustc_tools_util/Cargo.toml
vendored
12
vendor/rustc_tools_util/Cargo.toml
vendored
@@ -1,12 +0,0 @@
|
||||
[package]
|
||||
name = "rustc_tools_util"
|
||||
version = "0.4.0"
|
||||
description = "small helper to generate version information for git packages"
|
||||
repository = "https://github.com/rust-lang/rust-clippy"
|
||||
readme = "README.md"
|
||||
license = "MIT OR Apache-2.0"
|
||||
keywords = ["rustc", "tool", "git", "version", "hash"]
|
||||
categories = ["development-tools"]
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
201
vendor/rustc_tools_util/LICENSE-APACHE
vendored
201
vendor/rustc_tools_util/LICENSE-APACHE
vendored
@@ -1,201 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2014-2024 The Rust Project Developers
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
27
vendor/rustc_tools_util/LICENSE-MIT
vendored
27
vendor/rustc_tools_util/LICENSE-MIT
vendored
@@ -1,27 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2014-2024 The Rust Project Developers
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
62
vendor/rustc_tools_util/README.md
vendored
62
vendor/rustc_tools_util/README.md
vendored
@@ -1,62 +0,0 @@
|
||||
# rustc_tools_util
|
||||
|
||||
A small tool to help you generate version information
|
||||
for packages installed from a git repo
|
||||
|
||||
## Usage
|
||||
|
||||
Add a `build.rs` file to your repo and list it in `Cargo.toml`
|
||||
````toml
|
||||
build = "build.rs"
|
||||
````
|
||||
|
||||
List rustc_tools_util as regular AND build dependency.
|
||||
````toml
|
||||
[dependencies]
|
||||
rustc_tools_util = "0.4.0"
|
||||
|
||||
[build-dependencies]
|
||||
rustc_tools_util = "0.4.0"
|
||||
````
|
||||
|
||||
In `build.rs`, generate the data in your `main()`
|
||||
|
||||
```rust
|
||||
fn main() {
|
||||
rustc_tools_util::setup_version_info!();
|
||||
}
|
||||
```
|
||||
|
||||
Use the version information in your main.rs
|
||||
|
||||
```rust
|
||||
fn show_version() {
|
||||
let version_info = rustc_tools_util::get_version_info!();
|
||||
println!("{}", version_info);
|
||||
}
|
||||
```
|
||||
|
||||
This gives the following output in clippy:
|
||||
`clippy 0.1.66 (a28f3c8 2022-11-20)`
|
||||
|
||||
## Repository
|
||||
|
||||
This project is part of the rust-lang/rust-clippy repository. The source code
|
||||
can be found under `./rustc_tools_util/`.
|
||||
|
||||
The changelog for `rustc_tools_util` is available under:
|
||||
[`rustc_tools_util/CHANGELOG.md`](https://github.com/rust-lang/rust-clippy/blob/master/rustc_tools_util/CHANGELOG.md)
|
||||
|
||||
## License
|
||||
|
||||
<!-- REUSE-IgnoreStart -->
|
||||
|
||||
Copyright 2014-2024 The Rust Project Developers
|
||||
|
||||
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
<LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
option. All files in the project carrying such notice may not be
|
||||
copied, modified, or distributed except according to those terms.
|
||||
|
||||
<!-- REUSE-IgnoreEnd -->
|
||||
226
vendor/rustc_tools_util/src/lib.rs
vendored
226
vendor/rustc_tools_util/src/lib.rs
vendored
@@ -1,226 +0,0 @@
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use std::str;
|
||||
|
||||
/// This macro creates the version string during compilation from the
|
||||
/// current environment
|
||||
#[macro_export]
|
||||
macro_rules! get_version_info {
|
||||
() => {{
|
||||
let major = std::env!("CARGO_PKG_VERSION_MAJOR").parse::<u8>().unwrap();
|
||||
let minor = std::env!("CARGO_PKG_VERSION_MINOR").parse::<u8>().unwrap();
|
||||
let patch = std::env!("CARGO_PKG_VERSION_PATCH").parse::<u16>().unwrap();
|
||||
let crate_name = String::from(std::env!("CARGO_PKG_NAME"));
|
||||
|
||||
let host_compiler_version = std::option_env!("RUSTC_VERSION").map(str::to_string);
|
||||
let host_compiler = std::option_env!("RUSTC_RELEASE_CHANNEL").map(str::to_string);
|
||||
let commit_hash = std::option_env!("GIT_HASH").map(str::to_string);
|
||||
let commit_date = std::option_env!("COMMIT_DATE").map(str::to_string);
|
||||
|
||||
$crate::VersionInfo {
|
||||
major,
|
||||
minor,
|
||||
patch,
|
||||
host_compiler_version,
|
||||
host_compiler,
|
||||
commit_hash,
|
||||
commit_date,
|
||||
crate_name,
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
/// This macro can be used in `build.rs` to automatically set the needed
|
||||
/// environment values, namely `GIT_HASH`, `COMMIT_DATE`, `RUSTC_VERSION` and
|
||||
/// `RUSTC_RELEASE_CHANNEL`
|
||||
#[macro_export]
|
||||
macro_rules! setup_version_info {
|
||||
() => {{
|
||||
let _ = $crate::rerun_if_git_changes();
|
||||
println!(
|
||||
"cargo:rustc-env=GIT_HASH={}",
|
||||
$crate::get_commit_hash().unwrap_or_default()
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-env=COMMIT_DATE={}",
|
||||
$crate::get_commit_date().unwrap_or_default()
|
||||
);
|
||||
let compiler_version = $crate::get_compiler_version();
|
||||
println!(
|
||||
"cargo:rustc-env=RUSTC_VERSION={}",
|
||||
compiler_version.as_deref().unwrap_or_default()
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-env=RUSTC_RELEASE_CHANNEL={}",
|
||||
$crate::get_channel(compiler_version)
|
||||
);
|
||||
}};
|
||||
}
|
||||
|
||||
// some code taken and adapted from RLS and cargo
|
||||
pub struct VersionInfo {
|
||||
pub major: u8,
|
||||
pub minor: u8,
|
||||
pub patch: u16,
|
||||
pub host_compiler_version: Option<String>,
|
||||
pub host_compiler: Option<String>,
|
||||
pub commit_hash: Option<String>,
|
||||
pub commit_date: Option<String>,
|
||||
pub crate_name: String,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for VersionInfo {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let hash = self.commit_hash.clone().unwrap_or_default();
|
||||
let hash_trimmed = hash.trim();
|
||||
|
||||
let date = self.commit_date.clone().unwrap_or_default();
|
||||
let date_trimmed = date.trim();
|
||||
|
||||
if (hash_trimmed.len() + date_trimmed.len()) > 0 {
|
||||
write!(
|
||||
f,
|
||||
"{} {}.{}.{} ({hash_trimmed} {date_trimmed})",
|
||||
self.crate_name, self.major, self.minor, self.patch,
|
||||
)?;
|
||||
} else {
|
||||
write!(f, "{} {}.{}.{}", self.crate_name, self.major, self.minor, self.patch)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for VersionInfo {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"VersionInfo {{ crate_name: \"{}\", major: {}, minor: {}, patch: {}",
|
||||
self.crate_name, self.major, self.minor, self.patch,
|
||||
)?;
|
||||
if let Some(ref commit_hash) = self.commit_hash {
|
||||
write!(f, ", commit_hash: \"{}\"", commit_hash.trim(),)?;
|
||||
}
|
||||
if let Some(ref commit_date) = self.commit_date {
|
||||
write!(f, ", commit_date: \"{}\"", commit_date.trim())?;
|
||||
}
|
||||
if let Some(ref version) = self.host_compiler_version {
|
||||
write!(f, ", host_compiler_version: \"{}\"", version.trim())?;
|
||||
}
|
||||
if let Some(ref host_compiler) = self.host_compiler {
|
||||
write!(f, ", host_compiler: \"{}\"", host_compiler.trim())?;
|
||||
}
|
||||
|
||||
write!(f, " }}")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
fn get_output(cmd: &str, args: &[&str]) -> Option<String> {
|
||||
let output = Command::new(cmd).args(args).output().ok()?;
|
||||
let mut stdout = output.status.success().then_some(output.stdout)?;
|
||||
// Remove trailing newlines.
|
||||
while stdout.last().copied() == Some(b'\n') {
|
||||
stdout.pop();
|
||||
}
|
||||
String::from_utf8(stdout).ok()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn rerun_if_git_changes() -> Option<()> {
|
||||
// Make sure we get rerun when the git commit changes.
|
||||
// We want to watch two files: HEAD, which tracks which branch we are on,
|
||||
// and the file for that branch that tracks which commit is is on.
|
||||
|
||||
// First, find the `HEAD` file. This should work even with worktrees.
|
||||
let git_head_file = PathBuf::from(get_output("git", &["rev-parse", "--git-path", "HEAD"])?);
|
||||
if git_head_file.exists() {
|
||||
println!("cargo::rerun-if-changed={}", git_head_file.display());
|
||||
}
|
||||
|
||||
// Determine the name of the current ref.
|
||||
// This will quit if HEAD is detached.
|
||||
let git_head_ref = get_output("git", &["symbolic-ref", "-q", "HEAD"])?;
|
||||
// Ask git where this ref is stored.
|
||||
let git_head_ref_file = PathBuf::from(get_output("git", &["rev-parse", "--git-path", &git_head_ref])?);
|
||||
// If this ref is packed, the file does not exist. However, the checked-out branch is never (?)
|
||||
// packed, so we should always be able to find this file.
|
||||
if git_head_ref_file.exists() {
|
||||
println!("cargo::rerun-if-changed={}", git_head_ref_file.display());
|
||||
}
|
||||
|
||||
Some(())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_commit_hash() -> Option<String> {
|
||||
let mut stdout = get_output("git", &["rev-parse", "HEAD"])?;
|
||||
stdout.truncate(10);
|
||||
Some(stdout)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_commit_date() -> Option<String> {
|
||||
get_output("git", &["log", "-1", "--date=short", "--pretty=format:%cd"])
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_compiler_version() -> Option<String> {
|
||||
get_output("rustc", &["-V"])
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_channel(compiler_version: Option<String>) -> String {
|
||||
if let Ok(channel) = std::env::var("CFG_RELEASE_CHANNEL") {
|
||||
return channel;
|
||||
}
|
||||
|
||||
// if that failed, try to ask rustc -V, do some parsing and find out
|
||||
if let Some(rustc_output) = compiler_version {
|
||||
if rustc_output.contains("beta") {
|
||||
return String::from("beta");
|
||||
} else if rustc_output.contains("nightly") {
|
||||
return String::from("nightly");
|
||||
}
|
||||
}
|
||||
|
||||
// default to stable
|
||||
String::from("stable")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_struct_local() {
|
||||
let vi = get_version_info!();
|
||||
assert_eq!(vi.major, 0);
|
||||
assert_eq!(vi.minor, 4);
|
||||
assert_eq!(vi.patch, 0);
|
||||
assert_eq!(vi.crate_name, "rustc_tools_util");
|
||||
// hard to make positive tests for these since they will always change
|
||||
assert!(vi.commit_hash.is_none());
|
||||
assert!(vi.commit_date.is_none());
|
||||
|
||||
assert!(vi.host_compiler.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_display_local() {
|
||||
let vi = get_version_info!();
|
||||
assert_eq!(vi.to_string(), "rustc_tools_util 0.4.0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_debug_local() {
|
||||
let vi = get_version_info!();
|
||||
let s = format!("{vi:?}");
|
||||
assert_eq!(
|
||||
s,
|
||||
"VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 4, patch: 0 }"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user