Example #1
0
//--------------------------------------------------------------------------------------------------
void Generate
(
    const model::Exe_t* exePtr,
    const mk::BuildParams_t& buildParams,
    int argc,           ///< Count of the number of command line parameters.
    const char** argv   ///< Pointer to array of pointers to command line argument strings.
)
//--------------------------------------------------------------------------------------------------
{
    std::string filePath = path::Minimize(buildParams.workingDir + "/build.ninja");

    std::ofstream script;
    OpenFile(script, filePath, buildParams.beVerbose);

    // Start the script with a comment, the file-level variable definitions, and
    // a set of generic rules.
    GenerateCommentHeader(script, exePtr);
    std::string includes;
    for (const auto& dir : buildParams.interfaceDirs)
    {
        includes += " -I" + dir;
    }
    script << "builddir = " << buildParams.workingDir << "\n\n";
    script << "cFlags = " << buildParams.cFlags << includes << "\n\n";
    script << "cxxFlags = " << buildParams.cxxFlags << includes << "\n\n";
    script << "ldFlags = " << buildParams.ldFlags << "\n\n";
    GenerateIfgenFlagsDef(script, buildParams.interfaceDirs);
    GenerateBuildRules(script, buildParams.target, argc, argv);

    if (!buildParams.codeGenOnly)
    {
        // Add build statements for the executable and .o files included in it.
        GenerateBuildStatements(script, exePtr, buildParams);

        // Add build statements for all the components included in this executable.
        for (auto componentInstancePtr : exePtr->componentInstances)
        {
            GenerateBuildStatements(script, componentInstancePtr->componentPtr, buildParams);
        }
    }

    // Add build statements for all the IPC interfaces' generated files.
    GenerateIpcBuildStatements(script, exePtr, buildParams);

    // Add a build statement for the build.ninja file itself.
    GenerateNinjaScriptBuildStatement(script, exePtr, filePath);

    CloseFile(script);
}
Example #2
0
//--------------------------------------------------------------------------------------------------
void Generate
(
    const model::App_t* appPtr,
    const mk::BuildParams_t& buildParams,
    const std::string& outputDir,   ///< Path to the directory into which the built app will be put.
    int argc,           ///< Count of the number of command line parameters.
    const char** argv   ///< Pointer to array of pointers to command line argument strings.
)
//--------------------------------------------------------------------------------------------------
{
    std::string filePath = path::Minimize(buildParams.workingDir + "/build.ninja");

    std::ofstream script;
    OpenFile(script, filePath, buildParams.beVerbose);

    // Start the script with a comment, the file-level variable definitions, and
    // a set of generic rules.
    GenerateCommentHeader(script, appPtr);
    std::string includes;
    for (const auto& dir : buildParams.interfaceDirs)
    {
        includes += " -I" + dir;
    }
    script << "builddir =" << buildParams.workingDir << "\n\n";
    script << "cFlags =" << buildParams.cFlags << includes << "\n\n";
    script << "cxxFlags =" << buildParams.cxxFlags << includes << "\n\n";
    script << "ldFlags =" << buildParams.ldFlags << "\n\n";
    script << "target = " << buildParams.target << "\n\n";
    GenerateIfgenFlagsDef(script, buildParams.interfaceDirs);
    GenerateBuildRules(script, buildParams.target, argc, argv);
    GenerateAppBuildRules(script);

    // If we are not just generating code,
    if (!buildParams.codeGenOnly)
    {
        // For each component included in executables in this application.
        for (auto componentPtr : appPtr->components)
        {
            GenerateBuildStatements(script, componentPtr, buildParams);
        }

        // For each executable built by the mk tools for this application,
        GenerateExeBuildStatements(script, appPtr, buildParams);

        // Generate build statement for packing everything into an application bundle.
        GenerateAppBundleBuildStatement(script, appPtr, buildParams, outputDir);
    }

    // Add build statements for all the IPC interfaces' generated files.
    GenerateIpcBuildStatements(script, buildParams);

    // Add a build statement for the build.ninja file itself.
    GenerateNinjaScriptBuildStatement(script, appPtr, filePath);

    CloseFile(script);
}
Example #3
0
//--------------------------------------------------------------------------------------------------
void GenerateExeBuildStatements
(
    std::ofstream& script,      ///< Ninja script to write rules to.
    const model::App_t* appPtr,
    const mk::BuildParams_t& buildParams
)
//--------------------------------------------------------------------------------------------------
{
    for (auto mapItem : appPtr->executables)
    {
        GenerateBuildStatements(script, mapItem.second, buildParams);
    }
}
//--------------------------------------------------------------------------------------------------
static void GenerateSubComponentBuildStatements
(
    std::ofstream& script,
    const model::Component_t* componentPtr,
    const mk::BuildParams_t& buildParams
)
//--------------------------------------------------------------------------------------------------
{
    // It's possible that multiple components will share the same sub-component.
    // To prevent the generation of multiple build statements (which would cause ninja to fail),
    // we use a set containing the component names to keep track of what build statements we've
    // already generated.

    std::set<std::string> generatedSet;

    // Use a lambda to recursively descend through the tree of sub-components.

    std::function<void(const model::Component_t* componentPtr)> generate =
        [&script, &generatedSet, &buildParams, &generate]
        (
            const model::Component_t* componentPtr
        )
        {
            if (generatedSet.find(componentPtr->name) == generatedSet.end())
            {
                generatedSet.insert(componentPtr->name);

                GenerateBuildStatements(script, componentPtr, buildParams);

                for (auto subComponentPtr : componentPtr->subComponents)
                {
                    generate(subComponentPtr);
                }
            }
        };

    for (auto subComponentPtr : componentPtr->subComponents)
    {
        generate(subComponentPtr);
    }
}