AppleOpenSource/dyld-750.6/dyld3/shared-cache/SharedCacheBuilder.cpp
// This is the new build API which takes the raw files (which could be FAT) and tries to build a cache from them.
// We should remove the other build() method, or make it private so that this can wrap it.
This is the new build API which takes the raw files (which could be FAT) and tries to build a cache from them.
We should remove the other build() method, or make it private so that this can wrap it.
This is the new build API which takes the raw files ( which could be FAT ) and tries to build a cache from them . We should remove the other build () method or make it private so that this can wrap it .
void SharedCacheBuilder::build(std::vector<CacheBuilder::InputFile>& inputFiles,
                               std::vector<DyldSharedCache::FileAlias>& aliases) {
    CacheInputBuilder cacheInputBuilder(_fileSystem, *_options.archs, _options.platform);
    std::vector<LoadedMachO> dylibsToCache;
    std::vector<LoadedMachO> otherDylibs;
    std::vector<LoadedMachO> executables;
    std::vector<LoadedMachO> couldNotLoadFiles;
    cacheInputBuilder.loadMachOs(inputFiles, dylibsToCache, otherDylibs, executables, couldNotLoadFiles);
    verifySelfContained(dylibsToCache, otherDylibs, couldNotLoadFiles);
    if (!_diagnostics.hasError()) {
        std::string errorString;
        for (const LoadedMachO& dylib : otherDylibs) {
            if (dylib.inputFile->mustBeIncluded()) {
                bool gotWarning = false;
                for (const std::string& warning : dylib.inputFile->diag.warnings()) {
                    gotWarning = true;
                    std::string message = warning;
                    if (message.back() == '\n')
                        message.pop_back();
                    if (!errorString.empty())
                        errorString += "ERROR: ";
                    errorString += "Required binary was not included in the shared cache '" + std::string(dylib.inputFile->path) + "' because: " + message + "\n";
                }
                if (!gotWarning) {
                    if (!errorString.empty())
                        errorString += "ERROR: ";
                    errorString += "Required binary was not included in the shared cache '" + std::string(dylib.inputFile->path) + "' because: 'unknown error.  Please report to dyld'\n";
                }
            }
        }
        for (const LoadedMachO& dylib : couldNotLoadFiles) {
            if (dylib.inputFile->mustBeIncluded()) {
                if (dylib.inputFile->diag.hasError()) {
                    if (!errorString.empty())
                        errorString += "ERROR: ";
                    errorString += "Required binary was not included in the shared cache '" + std::string(dylib.inputFile->path) + "' because: " + dylib.inputFile->diag.errorMessage() + "\n";
                } else {
                    if (!errorString.empty())
                        errorString += "ERROR: ";
                    errorString += "Required binary was not included in the shared cache '" + std::string(dylib.inputFile->path) + "' because: 'unknown error.  Please report to dyld'\n";
                }
            }
        }
        if (!errorString.empty()) {
            _diagnostics.error("%s", errorString.c_str());
        }
    }
    if (!_diagnostics.hasError())
        build(dylibsToCache, otherDylibs, executables, aliases);
    if (!_diagnostics.hasError()) {
        std::string errorString;
        for (CacheBuilder::InputFile& inputFile : inputFiles) {
            if (inputFile.mustBeIncluded() && inputFile.diag.hasError()) {
                std::string message = inputFile.diag.errorMessage();
                if (message.back() == '\n')
                    message.pop_back();
                errorString += "Required binary was not included in the shared cache '" + std::string(inputFile.path) + "' because: " + message + "\n";
            }
        }
        if (!errorString.empty()) {
            _diagnostics.error("%s", errorString.c_str());
        }
    }
    for (CacheBuilder::InputFile& inputFile : inputFiles) {
        for (const std::string& warning : inputFile.diag.warnings())
            _diagnostics.warning("%s", warning.c_str());
    }
    for (LoadedMachO& loadedMachO : dylibsToCache)
        _fileSystem.unloadFile(loadedMachO.loadedFileInfo);
    for (LoadedMachO& loadedMachO : otherDylibs)
        _fileSystem.unloadFile(loadedMachO.loadedFileInfo);
    for (LoadedMachO& loadedMachO : executables)
        _fileSystem.unloadFile(loadedMachO.loadedFileInfo);
}
void SharedCacheBuilder :: build ( std :: vector < CacheBuilder :: InputFile > & inputFiles , std :: vector < DyldSharedCache :: FileAlias > & aliases ) { CacheInputBuilder cacheInputBuilder ( _fileSystem , * _options . archs , _options . platform ) ; std :: vector < LoadedMachO > dylibsToCache ; std :: vector < LoadedMachO > otherDylibs ; std :: vector < LoadedMachO > executables ; std :: vector < LoadedMachO > couldNotLoadFiles ; cacheInputBuilder . loadMachOs ( inputFiles , dylibsToCache , otherDylibs , executables , couldNotLoadFiles ) ; verifySelfContained ( dylibsToCache , otherDylibs , couldNotLoadFiles ) ; if ( ! _diagnostics . hasError ( ) ) { std :: string errorString ; for ( const LoadedMachO & dylib : otherDylibs ) { if ( dylib . inputFile -> mustBeIncluded ( ) ) { bool gotWarning = false ; for ( const std :: string & warning : dylib . inputFile -> diag . warnings ( ) ) { gotWarning = true ; std :: string message = warning ; if ( message . back ( ) == ' \n ' ) message . pop_back ( ) ; if ( ! errorString . empty ( ) ) errorString += " " ; errorString += " " + std :: string ( dylib . inputFile -> path ) + " " + message + " \n " ; } if ( ! gotWarning ) { if ( ! errorString . empty ( ) ) errorString += " " ; errorString += " " + std :: string ( dylib . inputFile -> path ) + " \n " ; } } } for ( const LoadedMachO & dylib : couldNotLoadFiles ) { if ( dylib . inputFile -> mustBeIncluded ( ) ) { if ( dylib . inputFile -> diag . hasError ( ) ) { if ( ! errorString . empty ( ) ) errorString += " " ; errorString += " " + std :: string ( dylib . inputFile -> path ) + " " + dylib . inputFile -> diag . errorMessage ( ) + " \n " ; } else { if ( ! errorString . empty ( ) ) errorString += " " ; errorString += " " + std :: string ( dylib . inputFile -> path ) + " \n " ; } } } if ( ! errorString . empty ( ) ) { _diagnostics . error ( " " , errorString . c_str ( ) ) ; } } if ( ! _diagnostics . hasError ( ) ) build ( dylibsToCache , otherDylibs , executables , aliases ) ; if ( ! _diagnostics . hasError ( ) ) { std :: string errorString ; for ( CacheBuilder :: InputFile & inputFile : inputFiles ) { if ( inputFile . mustBeIncluded ( ) && inputFile . diag . hasError ( ) ) { std :: string message = inputFile . diag . errorMessage ( ) ; if ( message . back ( ) == ' \n ' ) message . pop_back ( ) ; errorString += " " + std :: string ( inputFile . path ) + " " + message + " \n " ; } } if ( ! errorString . empty ( ) ) { _diagnostics . error ( " " , errorString . c_str ( ) ) ; } } for ( CacheBuilder :: InputFile & inputFile : inputFiles ) { for ( const std :: string & warning : inputFile . diag . warnings ( ) ) _diagnostics . warning ( " " , warning . c_str ( ) ) ; } for ( LoadedMachO & loadedMachO : dylibsToCache ) _fileSystem . unloadFile ( loadedMachO . loadedFileInfo ) ; for ( LoadedMachO & loadedMachO : otherDylibs ) _fileSystem . unloadFile ( loadedMachO . loadedFileInfo ) ; for ( LoadedMachO & loadedMachO : executables ) _fileSystem . unloadFile ( loadedMachO . loadedFileInfo ) ; }
This is the new build API which takes the raw files (which could be FAT) and tries to build a cache from them.
This is the new build API which takes the raw files ( which could be FAT ) and tries to build a cache from them .
// First filter down to files which are actually MachO's // Check for required binaries before we try to build the cache // If we succeeded in building, then now see if there was a missing required file, and if so why its missing. // An error loading a required file must be propagated up to the top level diagnostic handler. // If we succeeded in building, then now see if there was a missing required file, and if so why its missing. // An error loading a required file must be propagated up to the top level diagnostic handler. // Add all the warnings from the input files to the top level warnings on the main diagnostics object. // Clean up the loaded files