Add an option to generate dependency file

For issue #135
This commit is contained in:
Olivier Goffart 2020-12-15 15:54:09 +01:00
parent ca1fb8ab0d
commit 5a7fa5bf11
2 changed files with 71 additions and 8 deletions

View file

@ -12,11 +12,34 @@ function(SIXTYFPS_TARGET_60_SOURCES target)
foreach (it IN ITEMS ${ARGN})
get_filename_component(_60_BASE_NAME ${it} NAME_WE)
get_filename_component(_60_ABSOLUTE ${it} REALPATH BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
if(CMAKE_GENERATOR STREQUAL "Ninja")
# this code is inspired from the llvm source
# https://github.com/llvm/llvm-project/blob/a00290ed10a6b4e9f6e9be44ceec367562f270c6/llvm/cmake/modules/TableGen.cmake#L13
file(RELATIVE_PATH _60_BASE_NAME_REL ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${_60_BASE_NAME})
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_60_BASE_NAME}.h
COMMAND SixtyFPS::sixtyfps_compiler ${_60_ABSOLUTE} > ${CMAKE_CURRENT_BINARY_DIR}/${_60_BASE_NAME}.h
COMMAND SixtyFPS::sixtyfps_compiler ${_60_ABSOLUTE}
-o ${_60_BASE_NAME_REL}.h --depfile ${_60_BASE_NAME_REL}.d
DEPENDS SixtyFPS::sixtyfps_compiler ${_60_ABSOLUTE}
COMMENT "Generating ${_60_BASE_NAME}.h")
COMMENT "Generating ${_60_BASE_NAME}.h"
DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${_60_BASE_NAME}.d
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
else(CMAKE_GENERATOR STREQUAL "Ninja")
get_filename_component(_60_DIR ${_60_ABSOLUTE} DIRECTORY )
file(GLOB ALL_60S "${_60_DIR}/*.60")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_60_BASE_NAME}.h
COMMAND SixtyFPS::sixtyfps_compiler ${_60_ABSOLUTE}
-o ${CMAKE_CURRENT_BINARY_DIR}/${_60_BASE_NAME}.h
DEPENDS SixtyFPS::sixtyfps_compiler ${_60_ABSOLUTE} ${ALL_60S}
COMMENT "Generating ${_60_BASE_NAME}.h"
)
endif(CMAKE_GENERATOR STREQUAL "Ninja")
target_sources(${target} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/${_60_BASE_NAME}.h)
endforeach()
target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

View file

@ -8,6 +8,7 @@
Please contact info@sixtyfps.io for more information.
LICENSE END */
use sixtyfps_compilerlib::*;
use std::io::Write;
use structopt::StructOpt;
#[derive(StructOpt)]
@ -16,11 +17,26 @@ struct Cli {
#[structopt(short = "f", long = "format", default_value = "cpp")]
format: generator::OutputFormat,
#[structopt(short = "I", name = "include path for other .60 files", number_of_values = 1)]
/// Include path for other .60 files
#[structopt(short = "I", name = "include path", number_of_values = 1)]
include_paths: Vec<std::path::PathBuf>,
#[structopt(name = "path to .60 file", parse(from_os_str))]
/// Path to .60 file
#[structopt(name = "file", parse(from_os_str))]
path: std::path::PathBuf,
/// Generate a dependency file
#[structopt(
name = "dependency file",
long = "depfile",
number_of_values = 1,
parse(from_os_str)
)]
depfile: Option<std::path::PathBuf>,
/// Sets the output file ('-' for stdout)
#[structopt(name = "file to generate", short = "o", default_value = "-")]
output: std::path::PathBuf,
}
fn main() -> std::io::Result<()> {
@ -37,7 +53,31 @@ fn main() -> std::io::Result<()> {
let mut diag = diag.check_and_exit_on_error();
if args.output == std::path::Path::new("-") {
generator::generate(args.format, &mut std::io::stdout(), &doc, &mut diag)?;
} else {
generator::generate(
args.format,
&mut std::fs::File::create(&args.output)?,
&doc,
&mut diag,
)?;
}
if let Some(depfile) = args.depfile {
let mut f = std::fs::File::create(depfile)?;
write!(f, "{}:", args.output.display())?;
for x in diag.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(())
}