Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoseph Frazer <joseph.frazer@ryansg.com>2020-03-04 15:31:20 -0500
committerJoseph Frazer <joseph.frazer@ryansg.com>2020-03-06 09:41:55 -0500
commite613bd8a8c931546fd10ef50338b5a5affa1b3c2 (patch)
tree0a81c9d7406830068fa4273762897c5c9353191a /tamer/src/ld/poc.rs
parent777494a6026e6eabff9ca9f05f00aa92e2f58c3d (diff)
downloadtame-e613bd8a8c931546fd10ef50338b5a5affa1b3c2.tar.gz
tame-e613bd8a8c931546fd10ef50338b5a5affa1b3c2.tar.bz2
tame-e613bd8a8c931546fd10ef50338b5a5affa1b3c2.zip
[DEV-7081] Add options to tameld
We want to add an option to set the output file to the linker so we do not need to redirect output to awk any longer. This also adds integration tests for tameld.
Diffstat (limited to 'tamer/src/ld/poc.rs')
-rw-r--r--tamer/src/ld/poc.rs15
1 files changed, 5 insertions, 10 deletions
diff --git a/tamer/src/ld/poc.rs b/tamer/src/ld/poc.rs
index 53f9f7b..645a098 100644
--- a/tamer/src/ld/poc.rs
+++ b/tamer/src/ld/poc.rs
@@ -30,19 +30,17 @@ use std::convert::TryInto;
use std::error::Error;
use std::fs;
use std::io::BufReader;
-use std::io::Cursor;
type LinkerAsg<'i> = DefaultAsg<'i, global::ProgIdentSize>;
type LinkerObjectRef = ObjectRef<global::ProgIdentSize>;
-pub fn main() -> Result<(), Box<dyn Error>> {
+pub fn main(package_path: &str, output: &str) -> Result<(), Box<dyn Error>> {
let mut pkgs_seen: FxHashSet<String> = Default::default();
let mut fragments: FxHashMap<&str, String> = Default::default();
let mut depgraph = LinkerAsg::with_capacity(65536, 65536);
let mut roots = Vec::new();
let interner = DefaultInterner::new();
- let package_path = std::env::args().nth(1).expect("Missing argument");
let abs_path = fs::canonicalize(package_path).unwrap();
println!("WARNING: This is proof-of-concept; do not use!");
@@ -84,6 +82,7 @@ pub fn main() -> Result<(), Box<dyn Error>> {
&mut sorted,
name.expect("missing root package name"),
relroot.expect("missing root package relroot"),
+ output,
)?;
Ok(())
@@ -305,6 +304,7 @@ fn output_xmle<'a, 'i, I: Interner<'i>>(
sorted: &mut Sections<'a, 'i>,
name: &'i Symbol<'i>,
relroot: String,
+ output: &str,
) -> Result<(), Box<dyn Error>> {
if !sorted.map.is_empty() {
sorted.map.push_head(get_interner_value(
@@ -332,17 +332,12 @@ fn output_xmle<'a, 'i, I: Interner<'i>>(
));
}
- let writer = Cursor::new(Vec::new());
- let mut xmle_writer = XmleWriter::new(writer);
+ let file = fs::File::create(output)?;
+ let mut xmle_writer = XmleWriter::new(file);
xmle_writer
.write(&sorted, name, &relroot)
.expect("Could not write xmle output");
- print!(
- "{}",
- String::from_utf8(xmle_writer.into_inner().into_inner())?
- );
-
Ok(())
}