Make it so that you don't need to run xtask through cargo

This commit is contained in:
Olivier Goffart 2021-02-02 08:39:06 +01:00
parent 9b1fd52231
commit 54c979d9e6
5 changed files with 11 additions and 10 deletions

View file

@ -50,7 +50,7 @@ file(GLOB generated_headers_dependencies
add_custom_target(
generated_headers_target
COMMAND
${CMAKE_COMMAND} -E env CARGO_MANIFEST_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../../xtask}" $<TARGET_FILE:xtask> cbindgen --output-dir "${CMAKE_CURRENT_BINARY_DIR}/generated_include/"
xtask cbindgen --output-dir "${CMAKE_CURRENT_BINARY_DIR}/generated_include/"
BYPRODUCTS ${generated_headers}
DEPENDS ${generated_headers_dependencies}
)

View file

@ -60,7 +60,7 @@ fn symlink_files_in_dir<S: AsRef<Path>, T: AsRef<Path>, TS: AsRef<Path>>(
}
pub fn generate() -> Result<(), Box<dyn std::error::Error>> {
let root = super::root_dir()?;
let root = super::root_dir();
let docs_source_dir = root.join("api/sixtyfps-cpp");
let docs_build_dir = root.join("target/cppdocs");

View file

@ -273,7 +273,7 @@ const EXPECTED_HOMEPAGE: &str = "https://sixtyfps.io";
const EXPECTED_REPOSITORY: &str = "https://github.com/sixtyfpsui/sixtyfps";
fn collect_files() -> Result<Vec<PathBuf>> {
let root = super::root_dir()?;
let root = super::root_dir();
let ls_files_output = super::run_command(
"git",
&["ls-files", "-z"],
@ -552,7 +552,7 @@ impl LicenseHeaderCheck {
}
fn check_file(&self, path: &Path) -> Result<()> {
let repo_relative_path = path.strip_prefix(super::root_dir()?)?;
let repo_relative_path = path.strip_prefix(super::root_dir())?;
let path_str = repo_relative_path.to_str().unwrap();
let location = LICENSE_LOCATION_FOR_FILE
.iter()

View file

@ -42,10 +42,11 @@ pub struct CbindgenCommand {
output_dir: String,
}
pub fn root_dir() -> anyhow::Result<PathBuf> {
let mut root = PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").ok_or_else(|| anyhow::anyhow!("Cannot determine root directory - CARGO_MANIFEST_DIR is not set -- you can only run xtask via cargo"))?);
/// The root dir of the git repository
fn root_dir() -> PathBuf {
let mut root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
root.pop(); // $root/xtask -> $root
Ok(root)
root
}
fn run_command<I, K, V>(program: &str, args: &[&str], env: I) -> anyhow::Result<Vec<u8>>
@ -57,7 +58,7 @@ where
let cmdline = || format!("{} {}", program, args.join(" "));
let output = std::process::Command::new(program)
.args(args)
.current_dir(root_dir()?)
.current_dir(root_dir())
.envs(env)
.output()
.with_context(|| format!("Error launching {}", cmdline()))?;
@ -82,7 +83,7 @@ fn main() -> Result<(), Box<dyn Error>> {
match ApplicationArguments::from_args().command {
TaskCommand::CheckLicenseHeaders(cmd) => cmd.check_license_headers()?,
TaskCommand::CppDocs => cppdocs::generate()?,
TaskCommand::Cbindgen(cmd) => cbindgen::gen_all(&root_dir()?, Path::new(&cmd.output_dir))?,
TaskCommand::Cbindgen(cmd) => cbindgen::gen_all(&root_dir(), Path::new(&cmd.output_dir))?,
TaskCommand::NodePackage => nodepackage::generate()?,
};

View file

@ -11,7 +11,7 @@ use anyhow::Context;
use xshell::{cmd, cp, pushd, read_file, rm_rf, write_file};
pub fn generate() -> Result<(), Box<dyn std::error::Error>> {
let root = super::root_dir().context("error determining root directory")?;
let root = super::root_dir();
let node_dir = root.join("api").join("sixtyfps-node");
let cargo_toml_path = node_dir.join("native").join("Cargo.toml");