Beispiel #1
0
void Config::Parse(const std::string &config, IniSetting::Map &ini, Hdf &hdf) {
  if (boost::ends_with(config, "ini")) {
    std::ifstream ifs(config);
    const std::string str((std::istreambuf_iterator<char>(ifs)),
                          std::istreambuf_iterator<char>());
    auto parsed_ini = IniSetting::FromStringAsMap(str, config);
    for (auto &pair : parsed_ini.items()) {
      ini[pair.first] = pair.second;
    }
  } else {
    hdf.append(config);
  }
}
Beispiel #2
0
void Config::ParseHdfFile(const std::string &filename, Hdf &hdf) {
  hdf.append(filename);
}
Beispiel #3
0
void Config::ParseHdfFile(const std::string &filename, Hdf &hdf,
                          IniSetting::Map &ini) {
  hdf.append(filename);
}
Beispiel #4
0
int prepareOptions(ProgramOptions &po, int argc, char **argv) {
  options_description desc("HipHop Compiler for PHP Usage:\n\n"
                           "\thphp <options> <inputs>\n\n"
                           "Options");
  desc.add_options()
    ("help", "display this message")
    ("version", "display version number")
    ("target,t", value<string>(&po.target)->default_value("run"),
     "lint | "
     "analyze | "
     "php | "
     "cpp | "
     "sep-ext-cpp | "
     "filecache | "
     "run (default)")
    ("format,f", value<string>(&po.format),
     "lint: (none); \n"
     "analyze: (none); \n"
     "php: trimmed (default) | inlined | pickled | typeinfo |"
     " <any combination of them by any separator>; \n"
     "cpp: cluster (default) | file | sys | exe | lib; \n"
     "run: cluster (default) | file")
    ("cluster-count", value<int>(&po.clusterCount)->default_value(0),
     "Cluster by file sizes and output roughly these many number of files. "
     "Use 0 for no clustering.")
    ("input-dir", value<string>(&po.inputDir), "input directory")
    ("program", value<string>(&po.program)->default_value("program"),
     "final program name to use")
    ("args", value<string>(&po.programArgs), "program arguments")
    ("inputs,i", value<vector<string> >(&po.inputs), "input file names")
    ("input-list", value<string>(&po.inputList),
     "file containing list of file names, one per line")
    ("include-path",
     value<vector<string> >(&Option::IncludeSearchPaths)->composing(),
     "a list of include paths to search for files being included in includes "
     "or requires but cannot be found assuming relative paths")
    ("module", value<vector<string> >(&po.modules)->composing(),
     "directories containing all input files")
    ("exclude-dir", value<vector<string> >(&po.excludeDirs)->composing(),
     "directories to exclude from the input")
    ("fmodule", value<vector<string> >(&po.fmodules)->composing(),
     "same with module, except no exclusion checking is performed, so these "
     "modules are forced to be included")
    ("ffile", value<vector<string> >(&po.ffiles)->composing(),
     "extra PHP files forced to include without exclusion checking")
    ("exclude-file", value<vector<string> >(&po.excludeFiles)->composing(),
     "files to exclude from the input, even if parse-on-demand finds it")
    ("exclude-pattern",
     value<vector<string> >(&po.excludePatterns)->composing(),
     "regex (in 'find' command's regex command line option format) of files "
     "or directories to exclude from the input, even if parse-on-demand finds "
     "it")
    ("exclude-static-pattern",
     value<vector<string> >(&po.excludeStaticPatterns)->composing(),
     "regex (in 'find' command's regex command line option format) of files "
     "or directories to exclude from static content cache")
    ("exclude-static-dir",
     value<vector<string> >(&po.excludeStaticDirs)->composing(),
     "directories to exclude from static content cache")
    ("exclude-static-file",
     value<vector<string> >(&po.excludeStaticFiles)->composing(),
     "files to exclude from static content cache")
    ("cfile", value<vector<string> >(&po.cfiles)->composing(),
     "extra static files forced to include without exclusion checking")
    ("cmodule", value<vector<string> >(&po.cmodules)->composing(),
     "extra directories for static files without exclusion checking")
    ("parse-on-demand", value<bool>(&po.parseOnDemand)->default_value(true),
     "whether to parse files that are not specified from command line")
    ("branch", value<string>(&po.branch), "SVN branch")
    ("revision", value<int>(&po.revision), "SVN revision")
    ("output-dir,o", value<string>(&po.outputDir), "output directory")
    ("output-file", value<string>(&po.outputFile), "output file")
    ("sync-dir", value<string>(&po.syncDir),
     "Files will be created in this directory first, then sync with output "
     "directory without overwriting identical files. Great for incremental "
     "compilation and build.")
    ("optimize-level", value<int>(&po.optimizeLevel)->default_value(1),
     "optimization level")
    ("gen-stats", value<bool>(&po.genStats)->default_value(false),
     "whether to generate code errors")
    ("keep-tempdir,k", value<bool>(&po.keepTempDir)->default_value(false),
     "whether to keep the temporary directory")
    ("db-stats", value<string>(&po.dbStats),
     "database connection string to save code errors: "
     "<username>:<password>@<host>:<port>/<db>")
    ("no-type-inference",
     value<bool>(&po.noTypeInference)->default_value(false),
     "turn off type inference for C++ code generation")
    ("no-min-include",
     value<bool>(&po.noMinInclude)->default_value(false),
     "turn off minimium include analysis when target is \"analyze\"")
    ("no-meta-info",
     value<bool>(&po.noMetaInfo)->default_value(false),
     "do not generate class map, function jump table and macros "
     "when generating code; good for demo purposes")
    ("config,c", value<vector<string> >(&po.config)->composing(),
     "config file name")
    ("config-dir", value<string>(&po.configDir),
     "root directory configuration is based on (for example, "
     "excluded directories may be relative path in configuration.")
    ("config-value,v", value<vector<string> >(&po.confStrings)->composing(),
     "individual configuration string in a format of name=value, where "
     "name can be any valid configuration for a config file")
    ("log,l",
     value<int>(&po.logLevel)->default_value(-1),
     "-1: (default); 0: no logging; 1: errors only; 2: warnings and errors; "
     "3: informational as well; 4: really verbose.")
    ("force",
     value<bool>(&po.force)->default_value(true),
     "force to ignore code generation errors and continue compilations")
    ("file-cache",
     value<string>(&po.filecache),
     "if specified, generate a static file cache with this file name")
    ("rtti-directory", value<string>(&po.rttiDirectory)->default_value(""),
     "the directory of rtti profiling data")
    ("java-root",
     value<string>(&po.javaRoot)->default_value("php"),
     "the root package of generated Java FFI classes")
    ("generate-ffi",
     value<bool>(&po.generateFFI)->default_value(false),
     "generate ffi stubs")
    ("dump",
     value<bool>(&po.dump)->default_value(false),
     "dump the program graph")
    ("coredump",
     value<bool>(&po.coredump)->default_value(false),
     "turn on coredump")
    ("nofork",
     value<bool>(&po.nofork)->default_value(false),
     "forking is needed for large compilation to release memory before g++"
     "compilation. turning off forking can help gdb debugging.")
    ("fl-annotate",
     value<bool>(&po.fl_annotate)->default_value(false),
     "Annote emitted source with compiler file-line info")
    ("opts",
     value<string>(&po.optimizations)->default_value("none"),
     "Set optimizations to enable/disable")
    ("ppp",
     value<string>(&po.ppp)->default_value(""),
     "Preprocessed partition configuration. To speed up distcc compilation, "
     "bin/ppp.php can pre-compute better partition between different .cpp "
     "files according to preprocessed file sizes, instead of original file "
     "sizes (default). Run bin/ppp.php to generate an HDF configuration file "
     "to specify here.")
    ;

  positional_options_description p;
  p.add("inputs", -1);
  variables_map vm;
  try {
    store(command_line_parser(argc, argv).options(desc).positional(p).run(),
          vm);
    notify(vm);
  } catch (unknown_option e) {
    cerr << "Error in command line: " << e.what() << "\n\n";
    cout << desc << "\n";
    return -1;
  }
  if (argc <= 1 || vm.count("help")) {
    cout << desc << "\n";
    return 1;
  }
  if (vm.count("version")) {
#ifdef HPHP_VERSION
#undefine HPHP_VERSION
#endif
#define HPHP_VERSION(v) cout << "HipHop Compiler v" #v << "\n";
#include "../version"
    return 1;
  }

  // log level
  if (po.logLevel != -1) {
    Logger::LogLevel = (Logger::LogLevelType)po.logLevel;
  } else if (po.target == "run") {
    Logger::LogLevel = Logger::LogNone;
  } else {
    Logger::LogLevel = Logger::LogInfo;
  }

  // config and system
  Option::GenerateCPPMain = true;
  if (po.noMetaInfo) {
    Option::GenerateCPPMetaInfo = false;
    Option::GenerateCPPMacros = false;
  }
  Option::FlAnnotate = po.fl_annotate;

  Hdf config;
  for (vector<string>::const_iterator it = po.config.begin();
       it != po.config.end(); ++it) {
    config.append(*it);
  }
  for (unsigned int i = 0; i < po.confStrings.size(); i++) {
    config.fromString(po.confStrings[i].c_str());
  }
  Option::Load(config);
  vector<string> badnodes;
  config.lint(badnodes);
  for (unsigned int i = 0; i < badnodes.size(); i++) {
    Logger::Error("Possible bad config node: %s", badnodes[i].c_str());
  }

  if (po.inputDir.empty()) {
    po.inputDir = '.';
  }
  po.inputDir = Util::normalizeDir(po.inputDir);
  if (po.configDir.empty()) {
    po.configDir = po.inputDir;
  }
  po.configDir = Util::normalizeDir(po.configDir);
  Option::RootDirectory = po.configDir;

  for (unsigned int i = 0; i < po.excludeDirs.size(); i++) {
    Option::PackageExcludeDirs.insert
      (Util::normalizeDir(po.excludeDirs[i]));
  }
  for (unsigned int i = 0; i < po.excludeFiles.size(); i++) {
    Option::PackageExcludeFiles.insert(po.excludeFiles[i]);
  }
  for (unsigned int i = 0; i < po.excludePatterns.size(); i++) {
    Option::PackageExcludePatterns.insert
      (Util::format_pattern(po.excludePatterns[i], true));
  }
  for (unsigned int i = 0; i < po.excludeStaticDirs.size(); i++) {
    Option::PackageExcludeStaticDirs.insert
      (Util::normalizeDir(po.excludeStaticDirs[i]));
  }
  for (unsigned int i = 0; i < po.excludeStaticFiles.size(); i++) {
    Option::PackageExcludeStaticFiles.insert(po.excludeStaticFiles[i]);
  }
  for (unsigned int i = 0; i < po.excludeStaticPatterns.size(); i++) {
    Option::PackageExcludeStaticPatterns.insert
      (Util::format_pattern(po.excludeStaticPatterns[i], true));
  }

  if (po.target == "cpp" && po.format == "sys") {
    BuiltinSymbols::NoSuperGlobals = true; // so to generate super globals
    Option::AnalyzePerfectVirtuals = false;
  }
  Option::SystemGen = (po.target == "cpp" && po.format == "sys") ;

  Option::ProgramName = po.program;
  Option::PreprocessedPartitionConfig = po.ppp;

  if (po.target == "cpp") {
    if (po.format.empty()) po.format = "cluster";
  } else if (po.target == "php") {
    if (po.format.empty()) po.format = "trimmed";
  } else if (po.target == "run") {
    if (po.format.empty()) po.format = "cluster";
  }

  if (po.optimizeLevel > 0) {
    Option::PreOptimization = true;
    Option::PostOptimization = true;
  }

  if (po.generateFFI) {
    Option::GenerateFFI = true;
    Option::JavaFFIRootPackage = po.javaRoot;
  }

  return 0;
}