forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(playground): Create built.rs with versions and expose versions t…
…o the UI (vectordotdev#18424) * wip * wip * read versions from built.rs * create headers grid * add link to github issue * button tweaks * tweak header height (shortened)
- Loading branch information
Showing
8 changed files
with
203 additions
and
104 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use cargo_toml::Manifest; | ||
use std::fs::File; | ||
use std::io::Write; | ||
use std::path::{Path, PathBuf}; | ||
use std::{env, fs, io}; | ||
|
||
fn get_vector_toml_path() -> PathBuf { | ||
let path = fs::canonicalize(env::var("CARGO_MANIFEST_DIR").unwrap()).unwrap(); | ||
|
||
// Remove the "lib/vector-vrl/web-playground" suffix | ||
let parent_path = path | ||
.parent() | ||
.and_then(|p| p.parent()) | ||
.and_then(|p| p.parent()); | ||
parent_path | ||
.expect("Failed to find vector repo root") | ||
.join("Cargo.toml") | ||
.to_path_buf() | ||
} | ||
|
||
fn write_build_constants(manifest: &Manifest, dest_path: &Path) -> io::Result<()> { | ||
let mut output_file = File::create(dest_path)?; | ||
output_file.write_all( | ||
"// AUTOGENERATED CONSTANTS. SEE BUILD.RS AT REPOSITORY ROOT. DO NOT MODIFY.\n".as_ref(), | ||
)?; | ||
|
||
let create_const_statement = | ||
|name, value| format!("pub const {}: &str = \"{}\";\n", name, value); | ||
// TODO: For releases, we should use the manifest.package().version(). | ||
// https://github.com/vectordotdev/vector/issues/18425 | ||
let vector_version_const = create_const_statement("VECTOR_VERSION", "master"); | ||
output_file | ||
.write_all(vector_version_const.as_bytes()) | ||
.expect("Failed to write Vector version constant"); | ||
|
||
let vrl_version = &manifest | ||
.dependencies | ||
.get("vrl") | ||
.unwrap() | ||
.detail() | ||
.unwrap() | ||
.version | ||
.clone() | ||
.unwrap(); | ||
let vrl_version_const = create_const_statement("VRL_VERSION", vrl_version); | ||
output_file | ||
.write_all(vrl_version_const.as_bytes()) | ||
.expect("Failed to write Vector version constant"); | ||
Ok(()) | ||
} | ||
|
||
fn main() { | ||
let manifest = | ||
Manifest::from_path(get_vector_toml_path()).expect("Failed to load Vector Cargo.toml"); | ||
let dst = Path::new(&env::var("OUT_DIR").unwrap()).join("built.rs"); | ||
write_build_constants(&manifest, &dst).expect("Failed to write constants"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.