Ejemplo n.º 1
0
//--------------------------------------------------------------------------------------------------
void ApplicationBuilder_t::Build
(
    legato::App& app,
    std::string outputDirPath   ///< Directory into which the generated app bundle should be put.
)
//--------------------------------------------------------------------------------------------------
{
    CheckForLimitsConflicts(app);

    // Construct the working directory structure, which consists of an "work" directory and
    // a "staging" directory.  Inside the "staging" directory, there is "lib", "bin", and any
    // other directories required to hold files bundled by the application or one of its components.
    // The "work" directory is for intermediate build output, like generated .c files and .o files.
    // The "staging" directory will get tar-compressed to become the actual application file.

    if (m_Params.IsVerbose())
    {
        std::cout << "Creating working directories under '" << m_Params.ObjOutputDir() << "'."
                  << std::endl;
    }

    legato::BuildParams_t buildParams(m_Params);

    const std::string& stagingDirPath = m_Params.StagingDir();
    buildParams.LibOutputDir(stagingDirPath + "/lib");
    buildParams.ExeOutputDir(stagingDirPath + "/bin");
    buildParams.ObjOutputDir(m_Params.ObjOutputDir() + "/work");

    // Clean the staging area.
    legato::CleanDir(stagingDirPath);

    // Create directories.
    legato::MakeDir(buildParams.ObjOutputDir());
    legato::MakeDir(buildParams.LibOutputDir());
    legato::MakeDir(buildParams.ExeOutputDir());

    // Build all the components in the application, each with its own working directory
    // to avoid file name conflicts between .o files in different components, and copy all
    // generated and bundled files into the application staging area.
    // NOTE: Components have to be built before any other components that depend on them.
    //       They also need to be bundled into the app in the same order, so that higher-layer
    //       components can override files bundled by lower-layer components.
    ComponentBuilder_t componentBuilder(buildParams);
    auto& map = app.ComponentMap();
    for (auto& mapEntry : map)
    {
        auto& componentPtr = mapEntry.second;

        BuildAndBundleComponent(*componentPtr, componentBuilder, buildParams.ObjOutputDir());
    }

    // Build all the executables and their IPC libs.
    BuildExecutables(app, buildParams);

    // Copy in any bundled files and directories from the "bundles:" section of the .adef.
    // Note: do the directories first, in case the files list adds files to those directories.
    for (auto& fileMapping : app.BundledDirs())
    {
        mk::CopyToStaging(  fileMapping.m_SourcePath,
                            stagingDirPath,
                            fileMapping.m_DestPath,
                            m_Params.IsVerbose()    );
    }
    for (auto& fileMapping : app.BundledFiles())
    {
        mk::CopyToStaging(  fileMapping.m_SourcePath,
                            stagingDirPath,
                            fileMapping.m_DestPath,
                            m_Params.IsVerbose()    );
    }

    // Generate the app-specific configuration data that tells the framework what limits to place
    // on the app when it is run, etc.
    GenerateSystemConfig(stagingDirPath, app, m_Params);

    // TODO: Generate the application's configuration tree (containing all its pool sizes,
    //       and anything else listed under the "config:" section of the .adef.)

    // TODO: Copy in the metadata (.adef and Component.cdef) files so they can be retrieved
    //       by Developer Studio.

    // Zip it all up.
    std::string outputPath = legato::CombinePath(   outputDirPath,
                                                    app.Name() + "." + buildParams.Target() );
    if (!legato::IsAbsolutePath(outputPath))
    {
        outputPath = legato::GetWorkingDir() + "/" + outputPath;
    }
    std::string tarCommandLine = "tar cjf \"" + outputPath + "\" -C \"" + stagingDirPath + "\" .";
    if (m_Params.IsVerbose())
    {
        std::cout << "Packaging application into '" << outputPath << "'." << std::endl;
        std::cout << std::endl << "$ " << tarCommandLine << std::endl << std::endl;
    }

    mk::ExecuteCommandLine(tarCommandLine);
}
Ejemplo n.º 2
0
//--------------------------------------------------------------------------------------------------
static void Build
(
    void
)
//--------------------------------------------------------------------------------------------------
{
    // Construct the working directory structure, which consists of an "obj" directory and
    // a "staging" directory.  Application bundles will be put inside the "staging" directory.
    // The "staging" directory will get tarred to become the actual system bundle.
    // The "obj" directory is for intermediate build output, like generated .c
    // files and .o files.  Under the "obj" directory each app has its own subdirectory to work in.
    if (BuildParams.IsVerbose())
    {
        std::cout << "Creating working directories under '" << BuildParams.ObjOutputDir() << "'."
                  << std::endl;
    }
    std::string objDirPath = BuildParams.ObjOutputDir() + "/obj";
    std::string stagingDirPath = BuildParams.ObjOutputDir() + "/staging";

    // Clean the staging area.
    legato::CleanDir(stagingDirPath);

    // Create the staging and working directories.
    legato::MakeDir(objDirPath);
    legato::MakeDir(stagingDirPath);

    // For each app in the system,
    for (auto& mapEntry : System.Apps())
    {
        auto& app = mapEntry.second;

        // Create an Application Builder object to use to build this app.
        // Give it the appropriate build parameters.
        legato::BuildParams_t appBuildParams(BuildParams);
        appBuildParams.ObjOutputDir(legato::CombinePath(objDirPath, app.Name()));
        appBuildParams.StagingDir(legato::CombinePath(appBuildParams.ObjOutputDir(), "staging"));
        ApplicationBuilder_t appBuilder(appBuildParams);

        // Build the app.  This should result in an application bundle appearing in the
        // staging directory.
        appBuilder.Build(app, stagingDirPath);
    }

    // TODO: Copy in metadata for use by Developer Studio.

    // Generate a configuration data file containing user-to-app and user-to-user bindings.
    GenerateSystemConfig(stagingDirPath);

    // Create the tarball file name.
    std::string outputPath = legato::CombinePath(OutputDir, System.Name());
    outputPath += "." + BuildParams.Target() + "_sys";  // Add the file name extension.
    if (!legato::IsAbsolutePath(outputPath))
    {
        outputPath = legato::GetWorkingDir() + "/" + outputPath;
    }

    // Create the tarball.
    std::string tarCommandLine = "tar cf \"" + outputPath + "\" -C \"" + stagingDirPath + "\" .";
    if (BuildParams.IsVerbose())
    {
        std::cout << "Packaging system into '" << outputPath << "'." << std::endl;
        std::cout << std::endl << "$ "<< tarCommandLine << std::endl << std::endl;
    }
    mk::ExecuteCommandLine(tarCommandLine);
}