diff options
author | Dan Goodliffe <daniel.goodliffe@pressassociation.com> | 2015-01-28 10:47:57 +0000 |
---|---|---|
committer | Dan Goodliffe <daniel.goodliffe@pressassociation.com> | 2015-01-28 10:47:57 +0000 |
commit | 4c15f9462449c6af756ca8d778ee47a5fcc5d510 (patch) | |
tree | 75dc0fe8c9c0b748aa8c0d6a5aa1c7b29f0274d9 | |
parent | Call the compile slicer tool from the test case instead of just the library (... (diff) | |
download | slicer-4c15f9462449c6af756ca8d778ee47a5fcc5d510.tar.bz2 slicer-4c15f9462449c6af756ca8d778ee47a5fcc5d510.tar.xz slicer-4c15f9462449c6af756ca8d778ee47a5fcc5d510.zip |
Add support for ice include search paths (-I like slice2cpp)
-rw-r--r-- | slicer/slicer/parser.cpp | 17 | ||||
-rw-r--r-- | slicer/slicer/parser.h | 3 | ||||
-rw-r--r-- | slicer/test/Jamfile.jam | 3 | ||||
-rw-r--r-- | slicer/test/fileStructure.cpp | 1 | ||||
-rw-r--r-- | slicer/test/fileStructure.h | 1 | ||||
-rw-r--r-- | slicer/test/included/Jamfile.jam | 18 | ||||
-rw-r--r-- | slicer/test/included/included.ice | 4 | ||||
-rw-r--r-- | slicer/test/preprocessor.cpp | 15 | ||||
-rw-r--r-- | slicer/test/types.ice | 3 | ||||
-rw-r--r-- | slicer/tool/slicer.cpp | 9 |
10 files changed, 63 insertions, 11 deletions
diff --git a/slicer/slicer/parser.cpp b/slicer/slicer/parser.cpp index 928984e..74fc849 100644 --- a/slicer/slicer/parser.cpp +++ b/slicer/slicer/parser.cpp @@ -542,20 +542,31 @@ namespace Slicer { unsigned int Slicer::Apply(const boost::filesystem::path & ice, const boost::filesystem::path & cpp) { + return Apply(ice, cpp, {}); + } + + unsigned int + Slicer::Apply(const boost::filesystem::path & ice, const boost::filesystem::path & cpp, const Args & args) + { FilePtr cppfile(fopen(cpp.string().c_str(), "a"), fclose); if (!cppfile) { throw std::runtime_error("failed to open code file"); } - return Apply(ice, cppfile.get()); + return Apply(ice, cppfile.get(), args); } unsigned int Slicer::Apply(const boost::filesystem::path & ice, FILE * cpp) { - std::vector<std::string> cppArgs; + return Apply(ice, cpp, {}); + } + + unsigned int + Slicer::Apply(const boost::filesystem::path & ice, FILE * cpp, const Args & args) + { std::lock_guard<std::mutex> lock(slicePreprocessor); - Slice::PreprocessorPtr icecpp = Slice::Preprocessor::create("slicer", ice.string(), cppArgs); + Slice::PreprocessorPtr icecpp = Slice::Preprocessor::create("slicer", ice.string(), args); FILE * cppHandle = icecpp->preprocess(false); if (cppHandle == NULL) { diff --git a/slicer/slicer/parser.h b/slicer/slicer/parser.h index 8e7c469..dca94c0 100644 --- a/slicer/slicer/parser.h +++ b/slicer/slicer/parser.h @@ -17,11 +17,14 @@ namespace Slicer { std::string ConvertToExchangeFunc; }; typedef std::vector<ConversionSpec> Conversions; + typedef std::vector<std::string> Args; Slicer(FILE * c); static unsigned int Apply(const boost::filesystem::path & ice, const boost::filesystem::path & cpp); static unsigned int Apply(const boost::filesystem::path & ice, FILE *); + static unsigned int Apply(const boost::filesystem::path & ice, const boost::filesystem::path & cpp, const Args &); + static unsigned int Apply(const boost::filesystem::path & ice, FILE *, const Args &); virtual bool visitUnitStart(const Slice::UnitPtr&) override; diff --git a/slicer/test/Jamfile.jam b/slicer/test/Jamfile.jam index b4e1046..cd3a8eb 100644 --- a/slicer/test/Jamfile.jam +++ b/slicer/test/Jamfile.jam @@ -15,10 +15,13 @@ lib types : <library>pthread <library>Ice <library>IceUtil + <library>included//included + <implicit-dependency>included//included : : <library>pthread <library>Ice <library>IceUtil + <library>included//included ; lib common : diff --git a/slicer/test/fileStructure.cpp b/slicer/test/fileStructure.cpp index 99f7165..7152e7b 100644 --- a/slicer/test/fileStructure.cpp +++ b/slicer/test/fileStructure.cpp @@ -7,6 +7,7 @@ FileStructure::FileStructure() : base("types"), bjamout(me.parent_path().parent_path().parent_path().leaf() / me.parent_path().parent_path().leaf() / me.parent_path().leaf()), root(me.parent_path().parent_path().parent_path().parent_path()), + included(root / "included"), slice(fs::change_extension(root / base, ".ice")), tmp(root / "bin" / "slicer") { diff --git a/slicer/test/fileStructure.h b/slicer/test/fileStructure.h index ac5d4dd..ac38637 100644 --- a/slicer/test/fileStructure.h +++ b/slicer/test/fileStructure.h @@ -15,6 +15,7 @@ class FileStructure { const fs::path base; const fs::path bjamout; const fs::path root; + const fs::path included; const fs::path slice; const fs::path tmp; }; diff --git a/slicer/test/included/Jamfile.jam b/slicer/test/included/Jamfile.jam new file mode 100644 index 0000000..bbf476d --- /dev/null +++ b/slicer/test/included/Jamfile.jam @@ -0,0 +1,18 @@ +lib dl ; +lib pthread ; +lib Ice ; +lib IceUtil ; + +lib included : + included.ice + : + <library>pthread + <library>Ice + <library>IceUtil + : : + <library>pthread + <library>Ice + <library>IceUtil + <include>. + ; + diff --git a/slicer/test/included/included.ice b/slicer/test/included/included.ice new file mode 100644 index 0000000..d75e55e --- /dev/null +++ b/slicer/test/included/included.ice @@ -0,0 +1,4 @@ +module TestModule { + class DontCountMe { }; +}; + diff --git a/slicer/test/preprocessor.cpp b/slicer/test/preprocessor.cpp index 8b4876a..ed67661 100644 --- a/slicer/test/preprocessor.cpp +++ b/slicer/test/preprocessor.cpp @@ -19,7 +19,7 @@ BOOST_FIXTURE_TEST_SUITE ( preprocessor, FileStructure ); BOOST_AUTO_TEST_CASE( slicer_test_counts_path ) { - auto count = Slicer::Slicer::Apply(slice, boost::filesystem::path("/dev/null")); + auto count = Slicer::Slicer::Apply(slice, boost::filesystem::path("/dev/null"), {"-I" + included.string()}); BOOST_REQUIRE_EQUAL(COMPONENTS_IN_TEST_ICE, count); } @@ -28,7 +28,7 @@ BOOST_AUTO_TEST_CASE( slicer_test_counts_filestar ) FILE * file = fopen("/dev/null", "a"); BOOST_REQUIRE(file); - auto count = Slicer::Slicer::Apply(slice, file); + auto count = Slicer::Slicer::Apply(slice, file, {"-I" + included.string()}); BOOST_REQUIRE_EQUAL(COMPONENTS_IN_TEST_ICE, count); fclose(file); @@ -36,7 +36,7 @@ BOOST_AUTO_TEST_CASE( slicer_test_counts_filestar ) BOOST_AUTO_TEST_CASE( slicer_test_counts_nullfilestar ) { - auto count = Slicer::Slicer::Apply(slice, NULL); + auto count = Slicer::Slicer::Apply(slice, NULL, {"-I" + included.string()}); BOOST_REQUIRE_EQUAL(COMPONENTS_IN_TEST_ICE, count); } @@ -52,16 +52,18 @@ BOOST_AUTO_TEST_CASE( slicer_test_ice ) BOOST_TEST_CHECKPOINT("cpp: " << cpp); fs::remove(cpp); const std::string doslice = stringbf( - "%s %s %s", + "%s -I%s %s %s", root.parent_path() / "tool" / bjamout / "slicer", + included, slice, cpp); BOOST_TEST_CHECKPOINT("slicer: " << doslice); system(doslice); const fs::path obj = fs::change_extension(tmp / base, ".o"); const std::string compile = stringbf( - "g++ -Os -fPIC -c -std=c++0x -I tmp -I /usr/include/Ice -I /usr/include/IceUtil -I %s -I %s %s -o %s", + "g++ -Os -fPIC -c -std=c++0x -I tmp -I /usr/include/Ice -I /usr/include/IceUtil -I %s -I %s -I %s %s -o %s", root / bjamout, + included / bjamout, root / "..", cpp, obj); BOOST_TEST_CHECKPOINT("compile: " << compile); @@ -69,8 +71,9 @@ BOOST_AUTO_TEST_CASE( slicer_test_ice ) const fs::path so = fs::change_extension(tmp / ("libslicer" + slice.filename().string()), ".so"); const std::string link = stringbf( - "g++ -shared -lIce -lIceUtil %s/lib%s.so %s -o %s", + "g++ -shared -lIce -lIceUtil %s/lib%s.so %s/lib%s.so %s -o %s", root / bjamout, base, + included / bjamout, included.leaf(), obj, so); BOOST_TEST_CHECKPOINT("link: " << link); system(link); diff --git a/slicer/test/types.ice b/slicer/test/types.ice index 198116b..8f44fa0 100644 --- a/slicer/test/types.ice +++ b/slicer/test/types.ice @@ -1,5 +1,7 @@ [["cpp:include:boost/date_time/posix_time/posix_time_types.hpp"]] +#include <included.ice> + module TestModule { enum SomeNumbers { One = 1, Ten = 10, FiftyFive = 55 @@ -85,6 +87,7 @@ module TestModule { }; interface IgnoreMe { int someFunction(); + DontCountMe otherFileReference(); }; ["slicer:typeid:mytype"] class Base2 { diff --git a/slicer/tool/slicer.cpp b/slicer/tool/slicer.cpp index 1a41bcb..bc6aa75 100644 --- a/slicer/tool/slicer.cpp +++ b/slicer/tool/slicer.cpp @@ -8,10 +8,12 @@ main(int argc, char ** argv) { boost::filesystem::path slice; boost::filesystem::path cpp; + std::vector<boost::filesystem::path> includes; po::options_description opts("Slicer options"); opts.add_options() ("help,h", "Show this help message") + ("include,I", po::value(&includes), "Add include directory to search path") ("slice,i", po::value(&slice), "Input ICE Slice file") ("cpp,o", po::value(&cpp), "Output C++ file"); @@ -27,8 +29,11 @@ main(int argc, char ** argv) std::cout << opts << std::endl; return 1; } - - Slicer::Slicer::Apply(slice, cpp); + Slicer::Slicer::Args args; + for(const auto & include : includes) { + args.push_back("-I" + include.string()); + } + Slicer::Slicer::Apply(slice, cpp, args); return 0; } |