mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-02 22:54:36 +00:00

The README.md contains the warning that used to be in lib.rs. Add README.md files to all internal crates ... pointing to the official public crate to use instead. Rename internal crates fixup: README files fixup rename
78 lines
2.7 KiB
Rust
78 lines
2.7 KiB
Rust
// Copyright © SixtyFPS GmbH <info@sixtyfps.io>
|
|
// SPDX-License-Identifier: (GPL-3.0-only OR LicenseRef-SixtyFPS-commercial)
|
|
|
|
use clap::Parser;
|
|
use i_slint_compiler::diagnostics::BuildDiagnostics;
|
|
use i_slint_compiler::*;
|
|
use std::io::Write;
|
|
|
|
#[derive(Parser)]
|
|
struct Cli {
|
|
/// Set output format
|
|
#[clap(short = 'f', long = "format", default_value = "cpp")]
|
|
format: generator::OutputFormat,
|
|
|
|
/// Include path for other .slint files
|
|
#[clap(short = 'I', name = "include path", number_of_values = 1, parse(from_os_str))]
|
|
include_paths: Vec<std::path::PathBuf>,
|
|
|
|
/// Path to .slint file ('-' for stdin)
|
|
#[clap(name = "file", parse(from_os_str))]
|
|
path: std::path::PathBuf,
|
|
|
|
/// The style name ('native', 'fluent', or 'ugly')
|
|
#[clap(long, name = "style name")]
|
|
style: Option<String>,
|
|
|
|
/// Generate a dependency file
|
|
#[clap(name = "dependency file", long = "depfile", number_of_values = 1, parse(from_os_str))]
|
|
depfile: Option<std::path::PathBuf>,
|
|
|
|
/// Sets the output file ('-' for stdout)
|
|
#[clap(name = "file to generate", short = 'o', default_value = "-", parse(from_os_str))]
|
|
output: std::path::PathBuf,
|
|
}
|
|
|
|
fn main() -> std::io::Result<()> {
|
|
proc_macro2::fallback::force(); // avoid a abort if panic=abort is set
|
|
let args = Cli::parse();
|
|
let mut diag = BuildDiagnostics::default();
|
|
let syntax_node = parser::parse_file(&args.path, &mut diag);
|
|
//println!("{:#?}", syntax_node);
|
|
if diag.has_error() {
|
|
diag.print();
|
|
std::process::exit(-1);
|
|
}
|
|
let mut compiler_config = CompilerConfiguration::new(args.format);
|
|
compiler_config.include_paths = args.include_paths;
|
|
if let Some(style) = args.style {
|
|
compiler_config.style = Some(style);
|
|
}
|
|
let syntax_node = syntax_node.expect("diags contained no compilation errors");
|
|
let (doc, diag) = spin_on::spin_on(compile_syntax_node(syntax_node, diag, compiler_config));
|
|
|
|
let diag = diag.check_and_exit_on_error();
|
|
|
|
if args.output == std::path::Path::new("-") {
|
|
generator::generate(args.format, &mut std::io::stdout(), &doc)?;
|
|
} else {
|
|
generator::generate(args.format, &mut std::fs::File::create(&args.output)?, &doc)?;
|
|
}
|
|
|
|
if let Some(depfile) = args.depfile {
|
|
let mut f = std::fs::File::create(depfile)?;
|
|
write!(f, "{}:", args.output.display())?;
|
|
for x in &diag.all_loaded_files {
|
|
if x.is_absolute() {
|
|
write!(f, " {}", x.display())?;
|
|
}
|
|
}
|
|
for resource in doc.root_component.embedded_file_resources.borrow().keys() {
|
|
write!(f, " {}", resource)?;
|
|
}
|
|
|
|
writeln!(f)?;
|
|
}
|
|
diag.print_warnings_and_exit_on_error();
|
|
Ok(())
|
|
}
|