vergen-3.0.4/.gitignore010064423462670000024000000000341333313322500132220ustar0000000000000000target Cargo.lock .ssh *.bk vergen-3.0.4/.gitlab-ci.yml010064423462670000024000000012171335672565200137120ustar0000000000000000stages: - nightly # - stable - build variables: CARGO_HOME: $CI_PROJECT_DIR/cargo APT_CACHE_DIR: $CI_PROJECT_DIR/apt before_script: - apt-get update -yq # - apt-get install -o dir::cache::archives="$APT_CACHE_DIR" -y {{ DEPENDENCIES }} nightly: image: 'rustlang/rust:nightly' stage: nightly script: - rustc --version - cargo --version - cargo test --verbose # TODO: Uncomment this when editions hit stable # stable: # image: 'rust:latest' # stage: stable # script: # - rustc --version # - cargo --version # - cargo test --verbose --features serde cache: paths: - apt/ - cargo/ - target/vergen-3.0.4/.travis.yml010064423462670000024000000030611335672565200133660ustar0000000000000000language: rust rust: - stable - beta - nightly os: - linux matrix: allow_failures: - rust: stable addons: apt: packages: - libcurl4-openssl-dev - libelf-dev - libdw-dev - cmake - gcc - binutils-dev - libiberty-dev script: "./scripts/run-tests.sh" after_success: | wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz && tar xzf master.tar.gz && cd kcov-master && mkdir build && cd build && cmake .. && make && make install DESTDIR=../../kcov-build && cd ../.. && rm -rf kcov-master && for file in target/debug/vergen-*[^\.d]; do mkdir -p "target/cov/$(basename $file)"; ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; done && bash <(curl -s https://codecov.io/bash) && echo "Uploaded code coverage" notifications: slack: secure: YvvzRPEQN2VzjYR+7MpqH+cZ23vqzMV0U3Py59O5LbaVNWtmveWXWlthmy8CFUhv0MboWY3CjdiMhCEFAsW0xB4kBlldK0FekJNurVpfmsjqfNW7ekTwQzDOQT+XLpjE4Q/zDQmjzUhZ8JYjsKUgsxTZ9xeOHKjp2Ae472pbEAwzPYjIwNACD7EpJBapuTU/sfgSa+gR3BDeKwQMytyjXNEFyob+9ijWjLYjTH5fIvcvOyYFU1D6g6fhn+LBP0IGfCdDEhx3w1dzCCs4xRmfYzE3UU3+pd3oJEE0HNFiixh0x1b3TqTbE11p1JIaJk0ylZPcVA2idp+1xeSgtPnM4bSXxcvwa8XuEt+v3AkiIY+GygTG93KHwYuqPTRF0PkUaJIj0R4rRfAm3oxTdiNW/ru7a1YDRimMjKONnf0HoxzFgYbskJOwrfMSsSbv8QB1wD302Ca4hoKHzp0IFxld9VtoQAkTtx1yGHq2t5DGUDsQGHDkygtY2jJklYK8lGSXKN9/6jrQUHo2ArdiyhcFZXLWM6SyTMvtdNd9CKv0sXg2sGOT5UgJK7NSW97Q1pDmtHAfoCK+Q9zHbbg4VhbezrXVMR9nE7VzlNUnj8927zyQWKJVyMqIaLuQGs5VMbmfYtD0bzL7/yrKEEwmjIYydjk/opkiQ27rTnko5WbwqrY= vergen-3.0.4/appveyor.yml010064423462670000024000000113151335672565200136460ustar0000000000000000# Appveyor configuration template for Rust using rustup for Rust installation # https://github.com/starkat99/appveyor-rust ## Operating System (VM environment) ## # Rust needs at least Visual Studio 2013 Appveyor OS for MSVC targets. os: Visual Studio 2015 ## Build Matrix ## # This configuration will setup a build for each channel & target combination (12 windows # combinations in all). # # There are 3 channels: stable, beta, and nightly. # # Alternatively, the full version may be specified for the channel to build using that specific # version (e.g. channel: 1.5.0) # # The values for target are the set of windows Rust build targets. Each value is of the form # # ARCH-pc-windows-TOOLCHAIN # # Where ARCH is the target architecture, either x86_64 or i686, and TOOLCHAIN is the linker # toolchain to use, either msvc or gnu. See https://www.rust-lang.org/downloads.html#win-foot for # a description of the toolchain differences. # See https://github.com/rust-lang-nursery/rustup.rs/#toolchain-specification for description of # toolchains and host triples. # # Comment out channel/target combos you do not wish to build in CI. # # You may use the `cargoflags` and `RUSTFLAGS` variables to set additional flags for cargo commands # and rustc, respectively. For instance, you can uncomment the cargoflags lines in the nightly # channels to enable unstable features when building for nightly. Or you could add additional # matrix entries to test different combinations of features. environment: matrix: ### MSVC Toolchains ### # Stable 64-bit MSVC - channel: stable target: x86_64-pc-windows-msvc # cargoflags: --features "serde" # Stable 32-bit MSVC - channel: stable target: i686-pc-windows-msvc # cargoflags: --features "serde" # Beta 64-bit MSVC - channel: beta target: x86_64-pc-windows-msvc # cargoflags: --features "serde" # Beta 32-bit MSVC - channel: beta target: i686-pc-windows-msvc # cargoflags: --features "serde" # Nightly 64-bit MSVC - channel: nightly target: x86_64-pc-windows-msvc # cargoflags: --features "serde, unstable" # Nightly 32-bit MSVC - channel: nightly target: i686-pc-windows-msvc # cargoflags: --features "serde, unstable" ### GNU Toolchains ### # Stable 64-bit GNU - channel: stable target: x86_64-pc-windows-gnu # cargoflags: --features "serde" # Stable 32-bit GNU - channel: stable target: i686-pc-windows-gnu # cargoflags: --features "serde" # Beta 64-bit GNU - channel: beta target: x86_64-pc-windows-gnu # cargoflags: --features "serde" # Beta 32-bit GNU - channel: beta target: i686-pc-windows-gnu # cargoflags: --features "serde" # Nightly 64-bit GNU - channel: nightly target: x86_64-pc-windows-gnu # cargoflags: --features "serde, unstable" # Nightly 32-bit GNU - channel: nightly target: i686-pc-windows-gnu # cargoflags: --features "serde, unstable" ### Allowed failures ### # See Appveyor documentation for specific details. In short, place any channel or targets you wish # to allow build failures on (usually nightly at least is a wise choice). This will prevent a build # or test failure in the matching channels/targets from failing the entire build. # TODO: Remove this allowed failure when editions become stable. matrix: allow_failures: - channel: stable # If you only care about stable channel build failures, uncomment the following line: #- channel: beta ## Install Script ## # This is the most important part of the Appveyor configuration. This installs the version of Rust # specified by the 'channel' and 'target' environment variables from the build matrix. This uses # rustup to install Rust. # # For simple configurations, instead of using the build matrix, you can simply set the # default-toolchain and default-host manually here. install: - appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe - rustup-init -yv --default-toolchain %channel% --default-host %target% - set PATH=%PATH%;%USERPROFILE%\.cargo\bin - rustc -vV - cargo -vV ## Build Script ## # 'cargo test' takes care of building for us, so disable Appveyor's build stage. This prevents # the "directory does not contain a project or solution file" error. build: false # Uses 'cargo test' to run tests and build. Alternatively, the project may call compiled programs #directly or perform other testing commands. Rust will automatically be placed in the PATH # environment variable. test_script: - cargo test --verbose %cargoflags% notifications: - provider: Slack incoming_webhook: secure: zFh5haEvvSEoe3St75VQXEuBZh57gMYCV1iDVfDhSlKt9OqqM5HtClc2Sgrhg38QlQfmuDHE8eVATzlmRvlwVV1OShwH7TRssEieTs4L2Cs=vergen-3.0.4/build.rs010064423462670000024000000002551335473450600127200ustar0000000000000000extern crate chrono; pub fn main() { let now = chrono::Utc::now(); println!( "cargo:rustc-env=VERGEN_BUILD_TIMESTAMP={}", now.to_rfc3339() ); } vergen-3.0.4/Cargo.toml.orig010064423462670000024000000010251336135357500141370ustar0000000000000000[package] authors = ["Jason Ozias "] description = "Generate version related functions" documentation = "http://docs.rs/vergen" edition = "2018" homepage = "http://github.com/rustyhorde/vergen" keywords = ["version", "generation"] license = "MIT/Apache-2.0" name = "vergen" readme = "README.md" repository = "https://github.com/rustyhorde/vergen" version = "3.0.4" [dependencies] bitflags = "1" chrono = "0" failure = "0" [dev-dependencies] lazy_static = "1" regex = "1" [build-dependencies] chrono = "0" vergen-3.0.4/Cargo.toml0000644000000022020000000000000103570ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g. crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2018" name = "vergen" version = "3.0.4" authors = ["Jason Ozias "] description = "Generate version related functions" homepage = "http://github.com/rustyhorde/vergen" documentation = "http://docs.rs/vergen" readme = "README.md" keywords = ["version", "generation"] license = "MIT/Apache-2.0" repository = "https://github.com/rustyhorde/vergen" [dependencies.bitflags] version = "1" [dependencies.chrono] version = "0" [dependencies.failure] version = "0" [dev-dependencies.lazy_static] version = "1" [dev-dependencies.regex] version = "1" [build-dependencies.chrono] version = "0" vergen-3.0.4/LICENSE-APACHE010064423462670000024000000251371333313322500131710ustar0000000000000000 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 [yyyy] [name of copyright owner] 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. vergen-3.0.4/LICENSE-MIT010064423462670000024000000020571333313322500126750ustar0000000000000000Copyright (c) 2016 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. vergen-3.0.4/README.md010064423462670000024000000111751335677115500125400ustar0000000000000000# vergen ## Current Release [![Crates.io](https://img.shields.io/crates/v/vergen.svg)](https://crates.io/crates/vergen) [![Crates.io](https://img.shields.io/crates/l/vergen.svg)](https://crates.io/crates/vergen) [![Crates.io](https://img.shields.io/crates/d/vergen.svg)](https://crates.io/crates/vergen) ## Build Status | | | ---------------|-----------------------------------------------------------------------------------| | Travis | [![Build Status](https://travis-ci.org/rustyhorde/vergen.svg?branch=master)](https://travis-ci.org/rustyhorde/vergen)| | GitLab CI/CD | [![pipeline status](https://gitlab.com/rustyhorde/vergen/badges/master/pipeline.svg)](https://gitlab.com/rustyhorde/vergen/commits/master)| | Appveyor | [![Build status](https://ci.appveyor.com/api/projects/status/rcdjlx0sxvk3wnww/branch/master?svg=true)](https://ci.appveyor.com/project/CraZySacX/vergen/branch/master)| ## Code Coverage [![codecov](https://codecov.io/gh/rustyhorde/vergen/branch/master/graph/badge.svg)](https://codecov.io/gh/rustyhorde/vergen) ## Version 3.x.x Introduces `generate_cargo_keys()` and support for rebuild when `.git/HEAD` changes. Internally converted to use `failure` so `Result` is no longer exported and changed to the Rust 2018 edition. **This means the 3.x.x version will only work in the beta and nightly channels until Rust 2018 hits stable (12/06/18)** ## Version 2.1.x [![Build Status](https://travis-ci.org/rustyhorde/vergen.svg?branch=v2.1.1)](https://travis-ci.org/rustyhorde/vergen) Backport of the 3.x.x changes to work on stable until Rust 2018 hits stable. ## Version 2.0.x [![Build Status](https://travis-ci.org/rustyhorde/vergen.svg?branch=v2.0.4)](https://travis-ci.org/rustyhorde/vergen) Compatible with Version 1.x.x, but introduces a completely new way to use the constants without having to use the `include!` macro. ## Documentation [Documentation](https://docs.rs/vergen) ## Generate Compile Time Information `vergen`, when used in conjunction with cargo [build scripts], will generate environment variables to use with the `env!` macro. Below is a list of the supported variables. Key | Sample Value --------------------------|---------------------------------------- VERGEN_BUILD_TIMESTAMP |2018-08-09T15:15:57.282334589+00:000 VERGEN_BUILD_DATE |2018-08-09 VERGEN_SHA |75b390dc6c05a6a4aa2791cc7b3934591803bc22 VERGEN_SHA_SHORT |75b390d VERGEN_COMMIT_DATE |2018-08-08 VERGEN_TARGET_TRIPLE |x86_64-unknown-linux-gnu VERGEN_SEMVER |v3.0.0 VERGEN_SEMVER_LIGHTWEIGHT |v3.0.0 The variable generation can be toggled on or off at an individual level via [ConstantsFlags](crate::constants::ConstantsFlags) ### Note on SEMVER `VERGEN_SEMVER` can be generated via `git describe` or by `env::var("CARGO_PKG_VERSION")`. By default, `SEMVER` uses `git describe` if possible, and falls back to `CARGO_PKG_VERSION`. If you wish to force `CARGO_PKG_VERSION`, toggle off `SEMVER` and toggle on `SEMVER_FROM_CARGO_PKG`. ## Re-build On Changed HEAD `vergen` can also be configured to re-run `build.rs` when either `.git/HEAD` or the file that `.git/HEAD` points at changes. This can behavior can be toggled on or of with the [REBUILD_ON_HEAD_CHANGE] flag. [REBUILD_ON_HEAD_CHANGE]: crate::constants::ConstantsFlags::REBUILD_ON_HEAD_CHANGE [build scripts]: https://doc.rust-lang.org/cargo/reference/build-scripts.html ## 'cargo:' Key Build Script Output ```toml [package] #.. build = "build.rs" [dependencies] #.. [build-dependencies] vergen = "3" ``` ### Example 'build.rs' ```rust extern crate vergen; use vergen::{ConstantsFlags, generate_cargo_keys}; fn main() { // Setup the flags, toggling off the 'SEMVER_FROM_CARGO_PKG' flag let mut flags = ConstantsFlags::all(); flags.toggle(ConstantsFlags::SEMVER_FROM_CARGO_PKG); // Generate the 'cargo:' key output generate_cargo_keys(ConstantsFlags::all()).expect("Unable to generate the cargo keys!"); } ``` ### Use the constants in your code ```rust fn my_fn() { println!("Build Timestamp: {}", env!("VERGEN_BUILD_TIMESTAMP")); } ``` ## License Licensed under either of * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. vergen-3.0.4/scripts/run-tests.sh010075523462670000024000000003341335672565200152470ustar0000000000000000#!/bin/bash set -ev if [ "${TRAVIS_RUST_VERSION}" = "stable" ]; then cargo build cargo test elif [ "${TRAVIS_RUST_VERSION}" = "beta" ]; then cargo build cargo test else cargo build cargo test fi vergen-3.0.4/src/constants.rs010064423462670000024000000144271335476553200144350ustar0000000000000000// Copyright (c) 2016, 2018 vergen developers // // Licensed under the Apache License, Version 2.0 // or the MIT // license , at your // option. All files in the project carrying such notice may not be copied, // modified, or distributed except according to those terms. //! Flags used to control the build script output. bitflags!( /// Constants Flags /// /// Use these to toggle off the generation of constants you won't use. /// /// ``` /// # extern crate vergen; /// # /// # use vergen::ConstantsFlags; /// # /// # fn main() { /// let mut actual_flags = ConstantsFlags::all(); /// actual_flags.toggle(ConstantsFlags::SHA_SHORT); /// actual_flags.toggle(ConstantsFlags::BUILD_DATE); /// actual_flags.toggle(ConstantsFlags::SEMVER_LIGHTWEIGHT); /// actual_flags.toggle(ConstantsFlags::SEMVER_FROM_CARGO_PKG); /// /// let expected_flags = ConstantsFlags::BUILD_TIMESTAMP | /// ConstantsFlags::SHA | /// ConstantsFlags::COMMIT_DATE | /// ConstantsFlags::TARGET_TRIPLE | /// ConstantsFlags::SEMVER | /// ConstantsFlags::REBUILD_ON_HEAD_CHANGE; /// /// assert_eq!(actual_flags, expected_flags) /// # } /// ``` pub struct ConstantsFlags: u64 { /// Generate the build timestamp constant. /// /// `2018-08-09T15:15:57.282334589+00:00` const BUILD_TIMESTAMP = 0b0000_0000_0001; /// Generate the build date constant. /// /// `2018-08-09` const BUILD_DATE = 0b0000_0000_0010; /// Generate the SHA constant. /// /// `75b390dc6c05a6a4aa2791cc7b3934591803bc22` const SHA = 0b0000_0000_0100; /// Generate the short SHA constant. /// /// `75b390d` const SHA_SHORT = 0b0000_0000_1000; /// Generate the commit date constant. /// /// `2018-08-08` const COMMIT_DATE = 0b0000_0001_0000; /// Generate the target triple constant. /// /// `x86_64-unknown-linux-gnu` const TARGET_TRIPLE = 0b0000_0010_0000; /// Generate the semver constant. /// /// This defaults to the output of `git describe`. If that output is /// empty, the the `CARGO_PKG_VERSION` environment variable is used. /// /// `v0.1.0` const SEMVER = 0b0000_0100_0000; /// Generate the semver constant, including lightweight tags. /// /// This defaults to the output of `git describe --tags`. If that output /// is empty, the the `CARGO_PKG_VERSION` environment variable is used. /// /// `v0.1.0` const SEMVER_LIGHTWEIGHT = 0b0000_1000_0000; /// Generate the `cargo:rebuild-if-changed=.git/HEAD` and the /// `cargo:rebuild-if-changed=.git/` cargo build output. const REBUILD_ON_HEAD_CHANGE = 0b0001_0000_0000; /// Generate the semver constant from `CARGO_PKG_VERSION`. This is /// mutually exclusive with the `SEMVER` flag. /// /// `0.1.0` const SEMVER_FROM_CARGO_PKG = 0b0010_0000_0000; } ); /// const prefix for codegen pub const CONST_PREFIX: &str = "pub const "; /// const type for codegen pub const CONST_TYPE: &str = ": &str = "; pub const BUILD_TIMESTAMP_NAME: &str = "VERGEN_BUILD_TIMESTAMP"; pub const BUILD_TIMESTAMP_COMMENT: &str = "/// Build Timestamp (UTC)"; pub const BUILD_DATE_NAME: &str = "VERGEN_BUILD_DATE"; pub const BUILD_DATE_COMMENT: &str = "/// Compile Time - Short (UTC)"; pub const SHA_NAME: &str = "VERGEN_SHA"; pub const SHA_COMMENT: &str = "/// Commit SHA"; pub const SHA_SHORT_NAME: &str = "VERGEN_SHA_SHORT"; pub const SHA_SHORT_COMMENT: &str = "/// Commit SHA - Short"; pub const COMMIT_DATE_NAME: &str = "VERGEN_COMMIT_DATE"; pub const COMMIT_DATE_COMMENT: &str = "/// Commit Date"; pub const TARGET_TRIPLE_NAME: &str = "VERGEN_TARGET_TRIPLE"; pub const TARGET_TRIPLE_COMMENT: &str = "/// Target Triple"; pub const SEMVER_NAME: &str = "VERGEN_SEMVER"; pub const SEMVER_COMMENT: &str = "/// Semver"; pub const SEMVER_TAGS_NAME: &str = "VERGEN_SEMVER_LIGHTWEIGHT"; pub const SEMVER_TAGS_COMMENT: &str = "/// Semver (Lightweight)"; #[cfg(test)] mod test { use super::*; #[test] fn bitflags_dont_change() { assert_eq!(ConstantsFlags::BUILD_TIMESTAMP.bits(), 0b0000_0001); assert_eq!(ConstantsFlags::BUILD_DATE.bits(), 0b0000_0010); assert_eq!(ConstantsFlags::SHA.bits(), 0b0000_0100); assert_eq!(ConstantsFlags::SHA_SHORT.bits(), 0b0000_1000); assert_eq!(ConstantsFlags::COMMIT_DATE.bits(), 0b0001_0000); assert_eq!(ConstantsFlags::TARGET_TRIPLE.bits(), 0b0010_0000); assert_eq!(ConstantsFlags::SEMVER.bits(), 0b0100_0000); assert_eq!(ConstantsFlags::SEMVER_LIGHTWEIGHT.bits(), 0b1000_0000); assert_eq!( ConstantsFlags::REBUILD_ON_HEAD_CHANGE.bits(), 0b0001_0000_0000 ); assert_eq!( ConstantsFlags::SEMVER_FROM_CARGO_PKG.bits(), 0b0010_0000_0000 ); } #[test] fn constants_dont_change() { assert_eq!(CONST_PREFIX, "pub const "); assert_eq!(CONST_TYPE, ": &str = "); assert_eq!(BUILD_TIMESTAMP_NAME, "VERGEN_BUILD_TIMESTAMP"); assert_eq!(BUILD_TIMESTAMP_COMMENT, "/// Build Timestamp (UTC)"); assert_eq!(BUILD_DATE_NAME, "VERGEN_BUILD_DATE"); assert_eq!(BUILD_DATE_COMMENT, "/// Compile Time - Short (UTC)"); assert_eq!(SHA_NAME, "VERGEN_SHA"); assert_eq!(SHA_COMMENT, "/// Commit SHA"); assert_eq!(SHA_SHORT_NAME, "VERGEN_SHA_SHORT"); assert_eq!(SHA_SHORT_COMMENT, "/// Commit SHA - Short"); assert_eq!(COMMIT_DATE_NAME, "VERGEN_COMMIT_DATE"); assert_eq!(COMMIT_DATE_COMMENT, "/// Commit Date"); assert_eq!(TARGET_TRIPLE_NAME, "VERGEN_TARGET_TRIPLE"); assert_eq!(TARGET_TRIPLE_COMMENT, "/// Target Triple"); assert_eq!(SEMVER_NAME, "VERGEN_SEMVER"); assert_eq!(SEMVER_COMMENT, "/// Semver"); assert_eq!(SEMVER_TAGS_NAME, "VERGEN_SEMVER_LIGHTWEIGHT"); assert_eq!(SEMVER_TAGS_COMMENT, "/// Semver (Lightweight)"); } } vergen-3.0.4/src/lib.rs010064423462670000024000000072441335473467000131650ustar0000000000000000// Copyright (c) 2016, 2018 vergen developers // // Licensed under the Apache License, Version 2.0 // or the MIT // license , at your // option. All files in the project carrying such notice may not be copied, // modified, or distributed except according to those terms. //! # Generate Build Time Information //! `vergen`, when used in conjunction with cargo [build scripts], will //! generate environment variables to use with the `env!` macro. Below //! is a list of the supported variables. //! //! Key | Sample Value //! --------------------------|---------------------------------------- //! VERGEN_BUILD_TIMESTAMP |2018-08-09T15:15:57.282334589+00:000 //! VERGEN_BUILD_DATE |2018-08-09 //! VERGEN_SHA |75b390dc6c05a6a4aa2791cc7b3934591803bc22 //! VERGEN_SHA_SHORT |75b390d //! VERGEN_COMMIT_DATE |2018-08-08 //! VERGEN_TARGET_TRIPLE |x86_64-unknown-linux-gnu //! VERGEN_SEMVER |v0.1.0 //! VERGEN_SEMVER_LIGHTWEIGHT |v0.1.0 //! //! The variable generation can be toggled on or off at an individual level //! via [ConstantsFlags](crate::constants::ConstantsFlags) //! //! ### Note on SEMVER //! `VERGEN_SEMVER` can be generated via `git describe` or by //! `env::var("CARGO_PKG_VERSION")`. //! //! By default, `SEMVER` uses `git describe` if possible, and falls back to `CARGO_PKG_VERSION`. //! //! If you wish to force `CARGO_PKG_VERSION`, toggle off `SEMVER` and toggle //! on `SEMVER_FROM_CARGO_PKG`. //! //! # Re-build On Changed HEAD //! `vergen` can also be configured to re-run `build.rs` when either `.git/HEAD` or //! the file that `.git/HEAD` points at changes. //! //! This can behavior can be toggled on or of with the [REBUILD_ON_HEAD_CHANGE] flag. //! //! [REBUILD_ON_HEAD_CHANGE]: crate::constants::ConstantsFlags::REBUILD_ON_HEAD_CHANGE //! [build scripts]: https://doc.rust-lang.org/cargo/reference/build-scripts.html //! //! ## 'cargo:' Key Build Script Output //! ```toml //! [package] //! #.. //! build = "build.rs" //! //! [dependencies] //! #.. //! //! [build-dependencies] //! vergen = "2" //! ``` //! //! ### Example 'build.rs' //! ``` //! extern crate vergen; //! //! use vergen::{ConstantsFlags, generate_cargo_keys}; //! //! fn main() { //! // Setup the flags, toggling off the 'SEMVER_FROM_CARGO_PKG' flag //! let mut flags = ConstantsFlags::all(); //! flags.toggle(ConstantsFlags::SEMVER_FROM_CARGO_PKG); //! //! // Generate the 'cargo:' key output //! generate_cargo_keys(ConstantsFlags::all()).expect("Unable to generate the cargo keys!"); //! } //! ``` //! //! ### Use the constants in your code //! ``` //! fn my_fn() { //! println!("Build Timestamp: {}", env!("VERGEN_BUILD_TIMESTAMP")); //! } //! ``` //! //! ## **DEPRECATED** - `version.rs` File Build Script Output //! Generate a `version.rs` file in `OUT_DIR` (defined by cargo) with up to 8 build time //! constants. This file can then be used with the `include!` macro to pull the //! constants into your source for use. //! //! See the [generate_version_rs](crate::output::codegen::generate_version_rs) documentation //! if you wish to use this method. #![deny( missing_docs, missing_debug_implementations, missing_copy_implementations, trivial_casts, trivial_numeric_casts, unsafe_code, unused_import_braces, unused_qualifications )] #[macro_use] extern crate bitflags; #[cfg(test)] #[macro_use] extern crate lazy_static; mod constants; mod output; pub use crate::constants::ConstantsFlags; pub use crate::output::codegen::generate_version_rs; pub use crate::output::envvar::generate_cargo_keys; vergen-3.0.4/src/output/codegen.rs010064423462670000024000000073321335466457400153660ustar0000000000000000// Copyright (c) 2016, 2018 vergen developers // // Licensed under the Apache License, Version 2.0 // or the MIT // license , at your // option. All files in the project carrying such notice may not be copied, // modified, or distributed except according to those terms. //! Geneer //! the `include!` macro within your project. use crate::constants::{ConstantsFlags, CONST_PREFIX, CONST_TYPE}; use crate::output::generate_build_info; use failure::Error; use std::env; use std::fs::File; use std::io::Write; use std::path::PathBuf; fn gen_const(f: &mut W, comment: &str, name: &str, value: &str) -> Result<(), Error> { writeln!( f, "{}\n{}{}{}\"{}\";", comment, CONST_PREFIX, name, CONST_TYPE, value )?; Ok(()) } /// Create a `version.rs` file in `OUT_DIR` and write the toggled on constants /// to the file. /// /// # Example build.rs /// ``` /// # extern crate vergen; /// # /// # use std::env; /// # use vergen::{ConstantsFlags, generate_version_rs}; /// # /// fn main() { /// # env::set_var("OUT_DIR", "target"); /// let mut flags = ConstantsFlags::all(); /// flags.toggle(ConstantsFlags::BUILD_TIMESTAMP); /// generate_version_rs(flags).expect("Unable to generate constants!"); /// } /// ``` /// /// # Example Output (All Flags Enabled) /// ``` /// /// Build Timestamp (UTC) /// pub const VERGEN_BUILD_TIMESTAMP: &str = "2018-08-09T15:15:57.282334589+00:00"; /// /// /// Build Date - Short (UTC) /// pub const VERGEN_BUILD_DATE: &str = "2018-08-09"; /// /// /// Commit SHA /// pub const VERGEN_SHA: &str = "75b390dc6c05a6a4aa2791cc7b3934591803bc22"; /// /// /// Commit SHA - Short /// pub const VERGEN_SHA_SHORT: &str = "75b390d"; /// /// /// Commit Date /// pub const VERGEN_COMMIT_DATE: &str = "'2018-08-08'"; /// /// /// Target Triple /// pub const VERGEN_TARGET_TRIPLE: &str = "x86_64-unknown-linux-gnu"; /// /// /// Semver /// pub const VERGEN_SEMVER: &str = "v0.1.0-pre.0"; /// /// /// Semver (Lightweight) /// pub const VERGEN_SEMVER_LIGHTWEIGHT: &str = "v0.1.0-pre.0"; /// ``` /// /// ## Include the constants in your code (Version 1.x.x only) /// ```ignore /// include!(concat!(env!("OUT_DIR"), "/version.rs")); /// /// format!("{} {} blah {}", VERGEN_BUILD_TIMESTAMP, VERGEN_SHA, VERGEN_SEMVER) /// ``` #[deprecated( since = "2.0.0", note = "Please use `generate_cargo_keys` instead" )] pub fn generate_version_rs(flags: ConstantsFlags) -> Result<(), Error> { let dst = PathBuf::from(env::var("OUT_DIR")?); let mut f = File::create(&dst.join("version.rs"))?; let build_info = generate_build_info(flags)?; for (k, v) in build_info { gen_const(&mut f, k.comment(), k.name(), &v)?; writeln!(f)?; } Ok(()) } #[cfg(test)] mod test { use super::gen_const; use crate::constants::ConstantsFlags; use crate::output::generate_build_info; use regex::Regex; use std::io::Cursor; lazy_static! { static ref CONST_RE: Regex = Regex::new(r#"^/// .*[\r\n]+pub const [A-Z_]+: \&str = ".*";[\r\n]+$"#) .expect("Unable to create const regex"); } #[test] fn gen_const_output() { let flags = ConstantsFlags::all(); let build_info = generate_build_info(flags).expect("Unable to generate build_info map!"); for (k, v) in build_info { let buffer = Vec::new(); let mut cursor = Cursor::new(buffer); gen_const(&mut cursor, k.comment(), k.name(), &v) .expect("Unable to generate const string"); let const_str = String::from_utf8_lossy(&cursor.get_ref()); assert!(CONST_RE.is_match(&const_str)); } } } vergen-3.0.4/src/output/envvar.rs010064423462670000024000000103621336135346400152470ustar0000000000000000// Copyright (c) 2016, 2018 vergen developers // // Licensed under the Apache License, Version 2.0 // or the MIT // license , at your // option. All files in the project carrying such notice may not be copied, // modified, or distributed except according to those terms. //! Build time information. use crate::constants::ConstantsFlags; use crate::output::generate_build_info; use failure::Fallible; use std::fs::{self, File}; use std::io::Read; use std::path::PathBuf; /// Generate the `cargo:` key output /// /// The keys that can be generated include: /// * `cargo:rustc-env==` where key/value pairs are controlled by the supplied `ConstantsFlags`. /// * `cargo:rustc-rerun-if-changed=.git/HEAD` /// * `cargo:rustc-rerun-if-changed=` /// /// # Example `build.rs` /// /// ``` /// extern crate vergen; /// /// use vergen::{ConstantsFlags, generate_cargo_keys}; /// /// fn main() { /// generate_cargo_keys(ConstantsFlags::all()).expect("Unable to generate cargo keys!"); /// } /// ``` pub fn generate_cargo_keys(flags: ConstantsFlags) -> Fallible<()> { // Generate the build info map. let build_info = generate_build_info(flags)?; // Generate the 'cargo:' key output for (k, v) in build_info { println!("cargo:rustc-env={}={}", k.name(), v); } let git_dir_or_file = PathBuf::from(".git"); if let Ok(metadata) = fs::metadata(&git_dir_or_file) { if metadata.is_dir() { // Echo the HEAD path let git_head_path = git_dir_or_file.join("HEAD"); println!("cargo:rerun-if-changed={}", git_head_path.display()); // Determine where HEAD points and echo that path also. let mut f = File::open(&git_head_path)?; let mut git_head_contents = String::new(); let _ = f.read_to_string(&mut git_head_contents)?; eprintln!("HEAD contents: {}", git_head_contents); let ref_vec: Vec<&str> = git_head_contents.split(": ").collect(); if ref_vec.len() == 2 { let current_head_file = ref_vec[1]; let git_refs_path = PathBuf::from(".git").join(current_head_file); println!("cargo:rerun-if-changed={}", git_refs_path.display()); } else { eprintln!("You are most likely in a detached HEAD state"); } } else if metadata.is_file() { // We are in a worktree, so find out where the actual worktrees//HEAD file is. let mut git_file = File::open(&git_dir_or_file)?; let mut git_contents = String::new(); let _ = git_file.read_to_string(&mut git_contents)?; let dir_vec: Vec<&str> = git_contents.split(": ").collect(); eprintln!(".git contents: {}", git_contents); let git_path = dir_vec[1].trim(); // Echo the HEAD psth let git_head_path = PathBuf::from(git_path).join("HEAD"); println!("cargo:rerun-if-changed={}", git_head_path.display()); // Find out what the full path to the .git dir is. let mut actual_git_dir = PathBuf::from(git_path); actual_git_dir.pop(); actual_git_dir.pop(); // Determine where HEAD points and echo that path also. let mut f = File::open(&git_head_path)?; let mut git_head_contents = String::new(); let _ = f.read_to_string(&mut git_head_contents)?; eprintln!("HEAD contents: {}", git_head_contents); let ref_vec: Vec<&str> = git_head_contents.split(": ").collect(); if ref_vec.len() == 2 { let current_head_file = ref_vec[1]; let git_refs_path = actual_git_dir.join(current_head_file); println!("cargo:rerun-if-changed={}", git_refs_path.display()); } else { eprintln!("You are most likely in a detached HEAD state"); } } else { return Err(failure::err_msg( "Invalid .git format (Not a directory or a file)", )); }; } else { eprintln!("Unable to generate 'cargo:rerun-if-changed'"); } Ok(()) } vergen-3.0.4/src/output/mod.rs010064423462670000024000000115451335473123700145310ustar0000000000000000// Copyright (c) 2016, 2018 vergen developers // // Licensed under the Apache License, Version 2.0 // or the MIT // license , at your // option. All files in the project carrying such notice may not be copied, // modified, or distributed except according to those terms. //! Output types use chrono::Utc; use crate::constants::*; use failure::Fallible; use std::collections::HashMap; use std::env; use std::process::Command; pub mod codegen; pub mod envvar; pub fn generate_build_info(flags: ConstantsFlags) -> Fallible> { let mut build_info = HashMap::new(); let now = Utc::now(); if flags.contains(ConstantsFlags::BUILD_TIMESTAMP) { build_info.insert(VergenKey::BuildTimestamp, now.to_rfc3339()); } if flags.contains(ConstantsFlags::BUILD_DATE) { build_info.insert(VergenKey::BuildDate, now.format("%Y-%m-%d").to_string()); } if flags.contains(ConstantsFlags::SHA) { let sha = run_command(Command::new("git").args(&["rev-parse", "HEAD"])); build_info.insert(VergenKey::Sha, sha); } if flags.contains(ConstantsFlags::SHA_SHORT) { let sha = run_command(Command::new("git").args(&["rev-parse", "--short", "HEAD"])); build_info.insert(VergenKey::ShortSha, sha); } if flags.contains(ConstantsFlags::COMMIT_DATE) { let commit_date = run_command(Command::new("git").args(&[ "log", "--pretty=format:'%ad'", "-n1", "--date=short", ])); build_info.insert( VergenKey::CommitDate, commit_date.trim_matches('\'').to_string(), ); } if flags.contains(ConstantsFlags::TARGET_TRIPLE) { let target_triple = env::var("TARGET").unwrap_or_else(|_| "UNKNOWN".to_string()); build_info.insert(VergenKey::TargetTriple, target_triple); } if flags.contains(ConstantsFlags::SEMVER) { let describe = run_command(Command::new("git").args(&["describe"])); let semver = if describe.is_empty() { env::var("CARGO_PKG_VERSION")? } else { describe }; build_info.insert(VergenKey::Semver, semver); } else if flags.contains(ConstantsFlags::SEMVER_FROM_CARGO_PKG) { build_info.insert(VergenKey::Semver, env::var("CARGO_PKG_VERSION")?); } if flags.contains(ConstantsFlags::SEMVER_LIGHTWEIGHT) { let describe = run_command(Command::new("git").args(&["describe", "--tags"])); let semver = if describe.is_empty() { env::var("CARGO_PKG_VERSION")? } else { describe }; build_info.insert(VergenKey::SemverLightweight, semver); } Ok(build_info) } fn run_command(command: &mut Command) -> String { let raw_output = if let Ok(o) = command.output() { String::from_utf8_lossy(&o.stdout).into_owned() } else { "UNKNOWN".to_string() }; raw_output.trim().to_string() } /// Build information keys. #[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)] pub enum VergenKey { /// The build timestamp. (VERGEN_BUILD_TIMESTAMP) BuildTimestamp, /// The build date. (VERGEN_BUILD_DATE) BuildDate, /// The latest commit SHA. (VERGEN_SHA) Sha, /// The latest commit short SHA. (VERGEN_SHA_SHORT) ShortSha, /// The commit date. (VERGEN_COMMIT_DATE). CommitDate, /// The target triple. (VERGEN_TARGET_TRIPLE) TargetTriple, /// The semver version from the last git tag. (VERGEN_SEMVER) Semver, /// The semver version from the last git tag, including lightweight. /// (VERGEN_SEMVER_LIGHTWEIGHT) SemverLightweight, } impl VergenKey { /// Get the comment string for the given key. pub fn comment(self) -> &'static str { match self { VergenKey::BuildTimestamp => BUILD_TIMESTAMP_COMMENT, VergenKey::BuildDate => BUILD_DATE_COMMENT, VergenKey::Sha => SHA_COMMENT, VergenKey::ShortSha => SHA_SHORT_COMMENT, VergenKey::CommitDate => COMMIT_DATE_COMMENT, VergenKey::TargetTriple => TARGET_TRIPLE_COMMENT, VergenKey::Semver => SEMVER_COMMENT, VergenKey::SemverLightweight => SEMVER_TAGS_COMMENT, } } /// Get the name for the given key. pub fn name(self) -> &'static str { match self { VergenKey::BuildTimestamp => BUILD_TIMESTAMP_NAME, VergenKey::BuildDate => BUILD_DATE_NAME, VergenKey::Sha => SHA_NAME, VergenKey::ShortSha => SHA_SHORT_NAME, VergenKey::CommitDate => COMMIT_DATE_NAME, VergenKey::TargetTriple => TARGET_TRIPLE_NAME, VergenKey::Semver => SEMVER_NAME, VergenKey::SemverLightweight => SEMVER_TAGS_NAME, } } } #[cfg(test)] mod test {} vergen-3.0.4/.cargo_vcs_info.json0000644000000001120000000000000123570ustar00{ "git": { "sha1": "21fa51f89ba4a06c7c0ec8cb76dd6f65329b5787" } }