summaryrefslogtreecommitdiff
path: root/cpp/src/slice2rb
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2009-10-07 09:21:00 -0230
committerDwayne Boone <dwayne@zeroc.com>2009-10-07 09:21:00 -0230
commit09cdee9531f9f8562509914547d6b6c0907ff5a0 (patch)
tree6c7b1fe9130763d3ceaecdaebfe2e2519b4ea8d5 /cpp/src/slice2rb
parentMiss changes in my previous commit. (diff)
downloadice-09cdee9531f9f8562509914547d6b6c0907ff5a0.tar.bz2
ice-09cdee9531f9f8562509914547d6b6c0907ff5a0.tar.xz
ice-09cdee9531f9f8562509914547d6b6c0907ff5a0.zip
Bug 4294 - fix slice dependencies
Diffstat (limited to 'cpp/src/slice2rb')
-rw-r--r--cpp/src/slice2rb/Main.cpp145
1 files changed, 90 insertions, 55 deletions
diff --git a/cpp/src/slice2rb/Main.cpp b/cpp/src/slice2rb/Main.cpp
index 369fc9329db..68305f45072 100644
--- a/cpp/src/slice2rb/Main.cpp
+++ b/cpp/src/slice2rb/Main.cpp
@@ -84,6 +84,7 @@ usage(const char* n)
"-IDIR Put DIR in the include file search path.\n"
"-E Print preprocessor output on stdout.\n"
"--output-dir DIR Create files in the directory DIR.\n"
+ "--depend Generate Makefile dependencies.\n"
"-d, --debug Print debug messages.\n"
"--ice Permit `Ice' prefix (for building Ice source code only)\n"
"--all Generate code for Slice definitions in included files.\n"
@@ -102,6 +103,7 @@ compile(int argc, char* argv[])
opts.addOpt("I", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat);
opts.addOpt("E");
opts.addOpt("", "output-dir", IceUtilInternal::Options::NeedArg);
+ opts.addOpt("", "depend");
opts.addOpt("d", "debug");
opts.addOpt("", "ice");
opts.addOpt("", "all");
@@ -155,6 +157,8 @@ compile(int argc, char* argv[])
string output = opts.optArg("output-dir");
+ bool depend = opts.isSet("depend");
+
bool debug = opts.isSet("debug");
bool ice = opts.isSet("ice");
@@ -177,25 +181,30 @@ compile(int argc, char* argv[])
for(i = args.begin(); i != args.end(); ++i)
{
+ if(depend)
+ {
+ PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs);
+ FILE* cppHandle = icecpp->preprocess(false);
- PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs);
- FILE* cppHandle = icecpp->preprocess(false);
+ if(cppHandle == 0)
+ {
+ return EXIT_FAILURE;
+ }
- if(cppHandle == 0)
- {
- return EXIT_FAILURE;
- }
+ UnitPtr u = Unit::createUnit(false, false, ice);
+ int parseStatus = u->parse(*i, cppHandle, debug);
+ u->destroy();
- if(preprocess)
- {
- char buf[4096];
- while(fgets(buf, static_cast<int>(sizeof(buf)), cppHandle) != NULL)
+ if(parseStatus == EXIT_FAILURE)
{
- if(fputs(buf, stdout) == EOF)
- {
- return EXIT_FAILURE;
- }
+ return EXIT_FAILURE;
+ }
+
+ if(!icecpp->printMakefileDependencies(Preprocessor::Ruby, includePaths))
+ {
+ return EXIT_FAILURE;
}
+
if(!icecpp->close())
{
return EXIT_FAILURE;
@@ -203,68 +212,94 @@ compile(int argc, char* argv[])
}
else
{
- UnitPtr u = Unit::createUnit(false, all, ice);
- int parseStatus = u->parse(*i, cppHandle, debug);
+ PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs);
+ FILE* cppHandle = icecpp->preprocess(false);
- if(!icecpp->close())
+ if(cppHandle == 0)
{
- u->destroy();
return EXIT_FAILURE;
}
- if(parseStatus == EXIT_FAILURE)
+ if(preprocess)
{
- status = EXIT_FAILURE;
+ char buf[4096];
+ while(fgets(buf, static_cast<int>(sizeof(buf)), cppHandle) != NULL)
+ {
+ if(fputs(buf, stdout) == EOF)
+ {
+ return EXIT_FAILURE;
+ }
+ }
+ if(!icecpp->close())
+ {
+ return EXIT_FAILURE;
+ }
}
else
{
- string base = icecpp->getBaseName();
- string::size_type pos = base.find_last_of("/\\");
- if(pos != string::npos)
+ UnitPtr u = Unit::createUnit(false, all, ice);
+ int parseStatus = u->parse(*i, cppHandle, debug);
+
+ if(!icecpp->close())
{
- base.erase(0, pos + 1);
+ u->destroy();
+ return EXIT_FAILURE;
}
- string file = base + ".rb";
- if(!output.empty())
+ if(parseStatus == EXIT_FAILURE)
{
- file = output + '/' + file;
+ status = EXIT_FAILURE;
}
-
- try
+ else
{
- IceUtilInternal::Output out;
- out.open(file.c_str());
- if(!out)
+ string base = icecpp->getBaseName();
+ string::size_type pos = base.find_last_of("/\\");
+ if(pos != string::npos)
{
- ostringstream os;
- os << "cannot open`" << file << "': " << strerror(errno);
- throw FileException(__FILE__, __LINE__, os.str());
+ base.erase(0, pos + 1);
}
- FileTracker::instance()->addFile(file);
- printHeader(out);
- printGeneratedHeader(out, base + ".ice", "#");
-
- //
- // Generate the Ruby mapping.
- //
- generate(u, all, checksum, includePaths, out);
+ string file = base + ".rb";
+ if(!output.empty())
+ {
+ file = output + '/' + file;
+ }
- out.close();
- }
- catch(const Slice::FileException& ex)
- {
- // If a file could not be created, then cleanup
- // any created files.
- FileTracker::instance()->cleanup();
- u->destroy();
- getErrorStream() << argv[0] << ": error: " << ex.reason() << endl;
- return EXIT_FAILURE;
+ try
+ {
+ IceUtilInternal::Output out;
+ out.open(file.c_str());
+ if(!out)
+ {
+ ostringstream os;
+ os << "cannot open`" << file << "': " << strerror(errno);
+ throw FileException(__FILE__, __LINE__, os.str());
+ }
+ FileTracker::instance()->addFile(file);
+
+ printHeader(out);
+ printGeneratedHeader(out, base + ".ice", "#");
+
+ //
+ // Generate the Ruby mapping.
+ //
+ generate(u, all, checksum, includePaths, out);
+
+ out.close();
+ }
+ catch(const Slice::FileException& ex)
+ {
+ // If a file could not be created, then cleanup
+ // any created files.
+ FileTracker::instance()->cleanup();
+ u->destroy();
+ getErrorStream() << argv[0] << ": error: " << ex.reason() << endl;
+ return EXIT_FAILURE;
+ }
}
- }
- u->destroy();
+ u->destroy();
+ }
}
{