Skip to main content
Glama
generate_git_metadata_rust.py2.16 kB
#!/usr/bin/env python3 """Generate Rust constants from git metadata JSON.""" import argparse import json import os import sys def parse_args(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument( "git_metadata_json", help="Path to git metadata JSON file", ) parser.add_argument( "output", help="Output Rust file path", ) return parser.parse_args() def main() -> int: args = parse_args() with open(args.git_metadata_json) as f: data = json.load(f) rust_code = generate_rust_constants(data) os.makedirs(os.path.dirname(args.output), exist_ok=True) with open(args.output, "w") as f: f.write(rust_code) return 0 def generate_rust_constants(data: dict) -> str: """Generate Rust constants from git metadata.""" return f'''// Generated by Buck2 from git metadata // DO NOT EDIT - changes will be overwritten /// Abbreviated commit hash (typically 8 characters) #[allow(dead_code)] pub const ABBREVIATED_COMMIT_HASH: &str = "{data['abbreviated_commit_hash']}"; /// Git branch name #[allow(dead_code)] pub const BRANCH: &str = "{data['branch']}"; /// Calendar version in `YYYYMMDD.hhmmss.0` format (e.g., "20241127.123456.0") #[allow(dead_code)] pub const CAL_VER: &str = "{data['cal_ver']}"; /// Commit date in strict ISO 8601 format (e.g., "2024-11-27T12:34:56Z") #[allow(dead_code)] pub const COMMITTER_DATE_ISO8601: &str = "{data['committer_date_strict_iso8601']}"; /// Commit date as Unix timestamp (seconds since epoch) #[allow(dead_code)] pub const COMMITTER_DATE_TIMESTAMP: i64 = {data['committer_date_timestamp']}; /// Full 40-character commit SHA-1 hash #[allow(dead_code)] pub const COMMIT_HASH: &str = "{data['commit_hash']}"; /// Whether the working tree had uncommitted changes at build time #[allow(dead_code)] pub const IS_DIRTY: bool = {str(data['is_dirty']).lower()}; /// Canonical version string combining calendar version and commit hash (e.g., /// "20241127.123456.0-sha.a1b2c3d") #[allow(dead_code)] pub const VERSION: &str = "{data['canonical_version']}"; ''' if __name__ == "__main__": sys.exit(main())

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/systeminit/si'

If you have feedback or need assistance with the MCP directory API, please join our Discord server