Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo-lock [wip] #5

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/apps/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

def strip_hashes_from_lock(lock):
for source in lock['sources'].values():
del source['hash']
if 'hash' in source:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think dave just merged that bit

del source['hash']


def list(args):
Expand Down
3 changes: 3 additions & 0 deletions src/fetchers/default-fetcher.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
fetchFromGitLab,
fetchgit,
fetchurl,
writeScript,

lib,
...
Expand Down Expand Up @@ -36,6 +37,8 @@
inherit (source) url;
sha256 = source.hash or null;
}
else if source.type == "path" then
writeScript "fakePath" "foo"
else throw "unsupported source type '${source.type}'"
) sources;
}
1 change: 1 addition & 0 deletions src/fetchers/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
callPackage,
...
}:
rec {
defaultFetcher = callPackage ./default-fetcher.nix {};
Expand Down
50 changes: 50 additions & 0 deletions src/translators/rust/pure/cargo-lock/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
externals,
translatorName,
utils,
lib,
runCommandNoCC,
...
}:

let
translate =
{
inputPaths,
...
}:
let
cargoLock = builtins.fromTOML (builtins.readFile (builtins.elemAt inputPaths 0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DavHau just thinking out loud here, but I'm thinking that it might make sense to have inputPaths be a dictionary with name keys ? (rather than a list). Relying on the position of an attribute could be error prone ?
Just a thought.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I'm currently thinking about removing the path list and instead only allow to pass one path.
One reason is that pure translators should be callable via nix expression, and there it is simple to specify just one source.
If the source needs extra files, then it can be patched inside the nix expression before handing it to the translator

parsed = builtins.listToAttrs (map (p: lib.nameValuePair p.name p) cargoLock.package);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you are interested in some of the parsing that nixpkgs does on the cargolock, there was recently a PR about some improvements to it. You might be interested.
https://github.com/NixOS/nixpkgs/pull/137303/files

in
{
sources = builtins.mapAttrs (pname: pdata:
if pdata ? source && pdata ? checksum then
{
url = "https://crates.io/api/v1/crates/${pdata.name}/${pdata.version}/download";
type = "fetchurl";
hash = pdata.checksum;
}
else
{
path = ./.;
type = "path";
}
) parsed;

generic = {
buildSystem = "rust";
buildSystemFormatVersion = 1;
producedBy = translatorName;
dependencyGraph = null;
sourcesCombinedHash = null;
};
};

compatiblePaths = paths: utils.compatibleTopLevelPaths ".*(Cargo\\.lock)" paths;

in

{
inherit translate compatiblePaths;
}