Ticket #12917: repository_rework_squash.diff

File repository_rework_squash.diff, 19.3 KB (added by kallisti5, 3 years ago)

complete squashed repo work rev2

  • build/jam/ImageRules

    diff --git a/build/jam/ImageRules b/build/jam/ImageRules
    index c018470..3141d70 100644
    a b rule AddPackagesAndRepositoryVariablesToContainerScript script : container  
    901901    local repositoryFiles ;
    902902    for repository in $(HAIKU_REPOSITORIES) {
    903903        repositoryFiles
    904             += [ on $(repository) return $(HAIKU_REPOSITORY_CACHE_FILE) ] ;
     904            += [ on $(repository) return $(HAIKU_REPOSITORY_CONFIG_FILE) ] ;
    905905    }
    906906
    907907    AddTargetVariableToScript $(script) : $(repositoryFiles) : repositories ;
  • build/jam/RepositoryRules

    diff --git a/build/jam/RepositoryRules b/build/jam/RepositoryRules
    index fb91089..9290f2f 100644
    a b actions BuildRemoteHaikuPortsRepository1  
    761761}
    762762
    763763
    764 rule HaikuRepository repository : repoInfoTemplate : packages
     764rule HaikuRepository repository : repoInfoTemplate : packages : url
    765765{
    766     # HaikuRepository <repository> : <repoInfoTemplate> : <packages>
    767     #   [ : <url> [ : <versionFile> ] ] ;
     766    # HaikuRepository <repository> : <repoInfoTemplate> : <packages> : <url>
     767    #   [ : <versionFile> ] ;
    768768    # Builds the Haiku repository from the given packages and repository info
    769769    # template. <repository> must already be located.
    770770    #
    rule HaikuRepository repository : repoInfoTemplate : packages  
    773773    #   meta data files.
    774774    # <repoInfoTemplate> - The repository info template file to be used.
    775775    # <packages> - The packages to be added to the repository.
     776    # <url> - The remote location of the initial update repository
    776777
    777778    local architecture = $(HAIKU_PACKAGING_ARCH) ;
    778779    local secondaryArchitecture ;
    rule HaikuRepository repository : repoInfoTemplate : packages  
    791792    # build the respository config
    792793    local repositoryConfig = $(repository:G=repository-config)-config ;
    793794    MakeLocate $(repositoryConfig) : $(repositoriesDir) ;
    794     RepositoryConfig $(repositoryConfig) : $(repositoryInfo) ;
     795    RepositoryConfig $(repositoryConfig) : $(repositoryInfo) : $(url) ;
    795796    HAIKU_REPOSITORY_CONFIG_FILE on $(repository) = $(repositoryConfig) ;
    796797
    797798    # setup the repository cache file
  • build/jam/repositories/Haiku

    diff --git a/build/jam/repositories/Haiku b/build/jam/repositories/Haiku
    index 14f5ebe..1e2f0b1 100644
    a b if $(webPositiveIsAvailable) {  
    5252    packages += webpositive ;
    5353}
    5454
    55 HaikuRepository $(haikuRepository) : $(repoInfo) : $(packages:S=.hpkg) ;
     55local version = current ;
     56#local version = $(HAIKU_VERSION) ;
     57local remoteURL = http://packages.haiku-os.org/haiku/master/$(HAIKU_PACKAGING_ARCH)/$(version) ;
     58
     59HaikuRepository $(haikuRepository) : $(repoInfo) : $(packages:S=.hpkg) : $(remoteURL) ;
  • build/scripts/build_haiku_image

    diff --git a/build/scripts/build_haiku_image b/build/scripts/build_haiku_image
    index 28ab709..7554e0a 100755
    a b set -o errexit  
    77# tmpDir
    88# addBuildCompatibilityLibDir
    99# systemPackages - lists of the hpkg packages copied/updated
    10 # repositories - all repository files
     10# repositories - all repository configuration files
    1111# downloadDir
    1212# The following are only for image types:
    1313# installDir
  • headers/os/package/RepositoryInfo.h

    diff --git a/headers/os/package/RepositoryInfo.h b/headers/os/package/RepositoryInfo.h
    index 32aa05d..513539c 100644
    a b public:  
    3333            status_t            InitCheck() const;
    3434
    3535            const BString&      Name() const;
    36             const BString&      OriginalBaseURL() const;
    3736            const BString&      Vendor() const;
    3837            const BString&      Summary() const;
    3938            uint8               Priority() const;
    public:  
    4241            const BStringList&  LicenseTexts() const;
    4342
    4443            void                SetName(const BString& name);
    45             void                SetOriginalBaseURL(const BString& url);
    4644            void                SetVendor(const BString& vendor);
    4745            void                SetSummary(const BString& summary);
    4846            void                SetPriority(uint8 priority);
    public:  
    5755
    5856    static  const uint8         kDefaultPriority;
    5957
     58    // XXX: Kill me after everyone upgrades
     59    static  const char* const   kURLField;
     60
    6061    static  const char* const   kNameField;
    61     static  const char* const   kURLField;
    6262    static  const char* const   kVendorField;
    6363    static  const char* const   kSummaryField;
    6464    static  const char* const   kPriorityField;
    private:  
    7474            status_t            fInitStatus;
    7575
    7676            BString             fName;
    77             BString             fOriginalBaseURL;
    7877            BString             fVendor;
    7978            BString             fSummary;
    8079            uint8               fPriority;
  • src/bin/package_repo/command_list.cpp

    diff --git a/src/bin/package_repo/command_list.cpp b/src/bin/package_repo/command_list.cpp
    index c2dcd12..54d223d 100644
    a b struct RepositoryContentListHandler : BRepositoryContentHandler {  
    6969        printf("repository-info:\n");
    7070        printf("\tname: %s\n", repositoryInfo.Name().String());
    7171        printf("\tsummary: %s\n", repositoryInfo.Summary().String());
    72         printf("\turl: %s\n", repositoryInfo.OriginalBaseURL().String());
    7372        printf("\tvendor: %s\n", repositoryInfo.Vendor().String());
    7473        printf("\tpriority: %u\n", repositoryInfo.Priority());
    7574        printf("\tarchitecture: %s\n",
  • src/bin/pkgman/command_list_repos.cpp

    diff --git a/src/bin/pkgman/command_list_repos.cpp b/src/bin/pkgman/command_list_repos.cpp
    index 677983a..c7a26cc 100644
    a b ListReposCommand::Execute(int argc, const char* const* argv)  
    118118                        repoCache.Info().Architecture()]);
    119119                printf("\t\tpkg-count: %" B_PRIu32 "\n",
    120120                    repoCache.CountPackages());
    121                 printf("\t\torig-url:  %s\n",
    122                     repoCache.Info().OriginalBaseURL().String());
    123121                printf("\t\torig-prio: %u\n", repoCache.Info().Priority());
    124122            } else
    125123                printf("\t\t<no repository cache found>\n");
  • src/data/repository_infos/haiku

    diff --git a/src/data/repository_infos/haiku b/src/data/repository_infos/haiku
    index a6501ab..1c1a558 100644
    a b name Haiku  
    22vendor "Haiku Project"
    33summary "The Haiku repository (for Haiku %HAIKU_VERSION_NO_REVISION%)"
    44priority 1
    5 url http://packages.haiku-os.org/haiku/master/%HAIKU_PACKAGING_ARCH%/%HAIKU_VERSION_NO_REVISION%
    65architecture %HAIKU_PACKAGING_ARCH%
  • src/data/repository_infos/haikuports

    diff --git a/src/data/repository_infos/haikuports b/src/data/repository_infos/haikuports
    index 3c62733..bb62321 100644
    a b name HaikuPorts  
    22vendor "Haiku Project"
    33summary "The HaikuPorts repository (for Haiku %HAIKU_VERSION_NO_REVISION%)"
    44priority 1
    5 url http://packages.haiku-os.org/haikuports/master/repo/%HAIKU_PACKAGING_ARCH%/dummy
    65architecture %HAIKU_PACKAGING_ARCH%
  • src/kits/package/RepositoryInfo.cpp

    diff --git a/src/kits/package/RepositoryInfo.cpp b/src/kits/package/RepositoryInfo.cpp
    index aaff367..4682854 100644
    a b  
    11/*
    2  * Copyright 2011, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2011-2016, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
    66 *      Oliver Tappe <zooey@hirschkaefer.de>
     7 *      Alexander von Gluck IV <kallisti5@unixzen.com>
    78 */
    89
    910
    namespace BPackageKit {  
    2728const uint8 BRepositoryInfo::kDefaultPriority   = 50;
    2829
    2930const char* const BRepositoryInfo::kNameField           = "name";
    30 const char* const BRepositoryInfo::kURLField            = "url";
    3131const char* const BRepositoryInfo::kVendorField         = "vendor";
    3232const char* const BRepositoryInfo::kSummaryField        = "summary";
    3333const char* const BRepositoryInfo::kPriorityField       = "priority";
    const char* const BRepositoryInfo::kArchitectureField = "architecture";  
    3535const char* const BRepositoryInfo::kLicenseNameField    = "licenseName";
    3636const char* const BRepositoryInfo::kLicenseTextField    = "licenseText";
    3737
     38// XXX: Kill me after everyone upgrades.
     39const char* const BRepositoryInfo::kURLField            = "url";
     40
    3841
    3942BRepositoryInfo::BRepositoryInfo()
    4043    :
    BRepositoryInfo::Archive(BMessage* data, bool deep) const  
    8285    if (result != B_OK)
    8386        return result;
    8487
    85     if ((result = data->AddString(kNameField, fName)) != B_OK)
     88    // XXX: Kill me after everyone upgrades
     89    if ((result = data->AddString(kURLField, "STUB")) != B_OK)
    8690        return result;
    87     if ((result = data->AddString(kURLField, fOriginalBaseURL)) != B_OK)
     91
     92    if ((result = data->AddString(kNameField, fName)) != B_OK)
    8893        return result;
    8994    if ((result = data->AddString(kVendorField, fVendor)) != B_OK)
    9095        return result;
    91     result = data->AddString(kSummaryField, fSummary);
    92     if (result != B_OK)
     96    if ((result = data->AddString(kSummaryField, fSummary)) != B_OK)
    9397        return result;
    9498    if ((result = data->AddUInt8(kPriorityField, fPriority)) != B_OK)
    9599        return result;
    BRepositoryInfo::Name() const  
    139143
    140144
    141145const BString&
    142 BRepositoryInfo::OriginalBaseURL() const
    143 {
    144     return fOriginalBaseURL;
    145 }
    146 
    147 
    148 const BString&
    149146BRepositoryInfo::Vendor() const
    150147{
    151148    return fVendor;
    BRepositoryInfo::SetName(const BString& name)  
    195192
    196193
    197194void
    198 BRepositoryInfo::SetOriginalBaseURL(const BString& url)
    199 {
    200     fOriginalBaseURL = url;
    201 }
    202 
    203 
    204 void
    205195BRepositoryInfo::SetVendor(const BString& vendor)
    206196{
    207197    fVendor = vendor;
    BRepositoryInfo::_SetTo(const BMessage* data)  
    257247    status_t result;
    258248    if ((result = data->FindString(kNameField, &fName)) != B_OK)
    259249        return result;
    260     if ((result = data->FindString(kURLField, &fOriginalBaseURL)) != B_OK)
    261         return result;
    262250    if ((result = data->FindString(kVendorField, &fVendor)) != B_OK)
    263251        return result;
    264252    result = data->FindString(kSummaryField, &fSummary);
    BRepositoryInfo::_SetTo(const BEntry& entry)  
    318306        &unload_driver_settings);
    319307
    320308    const char* name = get_driver_parameter(settingsHandle, "name", NULL, NULL);
    321     const char* url = get_driver_parameter(settingsHandle, "url", NULL, NULL);
    322309    const char* vendor
    323310        = get_driver_parameter(settingsHandle, "vendor", NULL, NULL);
    324311    const char* summary
    BRepositoryInfo::_SetTo(const BEntry& entry)  
    328315    const char* architectureString
    329316        = get_driver_parameter(settingsHandle, "architecture", NULL, NULL);
    330317
    331     if (name == NULL || *name == '\0' || url == NULL || *url == '\0'
     318    if (name == NULL || *name == '\0'
    332319        || vendor == NULL || *vendor == '\0'
    333320        || summary == NULL || *summary == '\0'
    334321        || priorityString == NULL || *priorityString == '\0'
    BRepositoryInfo::_SetTo(const BEntry& entry)  
    343330    }
    344331
    345332    fName = name;
    346     fOriginalBaseURL = url;
    347333    fVendor = vendor;
    348334    fSummary = summary;
    349335    fPriority = atoi(priorityString);
  • src/tools/create_repository_config/create_repository_config.cpp

    diff --git a/src/tools/create_repository_config/create_repository_config.cpp b/src/tools/create_repository_config/create_repository_config.cpp
    index 9837945..549146f 100644
    a b  
    11/*
    2  * Copyright 2013, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2013-2016, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
    66 *      Ingo Weinhold <ingo_weinhold@gmx.de>
     7 *      Alexander von Gluck IV <kallisti5@unixzen.com>
    78 */
    89
    910
    void  
    3738print_usage_and_exit(bool error)
    3839{
    3940    fprintf(error ? stderr : stdout,
    40         "Usage: %s [ <URL> ] <repository info> <repository config>\n"
     41        "Usage: %s <URL> <repository info> <repository config>\n"
    4142        "Creates a repository config file from a given repository info and\n"
    42         "the base URL (the directory in which the \"repo\", \"repo.info\',\n"
    43         "and \"repo.sha256 files can be found). If the URL is not specified,\n"
    44         "the one from the repository info is used.",
     43        "the base URL (the directory in which the 'repo', 'repo.info',\n"
     44        "and 'repo.sha256' files can be found).\n",
    4545        sProgramName);
    4646    exit(error ? 1 : 0);
    4747}
    print_usage_and_exit(bool error)  
    5050int
    5151main(int argc, const char* const* argv)
    5252{
    53     if (argc < 3 || argc > 4) {
     53    if (argc != 4) {
    5454        if (argc == 2
    5555            && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)) {
    5656                print_usage_and_exit(false);
    main(int argc, const char* const* argv)  
    5959    }
    6060
    6161    int argi = 1;
    62     const char* url = argc == 4 ? argv[argi++] : NULL;
     62    const char* url = argv[argi++];
    6363    const char* infoPath = argv[argi++];
    6464    const char* configPath = argv[argi++];
    6565
    main(int argc, const char* const* argv)  
    6868    DIE_ON_ERROR(repoInfo.SetTo(infoPath),
    6969        "failed to read repository info file \"%s\"", infoPath);
    7070
    71     if (url == NULL)
    72         url = repoInfo.OriginalBaseURL();
    73 
    7471    // init and write the config
    7572    BPackageKit::BRepositoryConfig repoConfig;
    7673    repoConfig.SetName(repoInfo.Name());
  • new file src/tools/get_package_dependencies/HTTPClient.cpp

    diff --git a/src/tools/get_package_dependencies/HTTPClient.cpp b/src/tools/get_package_dependencies/HTTPClient.cpp
    new file mode 100644
    index 0000000..2297d4d
    - +  
     1/*
     2 * Copyright 2016, Haiku, Inc. All Rights Reserved.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Authors:
     6 *      Alexander von Gluck IV <kallisti5@unixzen.com>
     7 */
     8
     9
     10#include "HTTPClient.h"
     11
     12#include <File.h>
     13
     14
     15HTTPClient::HTTPClient()
     16    :
     17    fCurl(NULL)
     18{
     19    fCurl = curl_easy_init();
     20    curl_easy_setopt(fCurl, CURLOPT_FOLLOWLOCATION, 1L);
     21    curl_easy_setopt(fCurl, CURLOPT_NOSIGNAL, 1);
     22    curl_easy_setopt(fCurl, CURLOPT_ACCEPT_ENCODING, "deflate");
     23    curl_easy_setopt(fCurl, CURLOPT_WRITEFUNCTION, &_WriteCallback);
     24}
     25
     26
     27HTTPClient::~HTTPClient()
     28{
     29    curl_easy_cleanup(fCurl);
     30}
     31
     32
     33size_t
     34HTTPClient::_WriteCallback(void *buffer, size_t size, size_t nmemb,
     35    void *userp)
     36{
     37    BFile* target = reinterpret_cast<BFile*>(userp);
     38    ssize_t dataWritten = target->Write(buffer, size * nmemb);
     39    return size_t(dataWritten);
     40}
     41
     42
     43status_t
     44HTTPClient::Get(BString* url, BEntry* destination)
     45{
     46    BFile target(destination, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY);
     47
     48    curl_easy_setopt(fCurl, CURLOPT_URL, url->String());
     49    curl_easy_setopt(fCurl, CURLOPT_WRITEDATA, &target);
     50
     51    CURLcode res = curl_easy_perform(fCurl);
     52
     53    // Check result
     54    if (res != CURLE_OK) {
     55        fprintf(stderr, "curl_easy_perform() failed: %s\n",
     56            curl_easy_strerror(res));
     57        return B_ERROR;
     58    }
     59
     60    return B_OK;
     61}
  • new file src/tools/get_package_dependencies/HTTPClient.h

    diff --git a/src/tools/get_package_dependencies/HTTPClient.h b/src/tools/get_package_dependencies/HTTPClient.h
    new file mode 100644
    index 0000000..d178153
    - +  
     1/*
     2 * Copyright 2016, Haiku, Inc. All Rights Reserved.
     3 * Distributed under the terms of the MIT License.
     4 *
     5 * Authors:
     6 *      Alexander von Gluck IV <kallisti5@unixzen.com>
     7 */
     8#ifndef HTTP_CLIENT_H
     9#define HTTP_CLIENT_H
     10
     11
     12#include <String.h>
     13#include <Entry.h>
     14#include <curl/curl.h>
     15
     16
     17class HTTPClient {
     18public:
     19                        HTTPClient();
     20                        ~HTTPClient();
     21
     22            status_t    Get(BString* url, BEntry* destination);
     23
     24private:
     25    static  size_t      _WriteCallback(void *buffer, size_t size, size_t nmemb,
     26                            void *userp);
     27
     28            CURL*       fCurl;
     29};
     30
     31
     32#endif /* HTTP_CLIENT_H */
  • src/tools/get_package_dependencies/Jamfile

    diff --git a/src/tools/get_package_dependencies/Jamfile b/src/tools/get_package_dependencies/Jamfile
    index 0bba9b0..452afab 100644
    a b USES_BE_API on <build>get_package_dependencies = true ;  
    88
    99BuildPlatformMain <build>get_package_dependencies :
    1010    get_package_dependencies.cpp
     11    HTTPClient.cpp
    1112    :
    1213    libpackage-add-on-libsolv_build.so
    1314    libsolvext_build.so libsolv_build.so
    14     libpackage_build.so $(HOST_LIBBE) $(HOST_LIBSUPC++) $(HOST_LIBSTDC++)
     15    libpackage_build.so $(HOST_LIBBE) curl $(HOST_LIBSUPC++) $(HOST_LIBSTDC++)
    1516    ;
  • src/tools/get_package_dependencies/get_package_dependencies.cpp

    diff --git a/src/tools/get_package_dependencies/get_package_dependencies.cpp b/src/tools/get_package_dependencies/get_package_dependencies.cpp
    index 63d5439..09ec554 100644
    a b  
    11/*
    2  * Copyright 2013, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2013-2016, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
    66 *      Ingo Weinhold <ingo_weinhold@gmx.de>
     7 *      Alexander von Gluck IV <kallisti5@unixzen.com>
    78 */
    89
    910
     
    1314
    1415#include <map>
    1516
     17#include <FindDirectory.h>
     18#include <package/RepositoryConfig.h>
    1619#include <package/RepositoryCache.h>
    1720#include <package/manager/Exceptions.h>
    1821#include <package/manager/RepositoryBuilder.h>
     
    2326#include <package/solver/SolverProblemSolution.h>
    2427#include <package/solver/SolverRepository.h>
    2528#include <package/solver/SolverResult.h>
     29#include <Path.h>
     30
     31#include "HTTPClient.h"
    2632
    2733
    2834using namespace BPackageKit;
    void  
    4450print_usage_and_exit(bool error)
    4551{
    4652    fprintf(error ? stderr : stdout,
    47         "Usage: %s <repository> ... -- <package> ...\n"
     53        "Usage: %s <repository-config> ... -- <package> ...\n"
    4854        "Resolves the dependencies of the given packages using the given\n"
    4955        "repositories and prints the URLs of the packages that are also\n"
    5056        "needed to satisfy all requirements. Fails, if there are conflicts\n"
    print_usage_and_exit(bool error)  
    5460}
    5561
    5662
     63static status_t
     64get_repocache(BRepositoryConfig config, BPath* outFile)
     65{
     66    BString finalURL;
     67    finalURL.SetTo(config.BaseURL());
     68    finalURL += "/repo";
     69
     70    if (find_directory(B_SYSTEM_TEMP_DIRECTORY, outFile) != B_OK)
     71        outFile->SetTo("/tmp");
     72
     73    BString tempFile = config.Name();
     74    tempFile += ".repocache";
     75
     76    outFile->Append(tempFile);
     77
     78    //printf("Downloading: %s\n", finalURL.String());
     79    //printf("Final output will be %s\n", outFile->Path());
     80
     81    BEntry entry(outFile->Path());
     82    HTTPClient* http = new HTTPClient;
     83    status_t result = http->Get(&finalURL, &entry);
     84    delete http;
     85
     86    return result;
     87}
     88
     89
    5790int
    5891main(int argc, const char* const* argv)
    5992{
    main(int argc, const char* const* argv)  
    93126        DIE(B_OK, "%s", e.Details().String());
    94127    }
    95128
    96     // add external repositories
    97     std::map<BSolverRepository*, BRepositoryInfo> repositoryInfos;
     129    // add specified remote repositories
     130    std::map<BSolverRepository*, BString> repositoryURLs;
     131
    98132    for (int i = 0; i < repositoryCount; i++) {
    99133        BSolverRepository* repository = new BSolverRepository;
     134        BRepositoryConfig config;
     135        error = config.SetTo(repositories[i]);
     136        if (error != B_OK)
     137            DIE(error, "failed to read repository config '%s'", repositories[i]);
     138
     139        // TODO: It would make sense if BRepositoryBuilder could accept a
     140        // BRepositoryConfig directly and "get" the remote BRepositoryCache
     141        // to properly solve dependencies. For now we curl here.
     142
     143        BPath output;
     144        get_repocache(config, &output);
     145
    100146        BRepositoryCache cache;
    101         error = cache.SetTo(repositories[i]);
     147        error = cache.SetTo(output.Path());
    102148        if (error != B_OK)
    103             DIE(error, "failed to read repository file '%s'", repositories[i]);
     149            DIE(error, "failed to read repository cache '%s'", repositories[i]);
     150
    104151        BRepositoryBuilder(*repository, cache)
    105152            .AddToSolver(solver, false);
    106         repositoryInfos[repository] = cache.Info();
     153        repositoryURLs[repository] = config.BaseURL();
    107154    }
    108155
    109156    // solve
    main(int argc, const char* const* argv)  
    152199        switch (element->Type()) {
    153200            case BSolverResultElement::B_TYPE_INSTALL:
    154201                if (package->Repository() != &installedRepository) {
    155                     const BRepositoryInfo& info
    156                         = repositoryInfos[package->Repository()];
    157                     BString url = info.OriginalBaseURL();
     202                    BString url = repositoryURLs[package->Repository()];
    158203                    url << "/packages/" << package->Info().CanonicalFileName();
    159204                    printf("%s\n", url.String());
    160205                }