/// Creates a single-source-file version of a Cargo package.
Creates a single-source-file version of a Cargo package.
Creates a single - source - file version of a Cargo package .
pub fn bundle<P: AsRef<Path>>(package_path: P) -> String {
    let manifest_path = package_path.as_ref().join("Cargo.toml");
    let metadata = cargo_metadata::MetadataCommand::new()
        .manifest_path(&manifest_path)
        .no_deps()
        .exec()
        .expect("failed to obtain cargo metadata");
    let cannonical_manifest = manifest_path
        .canonicalize()
        .expect("failed to canonicalize manifest");
    let targets = &metadata
        .packages
        .iter()
        .find(|p| p.manifest_path == cannonical_manifest)
        .expect("package not found")
        .targets;
    let bins: Vec<_> = targets.iter().filter(|t| target_is(t, "bin")).collect();
    assert!(bins.len() != 0, "no binary target found");
    assert!(bins.len() == 1, "multiple binary targets not supported");
    let bin = bins[0];
    let libs: Vec<_> = targets.iter().filter(|t| target_is(t, "lib")).collect();
    assert!(libs.len() <= 1, "multiple library targets not supported");
    let lib = libs.get(0).unwrap_or(&bin);
    let base_path = Path::new(&lib.src_path)
        .parent()
        .expect("lib.src_path has no parent");
    let crate_name = &lib.name;
    eprintln!("expanding binary {}", bin.src_path);
    let code = read_file(&Path::new(&bin.src_path)).expect("failed to read binary target source");
    let mut file = syn::parse_file(&code).expect("failed to parse binary target source");
    Expander {
        base_path,
        crate_name,
    }
    .visit_file_mut(&mut file);
    prettify(file.into_token_stream().to_string())
}
pub fn bundle < P : AsRef < Path > > ( package_path : P ) -> String { let manifest_path = package_path . as_ref ( ) . join ( " " ) ; let metadata = cargo_metadata :: MetadataCommand :: new ( ) . manifest_path ( & manifest_path ) . no_deps ( ) . exec ( ) . expect ( " " ) ; let cannonical_manifest = manifest_path . canonicalize ( ) . expect ( " " ) ; let targets = & metadata . packages . iter ( ) . find ( | p | p . manifest_path == cannonical_manifest ) . expect ( " " ) . targets ; let bins : Vec < _ > = targets . iter ( ) . filter ( | t | target_is ( t , " " ) ) . collect ( ) ; assert ! ( bins len ( ) 0 " " ) ; assert ! ( bins len ( ) 1 " " ) ; let bin = bins [ 0 ] ; let libs : Vec < _ > = targets . iter ( ) . filter ( | t | target_is ( t , " " ) ) . collect ( ) ; assert ! ( libs len ( ) 1 " " ) ; let lib = libs . get ( 0 ) . unwrap_or ( & bin ) ; let base_path = Path :: new ( & lib . src_path ) . parent ( ) . expect ( " " ) ; let crate_name = & lib . name ; eprintln ! ( " " bin src_path ) ; let code = read_file ( & Path :: new ( & bin . src_path ) ) . expect ( " " ) ; let mut file = syn :: parse_file ( & code ) . expect ( " " ) ; Expander { base_path , crate_name , } . visit_file_mut ( & mut file ) ; prettify ( file . into_token_stream ( ) . to_string ( ) ) }
Creates a single-source-file version of a Cargo package.
Creates a single - source - file version of a Cargo package .
package_path
P