diff options
author | Jose <jose@zeroc.com> | 2015-01-14 09:22:33 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2015-01-14 09:22:33 +0100 |
commit | 195454df0895051579cd83d6e64d2308a8f42c16 (patch) | |
tree | 6527548e026a929f410aef51ad467b26c4e8bf2c /cpp/src | |
parent | Fix another bug with hello demos. (diff) | |
download | ice-195454df0895051579cd83d6e64d2308a8f42c16.tar.bz2 ice-195454df0895051579cd83d6e64d2308a8f42c16.tar.xz ice-195454df0895051579cd83d6e64d2308a8f42c16.zip |
JavaScript updates to use gulp and add npm and bower packages
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Slice/Preprocessor.cpp | 44 | ||||
-rw-r--r-- | cpp/src/slice2js/Gen.cpp | 26 | ||||
-rw-r--r-- | cpp/src/slice2js/Gen.h | 8 | ||||
-rw-r--r-- | cpp/src/slice2js/Main.cpp | 66 |
4 files changed, 128 insertions, 16 deletions
diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp index 30b6d5c6948..68da2bf9028 100644 --- a/cpp/src/Slice/Preprocessor.cpp +++ b/cpp/src/Slice/Preprocessor.cpp @@ -15,6 +15,7 @@ #include <IceUtil/FileUtil.h> #include <IceUtil/UUID.h> #include <algorithm> +#include <vector> #include <fstream> #include <sys/types.h> #include <sys/stat.h> @@ -398,6 +399,10 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin // // Process each dependency. // + + string sourceFile; + vector<string> dependencies; + string::size_type end; while((end = unprocessed.find(".ice", pos)) != string::npos) { @@ -442,6 +447,17 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin result += "\n <dependsOn name=\"" + file + "\"/>"; } } + if(lang == JavaScriptJSON) + { + if(sourceFile.empty()) + { + sourceFile = file; + } + else + { + dependencies.push_back(file); + } + } else { // @@ -465,6 +481,30 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin { result += "\n </source>\n"; } + else if(lang == JavaScriptJSON) + { + result = "\"" + sourceFile + "\":" + (dependencies.empty() ? "[]" : "["); + for(vector<string>::const_iterator i = dependencies.begin(); i != dependencies.end();) + { + string file = *i; + result += "\n \"" + file + "\""; + if(++i == dependencies.end()) + { + result += "]"; + } + else + { + result += ","; + } + } + + string::size_type pos = 0; + while((pos = result.find("\\", pos + 1)) != string::npos) + { + result.insert(pos, 1, '\\'); + ++pos; + } + } else { result += "\n"; @@ -570,7 +610,9 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin } break; } - case JS: + case JavaScriptJSON: + break; + case JavaScript: { // // Change .o[bj] suffix to .js suffix. diff --git a/cpp/src/slice2js/Gen.cpp b/cpp/src/slice2js/Gen.cpp index 5f13813a3de..c569568c385 100644 --- a/cpp/src/slice2js/Gen.cpp +++ b/cpp/src/slice2js/Gen.cpp @@ -573,7 +573,8 @@ Slice::JsVisitor::writeDocComment(const ContainedPtr& p, const string& deprecate Slice::Gen::Gen(const string& base, const vector<string>& includePaths, const string& dir, bool icejs) : _includePaths(includePaths), - _icejs(icejs) + _icejs(icejs), + _useStdout(false) { _fileBase = base; string::size_type pos = base.find_last_of("/\\"); @@ -581,13 +582,14 @@ Slice::Gen::Gen(const string& base, const vector<string>& includePaths, const st { _fileBase = base.substr(pos + 1); } + string file = _fileBase + ".js"; if(!dir.empty()) { file = dir + '/' + file; } - + _out.open(file.c_str()); if(!_out) { @@ -596,14 +598,32 @@ Slice::Gen::Gen(const string& base, const vector<string>& includePaths, const st throw FileException(__FILE__, __LINE__, os.str()); } FileTracker::instance()->addFile(file); + + printHeader(); + printGeneratedHeader(_out, _fileBase + ".ice"); +} +Slice::Gen::Gen(const string& base, const vector<string>& includePaths, const string& dir, bool icejs, ostream& out) : + _out(out), + _includePaths(includePaths), + _icejs(icejs), + _useStdout(true) +{ + _fileBase = base; + string::size_type pos = base.find_last_of("/\\"); + if(pos != string::npos) + { + _fileBase = base.substr(pos + 1); + } + + printHeader(); printGeneratedHeader(_out, _fileBase + ".ice"); } Slice::Gen::~Gen() { - if(_out.isOpen()) + if(_out.isOpen() || _useStdout) { _out << '\n'; } diff --git a/cpp/src/slice2js/Gen.h b/cpp/src/slice2js/Gen.h index f982df5ce27..86011de4bc8 100644 --- a/cpp/src/slice2js/Gen.h +++ b/cpp/src/slice2js/Gen.h @@ -55,6 +55,12 @@ public: const std::vector<std::string>&, const std::string&, bool); + + Gen(const std::string&, + const std::vector<std::string>&, + const std::string&, + bool, + std::ostream&); ~Gen(); void generate(const UnitPtr&); @@ -62,11 +68,13 @@ public: private: + std::ofstream _stdout; IceUtilInternal::Output _out; std::vector<std::string> _includePaths; std::string _fileBase; bool _icejs; + bool _useStdout; void printHeader(); diff --git a/cpp/src/slice2js/Main.cpp b/cpp/src/slice2js/Main.cpp index b09dccb6287..328b8997f60 100644 --- a/cpp/src/slice2js/Main.cpp +++ b/cpp/src/slice2js/Main.cpp @@ -66,8 +66,10 @@ usage(const char* n) "-UNAME Remove any definition for NAME.\n" "-IDIR Put DIR in the include file search path.\n" "-E Print preprocessor output on stdout.\n" + "--stdout Print genreated code to stdout.\n" "--output-dir DIR Create files in the directory DIR.\n" "--depend Generate Makefile dependencies.\n" + "--depend-json Generate Makefile dependencies in JSON format.\n" "-d, --debug Print debug messages.\n" "--ice Permit `Ice' prefix (for building Ice source code only).\n" "--underscore Permit underscores in Slice identifiers.\n" @@ -85,8 +87,10 @@ compile(int argc, char* argv[]) opts.addOpt("U", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); opts.addOpt("I", "", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); opts.addOpt("E"); + opts.addOpt("", "stdout"); opts.addOpt("", "output-dir", IceUtilInternal::Options::NeedArg); opts.addOpt("", "depend"); + opts.addOpt("", "depend-json"); opts.addOpt("d", "debug"); opts.addOpt("", "ice"); opts.addOpt("", "underscore"); @@ -137,9 +141,13 @@ compile(int argc, char* argv[]) bool preprocess = opts.isSet("E"); + bool useStdout = opts.isSet("stdout"); + string output = opts.optArg("output-dir"); bool depend = opts.isSet("depend"); + + bool dependJSON = opts.isSet("depend-json"); bool debug = opts.isSet("debug"); @@ -161,18 +169,27 @@ compile(int argc, char* argv[]) IceUtil::CtrlCHandler ctrlCHandler; ctrlCHandler.setCallback(interruptedCallback); + if(dependJSON) + { + cout << "{" << endl; + } + + // + // Create a copy of args without the duplicates. + // + vector<string> sources; for(vector<string>::const_iterator i = args.begin(); i != args.end(); ++i) { - // - // Ignore duplicates. - // - vector<string>::iterator p = find(args.begin(), args.end(), *i); - if(p != i) + vector<string>::iterator p = find(sources.begin(), sources.end(), *i); + if(p == sources.end()) { - continue; + sources.push_back(*i); } - - if(depend) + } + + for(vector<string>::const_iterator i = sources.begin(); i != sources.end();) + { + if(depend || dependJSON) { PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); FILE* cppHandle = icecpp->preprocess(false, "-D__SLICE2JS__"); @@ -190,8 +207,10 @@ compile(int argc, char* argv[]) { return EXIT_FAILURE; } - - if(!icecpp->printMakefileDependencies(Preprocessor::JS, includePaths, + + bool last = (++i == sources.end()); + + if(!icecpp->printMakefileDependencies(depend ? Preprocessor::JavaScript : Preprocessor::JavaScriptJSON, includePaths, "-D__SLICE2JS__")) { return EXIT_FAILURE; @@ -201,6 +220,15 @@ compile(int argc, char* argv[]) { return EXIT_FAILURE; } + + if(dependJSON) + { + if(!last) + { + cout << ","; + } + cout << "\n"; + } } else { @@ -245,8 +273,16 @@ compile(int argc, char* argv[]) { try { - Gen gen(icecpp->getBaseName(), includePaths, output, icejs); - gen.generate(p); + if(useStdout) + { + Gen gen(icecpp->getBaseName(), includePaths, output, icejs, cout); + gen.generate(p); + } + else + { + Gen gen(icecpp->getBaseName(), includePaths, output, icejs); + gen.generate(p); + } } catch(const Slice::FileException& ex) { @@ -262,6 +298,7 @@ compile(int argc, char* argv[]) p->destroy(); } + ++i; } { @@ -274,6 +311,11 @@ compile(int argc, char* argv[]) } } } + + if(dependJSON) + { + cout << "}" << endl; + } return status; } |