-
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.
- Loading branch information
1 parent
8753149
commit 5ad420b
Showing
12 changed files
with
35 additions
and
247 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,70 +1,47 @@ | ||
use clap::{Parser, Subcommand}; | ||
|
||
use anyhow::{Context, Result}; | ||
use pulumi_wasm_generator_lib::{extract_micro_package, generate_combined}; | ||
use std::path::Path; | ||
use std::{env, fs}; | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(version, about, long_about = None)] | ||
struct App { | ||
#[clap(subcommand)] | ||
command: Command, | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
enum Command { | ||
GenProvider { | ||
#[arg(short, long)] | ||
schema: String, | ||
|
||
#[arg(short, long)] | ||
output: String, | ||
|
||
#[arg(short, long)] | ||
remove: Option<bool>, | ||
}, | ||
GenRust { | ||
#[arg(short, long)] | ||
schema: String, | ||
|
||
#[arg(short, long)] | ||
output: String, | ||
|
||
#[arg(short, long)] | ||
remove: Option<bool>, | ||
}, | ||
} | ||
|
||
pub fn generate(provider_name: &str, provider_version: &str) { | ||
pub fn generate(provider_name: &str, provider_version: &str) -> Result<()> { | ||
let schema_output = std::process::Command::new("pulumi") | ||
.arg("package") | ||
.arg("get-schema") | ||
.arg(format!("{}@{}", provider_name, provider_version)) | ||
.output() | ||
.expect("Failed to execute pulumi command"); | ||
.context("Failed to execute pulumi command")?; | ||
|
||
let schema = String::from_utf8(schema_output.stdout).expect("Invalid UTF-8 in pulumi output"); | ||
|
||
let out_dir = env::var_os("OUT_DIR").unwrap(); | ||
let out_dir = out_dir.to_str().unwrap(); | ||
let out_dir = env::var_os("OUT_DIR").context("Failed to get OUT_DIR environment variable")?; | ||
let out_dir = out_dir | ||
.to_str() | ||
.context(format!("Failed to convert [{:?}] to string", out_dir))?; | ||
|
||
let location = Path::new(out_dir).join("pulumi").join(provider_name); | ||
|
||
let temp_dir = tempfile::tempdir().unwrap(); | ||
let temp_dir = tempfile::tempdir().context("Failed to create temporary directory")?; | ||
let file = temp_dir.path().join("schema.json"); | ||
fs::write(&file, &schema).unwrap(); | ||
fs::write(&file, &schema).context("Failed to write schema")?; | ||
|
||
generate_combined(file.as_path(), &location).unwrap(); | ||
generate_combined(file.as_path(), &location).context("Failed to generate glue files")?; | ||
println!("cargo::rerun-if-changed=build.rs"); | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn generate_from_schema(schema_file: &Path) { | ||
let package = extract_micro_package(schema_file).unwrap(); | ||
pub fn generate_from_schema(schema_file: &Path) -> Result<()> { | ||
let package = extract_micro_package(schema_file).context("Failed to deserialize package")?; | ||
let provider_name = package.name; | ||
|
||
let out_dir = env::var_os("OUT_DIR").unwrap(); | ||
let out_dir = out_dir.to_str().unwrap(); | ||
let out_dir = env::var_os("OUT_DIR").context("Failed to get OUT_DIR environment variable")?; | ||
let out_dir = out_dir | ||
.to_str() | ||
.context(format!("Failed to convert [{:?}] to string", out_dir))?; | ||
let location = Path::new(out_dir).join("pulumi").join(provider_name); | ||
|
||
generate_combined(schema_file, &location).unwrap(); | ||
generate_combined(schema_file, &location).context("Failed to generate glue files")?; | ||
println!("cargo::rerun-if-changed=build.rs"); | ||
println!("cargo::rerun-if-changed={}", schema_file.display()); | ||
Ok(()) | ||
} |
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
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