summaryrefslogtreecommitdiff
path: root/tools/minicargo/repository.h
blob: ca481166f748dd7255f697b98006b9f67de2fbe8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
 * minicargo - MRustC-specific clone of `cargo`
 * - By John Hodge (Mutabah)
 *
 * repository.h
 * - Handling (vendored) crates.io dependencies
 */
#pragma once

#include <string>
#include <map>
#include "helpers.h"
#include "manifest.h"

class Repository
{
    struct Entry
    {
        /// Path to the Cargo.toml file in the package root
        ::std::string   manifest_path;
        /// Package version
        PackageVersion  version;
        /// (Cached) loaded manifest
        ::std::shared_ptr<PackageManifest>  loaded_manifest;
    };

    ::std::multimap<::std::string, Entry>    m_cache;
    // path => manifest
    ::std::map<::std::string, ::std::shared_ptr<PackageManifest>>   m_path_cache;
public:
    void load_cache(const ::helpers::path& path);
    void load_vendored(const ::helpers::path& path);

    ::std::shared_ptr<PackageManifest> from_path(::helpers::path path);
    ::std::shared_ptr<PackageManifest> find(const ::std::string& name, const PackageVersionSpec& version);
};