Exemplo n.º 1
0
int EclCMDShell::callExternal(ArgvIterator &iter)
{
    const char *argv[100];
    StringBuffer cmdstr("ecl-");
    cmdstr.append(cmd.str());
    int i=0;
    argv[i++]=cmdstr.str();
    if (optHelp)
        argv[i++]="help";
    for (; !iter.done(); iter.next())
        argv[i++]=iter.query();
    argv[i]=NULL;
//TODO - add common routine or use existing in jlib
    // First try in same dir as the ecl executable
    StringBuffer local;
    splitFilename(queryCurrentProcessPath(), &local, &local, NULL, NULL);
    local.append(cmdstr);
    errno = 0;
#ifdef _WIN32
    if (_spawnvp(_P_WAIT, local.str(), const_cast<char **>(argv))==-1)
        return 0;
    // If not found, try the path
    if (errno!=ENOENT || _spawnvp(_P_WAIT, cmdstr.str(), const_cast<char **>(argv))==-1)
#else
    if (execvp(local.str(), const_cast<char **>(argv))!=-1)
        return 0;
    // If not found, try the path
    if (errno!=ENOENT || execvp(cmdstr.str(), const_cast<char **>(argv))==-1)
#endif
    {
        switch(errno)
        {
        case ENOENT:
            fprintf(stderr, "ecl '%s' command not found\n", cmd.str());
            return 1;
        default:
            fprintf(stderr, "ecl '%s' command error %d\n", cmd.str(), errno);
            return 1;
        }
    }
    return 0;
}
Exemplo n.º 2
0
    bool compile(const char *wuid, const char *target, const char *targetCluster)
    {
        Owned<IConstWUQuery> query = workunit->getQuery();
        if (!query)
        {
            reportError("Workunit does not contain a query", 2);
            return false;
        }

        addTimeStamp(workunit, SSTglobal, NULL, StWhenCompiled);

        SCMStringBuffer mainDefinition;
        SCMStringBuffer eclQuery;
        query->getQueryText(eclQuery);
        query->getQueryMainDefinition(mainDefinition);

        StringBuffer eclccProgName;
        splitDirTail(queryCurrentProcessPath(), eclccProgName);
        eclccProgName.append("eclcc");
        StringBuffer eclccCmd(" -shared");
        if (eclQuery.length())
            eclccCmd.append(" -");
        if (mainDefinition.length())
            eclccCmd.append(" -main ").append(mainDefinition);
        eclccCmd.append(" --timings --xml");
        eclccCmd.append(" --nostdinc");
        if (globals->getPropBool("@enableEclccDali", true))
        {
            const char *daliServers = globals->queryProp("@daliServers");
            if (!daliServers)
                daliServers = ".";
            eclccCmd.appendf(" -dfs=%s", daliServers);
            const char *wuScope = workunit->queryWuScope();
            if (!isEmptyString(wuScope))
                eclccCmd.appendf(" -scope=%s", wuScope);
            eclccCmd.appendf(" -cluster=%s", targetCluster);
            SCMStringBuffer token;
            workunit->getSecurityToken(token);
            if (token.length())
                eclccCmd.appendf(" -wuid=%s -token=%s", workunit->queryWuid(), token.str());
        }
        Owned<IPipeProcess> pipe = createPipeProcess();
        pipe->setenv("ECLCCSERVER_THREAD_INDEX", idxStr.str());
        Owned<IPropertyTreeIterator> options = globals->getElements("./Option");
        ForEach(*options)
        {
            IPropertyTree &option = options->query();
            const char *name = option.queryProp("@name");
            const char *value = option.queryProp("@value");
            const char *cluster = option.queryProp("@cluster");                // if cluster is set it's specific to a particular target
            if (name && (cluster==NULL || cluster[0]==0 || strcmp(cluster, targetCluster)==0))
                processOption(name, value, eclccCmd, eclccProgName, *pipe, false);
        }
        eclccCmd.appendf(" -o%s", wuid);
        eclccCmd.appendf(" -platform=%s", target);
        eclccCmd.appendf(" --component=%s", queryStatisticsComponentName());

        Owned<IStringIterator> debugValues = &workunit->getDebugValues();
        ForEach (*debugValues)
        {
            SCMStringBuffer debugStr, valueStr;
            debugValues->str(debugStr);
            workunit->getDebugValue(debugStr.str(), valueStr);
            processOption(debugStr.str(), valueStr.str(), eclccCmd, eclccProgName, *pipe, true);
        }
        if (workunit->getResultLimit())
        {
            eclccCmd.appendf(" -fapplyInstantEclTransformations=1 -fapplyInstantEclTransformationsLimit=%u", workunit->getResultLimit());
        }
        try
        {
            cycle_t startCycles = get_cycles_now();
            Owned<ErrorReader> errorReader = new ErrorReader(pipe, this);
            Owned<AbortWaiter> abortWaiter = new AbortWaiter(pipe, workunit);
            eclccCmd.insert(0, eclccProgName);
            if (!pipe->run(eclccProgName, eclccCmd, ".", true, false, true, 0, true))
                throw makeStringExceptionV(999, "Failed to run eclcc command %s", eclccCmd.str());
            errorReader->start();
            abortWaiter->start();
            try
            {
                pipe->write(eclQuery.s.length(), eclQuery.s.str());
                pipe->closeInput();
            }
            catch (IException *e)
            {
                reportError(e);
                e->Release();
            }
            unsigned retcode = pipe->wait();
            errorReader->join();
            abortWaiter->stop();
            if (retcode == 0)
            {
                StringBuffer realdllname, dllurl;
                realdllname.append(SharedObjectPrefix).append(wuid).append(SharedObjectExtension);

                StringBuffer realdllfilename(dllPath);
                realdllfilename.append(SharedObjectPrefix).append(wuid).append(SharedObjectExtension);

                StringBuffer wuXML;
                if (!getWorkunitXMLFromFile(realdllfilename, wuXML))
                    throw makeStringException(999, "Failed to extract workunit from query dll");

                Owned<ILocalWorkUnit> embeddedWU = createLocalWorkUnit(wuXML);
                queryExtendedWU(workunit)->copyWorkUnit(embeddedWU, false, true);
                workunit->setIsClone(false);
                const char *jobname = embeddedWU->queryJobName();
                if (jobname && *jobname) //let ECL win naming job during initial compile
                    workunit->setJobName(jobname);
                if (!workunit->getDebugValueBool("obfuscateOutput", false))
                {
                    Owned<IWUQuery> query = workunit->updateQuery();
                    query->setQueryText(eclQuery.s.str());
                }

                createUNCFilename(realdllfilename.str(), dllurl);
                unsigned crc = crc_file(realdllfilename.str());

                Owned<IWUQuery> query = workunit->updateQuery();
                associateLocalFile(query, FileTypeDll, realdllfilename, "Workunit DLL", crc);
                queryDllServer().registerDll(realdllname.str(), "Workunit DLL", dllurl.str());

                cycle_t elapsedCycles = get_cycles_now() - startCycles;
                updateWorkunitTimeStat(workunit, SSTcompilestage, "compile", StTimeElapsed, NULL, cycle_to_nanosec(elapsedCycles));

                workunit->commit();
                return true;
            }
        }
        catch (IException * e)
        {
            reportError(e);
            e->Release();
        }
        return false;
    }
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
    //
    // Build the default directory for the schema files
    std::string processPath(queryCurrentProcessPath());
    configSchemaDir = processPath.substr(0, processPath.find_last_of(PATHSEPSTR)) + PATHSEPSTR + configSchemaRelativeDir;

    if (argc == 1)
    {
        usage();
        return 0;
    }

    //
    // Read options and validate
    if (!processOptions(argc, argv))
    {
        return 1;   // get out now
    }

    if (!validate())
    {
        usage();
        return 1;
    }

    //
    // Create an environment manager reference and load the schema
    try
    {
        pEnvMgr = getEnvironmentMgrInstance(envType);
        std::cout << "Loading schema defined by " << masterSchemaFile << "...";

        // note that these are hardcoded for HPCC at this time, but could be made into options
        std::map<std::string, std::string> cfgParms;
        cfgParms["buildset"] = "buildset.xml";  // Not used right now, and probably never will be
        cfgParms["support_libs"] = "libcfgsupport_addrequiredinstances";
        std::string pluginsPath = configSchemaPluginsDir;

        if (!pEnvMgr->loadSchema(configSchemaDir, masterSchemaFile, cfgParms))
        {
            throw CliException(pEnvMgr->getLastSchemaMessage());
        }
    }
    catch (const ParseException &pe)
    {
        std::cout << "There was a problem creating the environment manager instance: " << pe.what() << std::endl;
    }
    catch(const CliException &e)
    {
        std::cout << "There was a problem loading the schema: " << e.what() << std::endl;
    }


    //
    // Create the modification template
    try
    {
        pTemplate = new EnvModTemplate(pEnvMgr, modTemplateSchemaFile);
        pTemplate->loadTemplateFromFile(modTemplateFile);
    }
    catch (const TemplateException &te)
    {
        std::cout << "There was a problem loading the modification template: " << te.what() << std::endl;
        return 1;
    }

    //
    // If list inputs was given, list them and get out
    if (listInputs)
    {
        std::cout << "Template inputs:" << std::endl;
        auto templateInputs = pTemplate->getVariables();
        for (auto &pInput : templateInputs)
        {
            std::cout << pInput->getName() << " - " << pInput->getDescription() << std::endl;
        }
        return 0;  // get out
    }

    //
    // Process the input file if given here

    //
    // If the user provided any inputs, assign them
    if (!userInputs.empty())
    {
        for (auto &userInput: userInputs)
        {
            try
            {
                auto pInput = pTemplate->getVariable(userInput.inputName);
                auto values = splitString(userInput.inputValue, ",");
                for (auto &value: values)
                {
                    pInput->addValue(value);
                }
            }
            catch (const TemplateException &te)
            {
                std::cout << "There was a problem: " << te.what() << std::endl;
                return 0;  // get out
            }
        }
    }

    //
    // If there is an environment, load it and apply
    if (!envFile.empty())
    {
        if (!pEnvMgr->loadEnvironment(envFile))
        {
            std::cout << "There was a problem loading the environment: " << std::endl << pEnvMgr->getLastEnvironmentMessage() << std::endl;
            return 1;
        }

        try
        {
            pTemplate->execute();
        }
        catch (const TemplateExecutionException &te)
        {
            std::cout << te.what() << std::endl;
            return 1;
        }

        //
        // Write results
        if (!envOutputFile.empty())
        {
            pEnvMgr->saveEnvironment(envOutputFile);
            std::cout << "Results written to " << envOutputFile << std::endl;
        }
        else
        {
            std::cout << "Resuls not saved." << std::endl;
        }
    }
    else
    {
        std::cout << "No problems found in the modification template" << std::endl;
    }

    std::cout << "Done" << std::endl;
    return 0;
}