diff options
author | John Hodge <tpg@mutabah.net> | 2016-10-18 23:16:34 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-10-18 23:16:34 +0800 |
commit | 5f8a9437fbbf78d966aa5811424d12d62d8b65a6 (patch) | |
tree | 26c7edb0009e873b886651276aec5041ae79d4d9 | |
parent | af61f19bce04f6a49ab5179656989c819896be16 (diff) | |
download | mrust-5f8a9437fbbf78d966aa5811424d12d62d8b65a6.tar.gz |
main - Determine output file from crate name if not provided
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | src/main.cpp | 98 |
2 files changed, 81 insertions, 25 deletions
@@ -159,13 +159,17 @@ output/rust/%.o: $(RUST_TESTS_DIR)%.rs $(RUSTCSRC) $(BIN) output/libstd.hir outp @$(BIN) $< -o $@ --stop-after resolve > $@.txt 2>&1 @touch $@ -output/rust/run-pass/allocator-default.o: output/libstd.hir output/liballoc_jemalloc.hir output/liballocator_dummy.hir +output/rust/run-pass/allocator-default.o: output/libstd.hir output/liballoc_jemalloc.hir output/rust/run-pass/allocator-system.o: output/liballoc_system.hir +output/rust/run-pass/anon-extern-mod-cross-crate-2.o: output/test_deps/libanonexternmod.hir + +output/test_deps/libanonexternmod.hir: $(RUST_TESTS_DIR)run-pass/auxiliary/anon-extern-mod-cross-crate-1.rs + $(BIN) $< --crate-type rlib --out-dir output/test_deps > $@.txt 2>&1 test_deps_run-pass.mk: Makefile $(wildcard $(RUST_TESTS_DIR)run_pass/*.rs) @echo "--- Generating test dependencies: $@" @grep 'aux-build:' rustc-nightly/src/test/run-pass/*.rs | awk -F : '{a=gensub(/.+run-pass\/(.*)\.rs$$/, "\\1", "g", $$1); b=gensub(/(.*)\.rs/,"\\1","g",$$3); gsub(/-/,"_",b); print "output/rust/run-pass/" a ".o: " "output/test_deps/lib" b ".hir" }' > $@.tmp - @grep 'aux-build:' rustc-nightly/src/test/run-pass/*.rs | awk -F : '{ print $$3 }' | sort | uniq | awk '{ b=gensub(/(.*)\.rs/,"\\1","g",$$1); gsub(/-/,"_",b); print "output/test_deps/lib" b ".hir: $$(RUST_TESTS_DIR)run-pass/auxiliary/" $$1 " output/libstd.hir" ; print "\t@mkdir -p $$(dir $$@)" ; print "\t@echo \"--- [MRUSTC] $$@\"" ; print "\t@$$(DBG) $$(BIN) $$< --crate-type rlib -o $$@ > $$@.txt 2>&1" }' >> $@.tmp + @grep 'aux-build:' rustc-nightly/src/test/run-pass/*.rs | awk -F : '{ print $$3 }' | sort | uniq | awk '{ b=gensub(/(.*)\.rs/,"\\1","g",$$1); gsub(/-/,"_",b); print "output/test_deps/lib" b ".hir: $$(RUST_TESTS_DIR)run-pass/auxiliary/" $$1 " output/libstd.hir" ; print "\t@mkdir -p $$(dir $$@)" ; print "\t@echo \"--- [MRUSTC] $$@\"" ; print "\t@$$(DBG) $$(BIN) $$< --crate-type rlib --out-dir output/test_deps > $$@.txt 2>&1" }' >> $@.tmp @mv $@.tmp $@ -include test_deps_run-pass.mk diff --git a/src/main.cpp b/src/main.cpp index 148faf6e..7e0d1188 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -109,8 +109,9 @@ struct ProgramParams STAGE_ALL,
} last_stage = STAGE_ALL;
- const char *infile = NULL;
+ ::std::string infile;
::std::string outfile;
+ ::std::string output_dir = "";
const char *crate_path = ".";
::AST::Crate::Type crate_type = ::AST::Crate::Type::Unknown;
@@ -186,14 +187,68 @@ int main(int argc, char *argv[]) CompilePhaseV("LoadCrates", [&]() {
crate.load_externs();
});
- //CompilePhaseV("Temp output - Parsed", [&]() {
- // Dump_Rust( FMT(params.outfile << "_0_pp.rs").c_str(), crate );
- // });
// Iterate all items in the AST, applying syntax extensions
CompilePhaseV("Expand", [&]() {
Expand(crate);
});
+
+ // Extract the crate type and name from the crate attributes
+ auto crate_type = params.crate_type;
+ if( crate_type == ::AST::Crate::Type::Unknown ) {
+ crate_type = crate.m_crate_type;
+ }
+ if( crate_type == ::AST::Crate::Type::Unknown ) {
+ // Assume to be executable
+ crate_type = ::AST::Crate::Type::Executable;
+ }
+ crate.m_crate_type = crate_type;
+ auto crate_name = crate.m_crate_name;
+ if( crate_name == "" ) {
+ auto s = params.infile.find_last_of('/');
+ if( s == ::std::string::npos )
+ s = 0;
+ else
+ s += 1;
+ auto e = params.infile.find_first_of('.', s);
+ if( e == ::std::string::npos )
+ e = params.infile.size() - s;
+
+ crate_name = ::std::string(params.infile.begin() + s, params.infile.begin() + e);
+ for(auto& b : crate_name)
+ {
+ switch(b)
+ {
+ case '0' ... '9':
+ case 'A' ... 'Z':
+ case 'a' ... 'z':
+ case '_':
+ break;
+ case '-':
+ b = '_';
+ break;
+ default:
+ break;
+ }
+ }
+ crate.m_crate_name = crate_name;
+ }
+
+ if( params.outfile == "" ) {
+ switch( crate.m_crate_type )
+ {
+ case ::AST::Crate::Type::RustLib:
+ params.outfile = FMT(params.output_dir << "lib" << crate.m_crate_name << ".hir");
+ break;
+ case ::AST::Crate::Type::Executable:
+ params.outfile = FMT(params.output_dir << crate.m_crate_name);
+ break;
+ default:
+ params.outfile = FMT(params.output_dir << crate.m_crate_name << ".o");
+ break;
+ }
+ DEBUG("params.outfile = " << params.outfile);
+ }
// XXX: Dump crate before resolve
CompilePhaseV("Temp output - Parsed", [&]() {
@@ -226,20 +281,6 @@ int main(int argc, char *argv[]) return 0;
}
- // Extract the crate type and name from the crate attributes
- auto crate_type = params.crate_type;
- if( crate_type == ::AST::Crate::Type::Unknown ) {
- crate_type = crate.m_crate_type;
- }
- if( crate_type == ::AST::Crate::Type::Unknown ) {
- // Assume to be executable
- crate_type = ::AST::Crate::Type::Executable;
- }
- auto crate_name = crate.m_crate_name;
- if( crate_name == "" ) {
- // TODO: Take the crate name from the input filename
- }
-
// --------------------------------------
// HIR Section
// --------------------------------------
@@ -396,7 +437,12 @@ ProgramParams::ProgramParams(int argc, char *argv[]) if( arg[0] != '-' )
{
+ if( this->infile != "" )
+ ;
this->infile = arg;
+
+ if( this->infile == "" )
+ ;
}
else if( arg[1] != '-' )
{
@@ -427,6 +473,17 @@ ProgramParams::ProgramParams(int argc, char *argv[]) }
this->crate_path = argv[++i];
}
+ else if( strcmp(arg, "--out-dir") == 0 ) {
+ if( i == argc - 1 ) {
+ ::std::cerr << "Flag " << arg << " requires an argument" << ::std::endl;
+ exit(1);
+ }
+ this->output_dir = argv[++i];
+ if( this->output_dir == "" )
+ ;
+ if( this->output_dir.back() != '/' )
+ this->output_dir += '/';
+ }
else if( strcmp(arg, "--crate-type") == 0 ) {
if( i == argc - 1 ) {
::std::cerr << "Flag --crate-type requires an argument" << ::std::endl;
@@ -485,10 +542,5 @@ ProgramParams::ProgramParams(int argc, char *argv[]) }
}
}
-
- if( this->outfile == "" )
- {
- this->outfile = (::std::string)this->infile + ".o";
- }
}
|