pub fn convert_elf(cli: &Cli) -> OutFiles {
    let package_name = cli.elf.file_stem().expect("ELF must be a file");
    let mut tab_path = cli.elf.clone();
    tab_path.set_extension("tab");
    let protected_size = TBF_HEADER_SIZE.to_string();
    if cli.verbose {
        println!("Package name: {:?}", package_name);
        println!("TAB path: {}", tab_path.display());
        println!("Protected region size: {}", protected_size);
    }
    let stack_size = read_stack_size(cli);
    let elf = cli.elf.as_os_str();
    let mut tbf_path = cli.elf.clone();
    tbf_path.set_extension("tbf");
    if cli.verbose {
        println!("ELF file: {:?}", elf);
        println!("TBF path: {}", tbf_path.display());
    }

    // If elf2tab returns a successful status but does not write to the TBF
    // file, then we run the risk of using an outdated TBF file, creating a
    // hard-to-debug situation. Therefore, we delete the TBF file, forcing
    // elf2tab to create it, and later verify that it exists.
    if let Err(io_error) = remove_file(&tbf_path) {
        // Ignore file-no-found errors, panic on any other error.
        if io_error.kind() != ErrorKind::NotFound {
            panic!("Unable to remove the TBF file. Error: {}", io_error);
        }
    }

    let mut command = Command::new("elf2tab");
    #[rustfmt::skip]
    command.args([
        // TODO: libtock-rs' crates are designed for Tock 2.1's Allow interface,
        // so we should increment this as soon as the Tock kernel will accept a
        // 2.1 app.
        "--kernel-major".as_ref(), "2".as_ref(),
        "--kernel-minor".as_ref(), "0".as_ref(),
        "-n".as_ref(), package_name,
        "-o".as_ref(), tab_path.as_os_str(),
        "--protected-region-size".as_ref(), protected_size.as_ref(),
        "--stack".as_ref(), stack_size.as_ref(),
        elf,
    ]);
    if cli.verbose {
        command.arg("-v");
        println!("elf2tab command: {:?}", command);
        println!("Spawning elf2tab");
    }
    let mut child = command.spawn().expect("failed to spawn elf2tab");
    let status = child.wait().expect("failed to wait for elf2tab");
    if cli.verbose {
        println!("elf2tab finished. {}", status);
    }
    assert!(status.success(), "elf2tab returned an error. {}", status);

    // Verify that elf2tab created the TBF file, and that it is a file.
    match metadata(&tbf_path) {
        Err(io_error) => {
            if io_error.kind() == ErrorKind::NotFound {
                panic!("elf2tab did not create {}", tbf_path.display());
            }
            panic!(
                "Unable to query metadata for {}: {}",
                tbf_path.display(),
                io_error
            );
        }
        Ok(metadata) => {
            assert!(metadata.is_file(), "{} is not a file", tbf_path.display());
        }
    }

    OutFiles { tab_path, tbf_path }
}
// Converts the ELF file specified on the command line into TBF and TAB files,
// and returns the paths to those files.
Converts the ELF file specified on the command line into TBF and TAB files,
and returns the paths to those files.
Converts the ELF file specified on the command line into TBF and TAB files and returns the paths to those files .
pub fn convert_elf(cli: &Cli) -> OutFiles {
    let package_name = cli.elf.file_stem().expect("ELF must be a file");
    let mut tab_path = cli.elf.clone();
    tab_path.set_extension("tab");
    let protected_size = TBF_HEADER_SIZE.to_string();
    if cli.verbose {
        println!("Package name: {:?}", package_name);
        println!("TAB path: {}", tab_path.display());
        println!("Protected region size: {}", protected_size);
    }
    let stack_size = read_stack_size(cli);
    let elf = cli.elf.as_os_str();
    let mut tbf_path = cli.elf.clone();
    tbf_path.set_extension("tbf");
    if cli.verbose {
        println!("ELF file: {:?}", elf);
        println!("TBF path: {}", tbf_path.display());
    }
    // If elf2tab returns a successful status but does not write to the TBF
    // file, then we run the risk of using an outdated TBF file, creating a
    // hard-to-debug situation. Therefore, we delete the TBF file, forcing
    // elf2tab to create it, and later verify that it exists.
    if let Err(io_error) = remove_file(&tbf_path) {
        // Ignore file-no-found errors, panic on any other error.
        if io_error.kind() != ErrorKind::NotFound {
            panic!("Unable to remove the TBF file. Error: {}", io_error);
        }
    }
    let mut command = Command::new("elf2tab");
    #[rustfmt::skip]
    command.args([
        // TODO: libtock-rs' crates are designed for Tock 2.1's Allow interface,
        // so we should increment this as soon as the Tock kernel will accept a
        // 2.1 app.
        "--kernel-major".as_ref(), "2".as_ref(),
        "--kernel-minor".as_ref(), "0".as_ref(),
        "-n".as_ref(), package_name,
        "-o".as_ref(), tab_path.as_os_str(),
        "--protected-region-size".as_ref(), protected_size.as_ref(),
        "--stack".as_ref(), stack_size.as_ref(),
        elf,
    ]);
    if cli.verbose {
        command.arg("-v");
        println!("elf2tab command: {:?}", command);
        println!("Spawning elf2tab");
    }
    let mut child = command.spawn().expect("failed to spawn elf2tab");
    let status = child.wait().expect("failed to wait for elf2tab");
    if cli.verbose {
        println!("elf2tab finished. {}", status);
    }
    assert!(status.success(), "elf2tab returned an error. {}", status);
    // Verify that elf2tab created the TBF file, and that it is a file.
    match metadata(&tbf_path) {
        Err(io_error) => {
            if io_error.kind() == ErrorKind::NotFound {
                panic!("elf2tab did not create {}", tbf_path.display());
            }
            panic!(
                "Unable to query metadata for {}: {}",
                tbf_path.display(),
                io_error
            );
        }
        Ok(metadata) => {
            assert!(metadata.is_file(), "{} is not a file", tbf_path.display());
        }
    }
    OutFiles { tab_path, tbf_path }
}
pub fn convert_elf ( cli : & Cli ) -> OutFiles { let package_name = cli . elf . file_stem ( ) . expect ( " " ) ; let mut tab_path = cli . elf . clone ( ) ; tab_path . set_extension ( " " ) ; let protected_size = TBF_HEADER_SIZE . to_string ( ) ; if cli . verbose { println ! ( " " package_name ) ; println ! ( " " tab_path display ( ) ) ; println ! ( " " protected_size ) ; } let stack_size = read_stack_size ( cli ) ; let elf = cli . elf . as_os_str ( ) ; let mut tbf_path = cli . elf . clone ( ) ; tbf_path . set_extension ( " " ) ; if cli . verbose { println ! ( " " elf ) ; println ! ( " " tbf_path display ( ) ) ; } // If elf2tab returns a successful status but does not write to the TBF // file, then we run the risk of using an outdated TBF file, creating a // hard-to-debug situation. Therefore, we delete the TBF file, forcing // elf2tab to create it, and later verify that it exists. if let Err ( io_error ) = remove_file ( & tbf_path ) { // Ignore file-no-found errors, panic on any other error. if io_error . kind ( ) != ErrorKind :: NotFound { panic ! ( " " io_error ) ; } } let mut command = Command :: new ( " " ) ; # [ rustfmt :: skip ] command . args ( [ // TODO: libtock-rs' crates are designed for Tock 2.1's Allow interface, // so we should increment this as soon as the Tock kernel will accept a // 2.1 app. " " . as_ref ( ) , " " . as_ref ( ) , " " . as_ref ( ) , " " . as_ref ( ) , " " . as_ref ( ) , package_name , " " . as_ref ( ) , tab_path . as_os_str ( ) , " " . as_ref ( ) , protected_size . as_ref ( ) , " " . as_ref ( ) , stack_size . as_ref ( ) , elf , ] ) ; if cli . verbose { command . arg ( " " ) ; println ! ( " " command ) ; println ! ( " " ) ; } let mut child = command . spawn ( ) . expect ( " " ) ; let status = child . wait ( ) . expect ( " " ) ; if cli . verbose { println ! ( " " status ) ; } assert ! ( status success ( ) " " status ) ; // Verify that elf2tab created the TBF file, and that it is a file. match metadata ( & tbf_path ) { Err ( io_error ) => { if io_error . kind ( ) == ErrorKind :: NotFound { panic ! ( " " tbf_path display ( ) ) ; } panic ! ( " " tbf_path display ( ) io_error ) ; } Ok ( metadata ) => { assert ! ( metadata is_file ( ) " " tbf_path display ( ) ) ; } } OutFiles { tab_path , tbf_path } }
Converts the ELF file specified on the command line into TBF and TAB files,
and returns the paths to those files.
Converts the ELF file specified on the command line into TBF and TAB files and returns the paths to those files .
cli
&Cli
cli
&Cli