diff --git a/hacking/cargo-manifest-management/Makefile b/hacking/cargo-manifest-management/Makefile index d8cc21a8a..0b47e7a74 100644 --- a/hacking/cargo-manifest-management/Makefile +++ b/hacking/cargo-manifest-management/Makefile @@ -4,10 +4,8 @@ # SPDX-License-Identifier: BSD-2-Clause # -project_root := ../.. - run_script := \ - script=$$(nix-build -A script --no-out-link) && $$script --root $(project_root) + script=$$(nix-build -A script --no-out-link) && $$script .PHONY: none none: diff --git a/hacking/cargo-manifest-management/execute_plan.py b/hacking/cargo-manifest-management/execute_plan.py index db664792b..efbc84186 100644 --- a/hacking/cargo-manifest-management/execute_plan.py +++ b/hacking/cargo-manifest-management/execute_plan.py @@ -16,19 +16,18 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument('--plan', type=Path) - parser.add_argument('--root', type=Path) parser.add_argument('--just-check', default=False, action=argparse.BooleanOptionalAction) args = parser.parse_args() with args.plan.open() as f: plan = json.load(f) - run(plan, args.root, args.just_check) + run(plan, args.just_check) -def run(plan, root, just_check): - for relative_manifest_path, v in plan.items(): - manifest_path = root / relative_manifest_path +def run(plan, just_check): + for manifest_path, v in plan.items(): + manifest_path = Path(manifest_path) src = Path(v['src']) just_check_equivalence = v['justEnsureEquivalence'] diff --git a/hacking/cargo-manifest-management/manual-manifests.nix b/hacking/cargo-manifest-management/manual-manifests.nix index c6c4924ca..85c330655 100644 --- a/hacking/cargo-manifest-management/manual-manifests.nix +++ b/hacking/cargo-manifest-management/manual-manifests.nix @@ -4,11 +4,15 @@ # SPDX-License-Identifier: BSD-2-Clause # -{ - # "virtio-drivers" = "tmp/virtio-drivers"; - # "mbedtls" = "tmp/rust-mbedtls/mbedtls"; - # "mbedtls-sys-auto" = "tmp/rust-mbedtls/mbedtls-sys"; - # "mbedtls-platform-support" = "tmp/rust-mbedtls/mbedtls-platform-support"; - # "embedded-fat" = "tmp/rust-embedded-fat"; - # "volatile" = "tmp/volatile"; +let + + relativeToWorkspaceRoot = relativePath: "${toString ../..}/${relativePath}"; + +in { + # "virtio-drivers" = relativeToWorkspaceRoot "tmp/virtio-drivers"; + # "mbedtls" = relativeToWorkspaceRoot "tmp/rust-mbedtls/mbedtls"; + # "mbedtls-sys-auto" = relativeToWorkspaceRoot "tmp/rust-mbedtls/mbedtls-sys"; + # "mbedtls-platform-support" = relativeToWorkspaceRoot "tmp/rust-mbedtls/mbedtls-platform-support"; + # "embedded-fat" = relativeToWorkspaceRoot "tmp/rust-embedded-fat"; + # "volatile" = relativeToWorkspaceRoot "tmp/volatile"; } diff --git a/hacking/cargo-manifest-management/workspace.nix b/hacking/cargo-manifest-management/workspace.nix index 4113161d0..e3f89337f 100644 --- a/hacking/cargo-manifest-management/workspace.nix +++ b/hacking/cargo-manifest-management/workspace.nix @@ -22,20 +22,17 @@ let in scanDirForFilesWithName dirFilter "Cargo.nix" workspaceRoot; - genrateManifest = absolutePath: + genrateManifest = cargoNixAbsolutePath: let - relativePath = - pathBetween - workspaceRoot - (builtins.dirOf absolutePath); + absolutePath = builtins.dirOf cargoNixAbsolutePath; manifestExpr = callManifest { - inherit relativePath; - f = import absolutePath; + inherit absolutePath; + f = import cargoNixAbsolutePath; }; parsed = parseManifestExpr manifestExpr; inherit (parsed) manifestValue frontmatter justEnsureEquivalence; in { - inherit relativePath manifestValue frontmatter justEnsureEquivalence; + inherit absolutePath manifestValue frontmatter justEnsureEquivalence; packageName = manifestValue.package.name or null; packageVersion = manifestValue.package.version or null; manifestTOML = renderManifest { @@ -65,19 +62,19 @@ let inherit (elaboratedNix) frontmatter justEnsureEquivalence; }; - callManifest = { relativePath, f }: + callManifest = { absolutePath, f }: let bespokeScope = manifestScope // { - localCrates = mkDeps relativePath; + localCrates = mkDeps absolutePath; }; args = builtins.intersectAttrs (lib.functionArgs f) bespokeScope; in f args; - mkDeps = relativePath: + mkDeps = absolutePath: let - rel = pathBetween relativePath; - generated = lib.mapAttrs (_: manifest: { path = rel manifest.relativePath; }) generatedManifestsByPackageName; + rel = pathBetween absolutePath; + generated = lib.mapAttrs (_: manifest: { path = rel manifest.absolutePath; }) generatedManifestsByPackageName; manual = lib.mapAttrs (_: otherPath: { path = rel otherPath; }) manualManifests; in generated // manual; @@ -90,7 +87,7 @@ let (manifest: lib.optional (manifest.packageName != null) (lib.nameValuePair manifest.packageName manifest))); plan = lib.listToAttrs (lib.forEach generatedManifestsList (manifest: { - name = "${manifest.relativePath}${lib.optionalString (manifest.relativePath != "") "/"}Cargo.toml"; + name = "${manifest.absolutePath}/Cargo.toml"; value = { src = manifest.manifestTOML; inherit (manifest) justEnsureEquivalence; @@ -105,7 +102,10 @@ let ''; # for manual inspection, useful for debugging this script - links = linkFarm "crates" (lib.mapAttrs (_: v: v.src) plan); + links = linkFarm "crates" + (lib.mapAttrs' + (absolutePath: v: lib.nameValuePair "root/${absolutePath}" v.src) + plan); in { inherit script;