From 05428c973211017fd722cb7182b2fdeb2ac39cff Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 7 Oct 2016 10:01:31 +0100 Subject: Behave more like a normal compiler (write whole file, not append existing one) --- slice.jam | 7 +++--- slicer/db/Jamfile.jam | 3 --- slicer/ice/Jamfile.jam | 1 - slicer/json/Jamfile.jam | 1 - slicer/test/Jamfile.jam | 30 ++++-------------------- slicer/tool/parser.cpp | 62 ++++++++++++++++++++++++++++--------------------- slicer/xml/Jamfile.jam | 1 - 7 files changed, 43 insertions(+), 62 deletions(-) diff --git a/slice.jam b/slice.jam index 0ea52ba..434e562 100644 --- a/slice.jam +++ b/slice.jam @@ -24,8 +24,8 @@ scanner.register slice-scanner : include ; type.set-scanner SLICE : slice-scanner ; generators.register-standard slice.slice2cpp : SLICE : CPP H : no ; -generators.register-standard slice.slicer : SLICE : CPP H : yes ; -generators.register-standard slice.slicer.pure : SLICE : CPP : pure ; +generators.register-standard slice.slicer : SLICE : CPP CPP(slicer-%) H : yes ; +generators.register-standard slice.slicer.pure : SLICE : CPP(slicer-%) : pure ; toolset.flags slice.slice2cpp INCLUDES ; toolset.flags slice.slice2cpp DLLEXPORT public : --dll-export JAM_DLL_PUBLIC ; @@ -44,12 +44,11 @@ actions slice.slice2cpp actions slice.slicer { slice2cpp -I"$(INCLUDES)" --checksum --output-dir $(1[1]:D) $(2) $(DLLEXPORT) $(ALLOWICE[1]) - slicer -I"$(INCLUDES)" $(2) $(1[1]) $(ALLOWICE[1]) + slicer -I"$(INCLUDES)" $(2) $(1[2]) $(ALLOWICE[1]) } actions slice.slicer.pure { - truncate -c -s 0 $(1[1]) slicer -I"$(INCLUDES)" $(2) $(1[1]) $(ALLOWICE[1]) } diff --git a/slicer/db/Jamfile.jam b/slicer/db/Jamfile.jam index 54677a7..ea394ff 100644 --- a/slicer/db/Jamfile.jam +++ b/slicer/db/Jamfile.jam @@ -45,7 +45,6 @@ run testSelect.cpp ../slicer//slicer .. slicer.sql - ../test//compilation : testSelect ; @@ -64,7 +63,6 @@ run testInsert.cpp ../slicer//slicer .. slicer.sql - ../test//compilation : testInsert ; @@ -84,7 +82,6 @@ run testUpdate.cpp ../slicer//slicer .. slicer.sql - ../test//compilation : testUpdate ; diff --git a/slicer/ice/Jamfile.jam b/slicer/ice/Jamfile.jam index d4c6685..75a7844 100644 --- a/slicer/ice/Jamfile.jam +++ b/slicer/ice/Jamfile.jam @@ -33,7 +33,6 @@ run testSpecifics.cpp ../test//common ../slicer//slicer .. - ../test//compilation : testSpecifics ; diff --git a/slicer/json/Jamfile.jam b/slicer/json/Jamfile.jam index 05b5228..ef3c9e0 100644 --- a/slicer/json/Jamfile.jam +++ b/slicer/json/Jamfile.jam @@ -35,7 +35,6 @@ run testSpecifics.cpp ../test//common ../slicer//slicer .. - ../test//compilation : testSpecifics ; diff --git a/slicer/test/Jamfile.jam b/slicer/test/Jamfile.jam index 47240c3..4046e6f 100644 --- a/slicer/test/Jamfile.jam +++ b/slicer/test/Jamfile.jam @@ -14,8 +14,8 @@ lib boost_date_time ; lib boost_utf : : boost_unit_test_framework ; lib adhocutil : : : : /usr/include/adhocutil ; -generators.register-standard $(__name__).slicer : SLICE : CPP : pure ; -generators.override $(__name__).slicer : slice.slicer.pure ; +generators.register-standard $(__name__).slicer : SLICE : CPP CPP(slicer-%) H : yes ; +generators.override $(__name__).slicer : slice.slicer ; feature.feature slicerbin : : free dependency ; toolset.flags slicer SLICERBIN ; toolset.flags slicer INCLUDES ; @@ -23,48 +23,28 @@ toolset.flags slicer ALLOWICE yes : --ice ; actions slicer bind SLICERBIN { - truncate -c -s 0 $(1[1]) - "$(SLICERBIN)" -I"$(INCLUDES)" $(2) $(1[1]) $(ALLOWICE[1]) --headerPrefix="\"\"" + slice2cpp -I"$(INCLUDES)" --checksum --output-dir $(1[1]:D) $(2) --dll-export JAM_DLL_PUBLIC $(ALLOWICE[1]) + "$(SLICERBIN)" -I"$(INCLUDES)" $(2) $(1[2]) $(ALLOWICE[1]) --headerPrefix="\"\"" } -lib typesice : - [ glob *.ice ] - : - no - . - included - pthread - Ice - IceUtil - included//included - included//included - : : - pthread - Ice - IceUtil - ; - lib types : [ glob *.ice ] conversions.cpp : ../tool//slicer - pure + yes ../tool//slicer . adhocutil - typesice boost_date_time included//included ../slicer//slicer - typesice included//included ../slicer//slicer : : . included//included ../slicer//slicer - typesice ; path-constant me : . ; diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index a15fb34..f8ec87b 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -589,48 +589,56 @@ namespace Slicer { throw CompilerError("Both file handle and path provided."); } FilePtr cppfile( - cpp || cppPath.empty() ? cpp : fopen(cppPath.string(), "a"), + cpp || cppPath.empty() ? cpp : fopen(cppPath.string(), "w"), cppPath.empty() ? fflush : fclose); if (!cppfile && !cppPath.empty()) { throw CompilerError("Failed to open output file"); } - cpp = cppfile.get(); - Slicer::Slicer::Args args; - // Copy includes to args - for(const auto & include : includes) { - args.push_back("-I" + include.string()); - } + try { + cpp = cppfile.get(); + Slicer::Slicer::Args args; + // Copy includes to args + for(const auto & include : includes) { + args.push_back("-I" + include.string()); + } - Slice::PreprocessorPtr icecpp = Slice::Preprocessor::create("slicer", slicePath.string(), args); - FILE * cppHandle = icecpp->preprocess(false); + Slice::PreprocessorPtr icecpp = Slice::Preprocessor::create("slicer", slicePath.string(), args); + FILE * cppHandle = icecpp->preprocess(false); - if (cppHandle == NULL) { - throw CompilerError("preprocess failed"); - } + if (cppHandle == NULL) { + throw CompilerError("preprocess failed"); + } - Slice::UnitPtr u = Slice::Unit::createUnit(false, false, allowIcePrefix, false); + Slice::UnitPtr u = Slice::Unit::createUnit(false, false, allowIcePrefix, false); - int parseStatus = u->parse(slicePath.string(), cppHandle, false); + int parseStatus = u->parse(slicePath.string(), cppHandle, false); - if (!icecpp->close()) { - throw CompilerError("preprocess close failed"); - } + if (!icecpp->close()) { + throw CompilerError("preprocess close failed"); + } - if (parseStatus == EXIT_FAILURE) { - throw CompilerError("unit parse failed"); - } + if (parseStatus == EXIT_FAILURE) { + throw CompilerError("unit parse failed"); + } - unsigned int initial = Components(); + unsigned int initial = Components(); - u->visit(this, false); + u->visit(this, false); - u->destroy(); + u->destroy(); - if (!cppPath.empty()) { - cpp = NULL; - } + if (!cppPath.empty()) { + cpp = NULL; + } - return Components() - initial; + return Components() - initial; + } + catch (...) { + if (!cppPath.empty()) { + unlink(cppPath.c_str()); + } + throw; + } } Slicer::ConversionSpec::ConversionSpec(const Slicer::Args & s) : diff --git a/slicer/xml/Jamfile.jam b/slicer/xml/Jamfile.jam index d16fc8a..e9bcec4 100644 --- a/slicer/xml/Jamfile.jam +++ b/slicer/xml/Jamfile.jam @@ -37,7 +37,6 @@ run testSpecifics.cpp ../test//common ../slicer//slicer .. - ../test//compilation : testSpecifics ; -- cgit v1.2.3