Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/testing/geckodriver/   (Firefox Browser Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 3 kB image not shown  

Quelle  build.rs

  Sprache: Rust
 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


// Writes build information to ${OUT_DIR}/build-info.rs which is included in
// the program during compilation:
//
// ```no_run
// const COMMIT_HASH: Option<&'static str> = Some("c31a366");
// const COMMIT_DATE: Option<&'static str> = Some("1988-05-10");
// ```
//
// The values are `None` if running hg failed, e.g. if it is not installed or
// if we are not in an hg repo.

use std::env;
use std::ffi::OsStr;
use std::fs::File;
use std::io;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::Command;

fn main() -> io::Result<()> {
    let cur_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
    let build_info = get_build_info(&cur_dir);

    let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
    let mut fh = File::create(out_dir.join("build-info.rs"))?;
    writeln!(
        fh,
        "const COMMIT_HASH: Option<&'static str> = {:?};",
        build_info.hash()
    )?;
    writeln!(
        fh,
        "const COMMIT_DATE: Option<&'static str> = {:?};",
        build_info.date()
    )?;

    Ok(())
}

fn get_build_info(dir: &Path) -> Box<dyn BuildInfo> {
    if Path::exists(&dir.join(".hg")) {
        Box::new(Hg {})
    } else if Path::exists(&dir.join(".git")) {
        Box::new(Git {})
    } else if let Some(parent) = dir.parent() {
        get_build_info(parent)
    } else {
        eprintln!("unable to detect vcs");
        Box::new(Noop {})
    }
}

trait BuildInfo {
    fn hash(&self) -> Option<String>;
    fn date(&self) -> Option<String>;
}

struct Hg;

impl Hg {
    fn exec<I, S>(&self, args: I) -> Option<String>
    where
        I: IntoIterator<Item = S>,
        S: AsRef<OsStr>,
    {
        Command::new("hg")
            .env("HGPLAIN""1")
            .args(args)
            .output()
            .ok()
            .and_then(|r| String::from_utf8(r.stdout).ok())
            .map(|s| s.trim_end().into())
    }
}

impl BuildInfo for Hg {
    fn hash(&self) -> Option<String> {
        self.exec(["log""-r.""-T{node|short}"])
    }

    fn date(&self) -> Option<String> {
        self.exec(["log""-r.""-T{date|isodate}"])
    }
}

struct Git;

impl Git {
    fn exec<I, S>(&self, args: I) -> Option<String>
    where
        I: IntoIterator<Item = S>,
        S: AsRef<OsStr>,
    {
        Command::new("git")
            .env("GIT_CONFIG_NOSYSTEM""1")
            .args(args)
            .output()
            .ok()
            .and_then(|r| String::from_utf8(r.stdout).ok())
            .map(|s| s.trim_end().into())
    }

    fn to_hg_sha(&self, git_sha: String) -> Option<String> {
        self.exec(["cinnabar""git2hg", &git_sha])
    }
}

impl BuildInfo for Git {
    fn hash(&self) -> Option<String> {
        self.exec(["rev-parse""HEAD"])
            .and_then(|sha| self.to_hg_sha(sha))
            .map(|mut s| {
                s.truncate(12);
                s
            })
    }

    fn date(&self) -> Option<String> {
        self.exec(["log""-1""--date=short""--pretty=format:%cd"])
    }
}

struct Noop;

impl BuildInfo for Noop {
    fn hash(&self) -> Option<String> {
        None
    }
    fn date(&self) -> Option<String> {
        None
    }
}

Messung V0.5 in Prozent
C=92 H=99 G=95

¤ Dauer der Verarbeitung: 0.14 Sekunden  (vorverarbeitet am  2026-06-18) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.