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/slice2py/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/slice2py/Main.cpp')
-rw-r--r-- | cpp/src/slice2py/Main.cpp | 178 |
1 files changed, 107 insertions, 71 deletions
diff --git a/cpp/src/slice2py/Main.cpp b/cpp/src/slice2py/Main.cpp index 3af0f9b217b..74cc5d02916 100644 --- a/cpp/src/slice2py/Main.cpp +++ b/cpp/src/slice2py/Main.cpp @@ -396,6 +396,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" @@ -416,6 +417,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"); @@ -471,6 +473,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"); @@ -499,24 +503,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(keepComments); - - 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::Python, includePaths, "", prefix)) + { + return EXIT_FAILURE; + } + if(!icecpp->close()) { return EXIT_FAILURE; @@ -524,88 +534,114 @@ 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(keepComments); - 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; } - // - // Append the suffix "_ice" to the filename in order to avoid any conflicts - // with Slice module names. For example, if the file Test.ice defines a - // Slice module named "Test", then we couldn't create a Python package named - // "Test" and also call the generated file "Test.py". - // - string file = prefix + base + "_ice.py"; - 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 Python mapping. + // Append the suffix "_ice" to the filename in order to avoid any conflicts + // with Slice module names. For example, if the file Test.ice defines a + // Slice module named "Test", then we couldn't create a Python package named + // "Test" and also call the generated file "Test.py". // - generate(u, all, checksum, includePaths, out); - - out.close(); + string file = prefix + base + "_ice.py"; + if(!output.empty()) + { + file = output + '/' + file; + } - // - // Create or update the Python package hierarchy. - // - if(!noPackage) + try { - PackageVisitor visitor(prefix + base + "_ice", output); - u->visit(&visitor, false); + 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 Python mapping. + // + generate(u, all, checksum, includePaths, out); + + out.close(); + + // + // Create or update the Python package hierarchy. + // + if(!noPackage) + { + PackageVisitor visitor(prefix + base + "_ice", output); + u->visit(&visitor, false); + } + } + 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; } } - 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(); + } } { |