diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2009-10-07 09:21:00 -0230 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2009-10-07 09:21:00 -0230 |
commit | 09cdee9531f9f8562509914547d6b6c0907ff5a0 (patch) | |
tree | 6c7b1fe9130763d3ceaecdaebfe2e2519b4ea8d5 /cpp/src/slice2php/Main.cpp | |
parent | Miss changes in my previous commit. (diff) | |
download | ice-09cdee9531f9f8562509914547d6b6c0907ff5a0.tar.bz2 ice-09cdee9531f9f8562509914547d6b6c0907ff5a0.tar.xz ice-09cdee9531f9f8562509914547d6b6c0907ff5a0.zip |
Bug 4294 - fix slice dependencies
Diffstat (limited to 'cpp/src/slice2php/Main.cpp')
-rw-r--r-- | cpp/src/slice2php/Main.cpp | 160 |
1 files changed, 98 insertions, 62 deletions
diff --git a/cpp/src/slice2php/Main.cpp b/cpp/src/slice2php/Main.cpp index e943a742838..f0f09f0a7d5 100644 --- a/cpp/src/slice2php/Main.cpp +++ b/cpp/src/slice2php/Main.cpp @@ -1529,6 +1529,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" @@ -1548,6 +1549,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"); @@ -1602,6 +1604,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"); @@ -1626,24 +1630,30 @@ compile(int argc, char* argv[]) for(i = args.begin(); i != args.end(); ++i) { - PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(false); - - if(cppHandle == 0) + if(depend) { - return EXIT_FAILURE; - } + PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); + FILE* cppHandle = icecpp->preprocess(false); - if(preprocess) - { - char buf[4096]; - while(fgets(buf, static_cast<int>(sizeof(buf)), cppHandle) != NULL) + if(cppHandle == 0) { - if(fputs(buf, stdout) == EOF) - { - return EXIT_FAILURE; - } + return EXIT_FAILURE; + } + + UnitPtr u = Unit::createUnit(false, false, ice); + int parseStatus = u->parse(*i, cppHandle, debug); + u->destroy(); + + if(parseStatus == EXIT_FAILURE) + { + return EXIT_FAILURE; } + + if(!icecpp->printMakefileDependencies(Preprocessor::PHP, includePaths)) + { + return EXIT_FAILURE; + } + if(!icecpp->close()) { return EXIT_FAILURE; @@ -1651,76 +1661,102 @@ 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 + ".php"; - 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); - out << "<?php\n"; - printHeader(out); - printGeneratedHeader(out, base + ".ice"); + string file = base + ".php"; + if(!output.empty()) + { + file = output + '/' + file; + } - // - // Generate the PHP mapping. - // - generate(u, all, checksum, ns, includePaths, out); + 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); - out << "?>\n"; - 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; - } - catch(const string& err) - { - FileTracker::instance()->cleanup(); - getErrorStream() << argv[0] << ": error: " << err << endl; - status = EXIT_FAILURE; + out << "<?php\n"; + printHeader(out); + printGeneratedHeader(out, base + ".ice"); + + // + // Generate the PHP mapping. + // + generate(u, all, checksum, ns, includePaths, out); + + out << "?>\n"; + 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; + } + catch(const string& err) + { + FileTracker::instance()->cleanup(); + getErrorStream() << argv[0] << ": error: " << err << endl; + status = EXIT_FAILURE; + } } - } - u->destroy(); + u->destroy(); + } } { |