-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
buildDubPackage: split into hooks and into importDubLock #344744
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,148 +1,71 @@ | ||
| { | ||
| lib, | ||
| stdenv, | ||
| fetchurl, | ||
| fetchgit, | ||
| linkFarm, | ||
| dub, | ||
| importDubLock, | ||
| dubSetupHook, | ||
| dubBuildHook, | ||
| dubCheckHook, | ||
| ldc, | ||
| removeReferencesTo, | ||
| }: | ||
|
|
||
| # See https://nixos.org/manual/nixpkgs/unstable#dlang for more detailed usage information | ||
| lib.extendMkDerivation { | ||
| constructDrv = stdenv.mkDerivation; | ||
|
|
||
| { | ||
| # A lockfile generated by `dub-to-nix` from the source of the package. | ||
| # Can be either a path to the file, or an attrset already parsed with `lib.importJSON`. | ||
| dubLock, | ||
| # The build type to pass to `dub build` as a value for the `--build=` flag. | ||
| dubBuildType ? "release", | ||
| # The flags to pass to `dub build` and `dub test`. | ||
| dubFlags ? [ ], | ||
| # The flags to pass to `dub build`. | ||
| dubBuildFlags ? [ ], | ||
| # The flags to pass to `dub test`. | ||
| dubTestFlags ? [ ], | ||
| # The D compiler to be used by `dub`. | ||
| compiler ? ldc, | ||
| ... | ||
| }@args: | ||
| excludeDrvArgNames = [ | ||
| "dubLock" | ||
| "compiler" | ||
| ]; | ||
|
|
||
| let | ||
| makeDubDep = | ||
| { | ||
| pname, | ||
| version, | ||
| sha256, | ||
| }: | ||
| extendDrvArgs = | ||
| finalAttrs: | ||
| { | ||
| inherit pname version; | ||
| src = fetchurl { | ||
| name = "dub-${pname}-${version}.zip"; | ||
| url = "mirror://dub/${pname}/${version}.zip"; | ||
| inherit sha256; | ||
| }; | ||
| }; | ||
| # A lockfile generated by `dub-to-nix` from the source of the package. | ||
| # Can be either a path to the file, or an attrset already parsed with `lib.importJSON`. | ||
| dubLock, | ||
| compiler ? ldc, | ||
| ... | ||
| }@args: | ||
|
|
||
| makeGitDep = | ||
| { | ||
| pname, | ||
| version, | ||
| repository, | ||
| sha256, | ||
| }: | ||
| { | ||
| inherit pname version; | ||
| src = fetchgit { | ||
| url = repository; | ||
| rev = version; | ||
| inherit sha256; | ||
| dubDeps = importDubLock { | ||
| inherit (finalAttrs) pname version; | ||
| lock = dubLock; | ||
| }; | ||
| }; | ||
|
|
||
| lockJson = if lib.isPath dubLock then lib.importJSON dubLock else dubLock; | ||
| depsRaw = lib.mapAttrsToList (pname: args: { inherit pname; } // args) lockJson.dependencies; | ||
|
|
||
| dubDeps = map makeDubDep (lib.filter (args: !(args ? repository)) depsRaw); | ||
| gitDeps = map makeGitDep (lib.filter (args: args ? repository) depsRaw); | ||
|
|
||
| # a directory with multiple single element registries | ||
| # one big directory with all .zip files leads to version parsing errors | ||
| # when the name of a package is a prefix of the name of another package | ||
| dubRegistryBase = linkFarm "dub-registry-base" ( | ||
| map (dep: { | ||
| name = "${dep.pname}/${dep.pname}-${dep.version}.zip"; | ||
| path = dep.src; | ||
| }) dubDeps | ||
| ); | ||
| strictDeps = args.strictDeps or true; | ||
|
|
||
| combinedFlags = "--skip-registry=all --compiler=${lib.getExe compiler} ${toString dubFlags}"; | ||
| combinedBuildFlags = "${combinedFlags} --build=${dubBuildType} ${toString dubBuildFlags}"; | ||
| combinedTestFlags = "${combinedFlags} ${toString dubTestFlags}"; | ||
| in | ||
| stdenv.mkDerivation ( | ||
| builtins.removeAttrs args [ "dubLock" ] | ||
| // { | ||
| strictDeps = args.strictDeps or true; | ||
| nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [ | ||
| dubSetupHook | ||
| (dubBuildHook.override { inherit dub; }) | ||
| compiler | ||
| removeReferencesTo | ||
| ]; | ||
|
|
||
| nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [ | ||
| dub | ||
| compiler | ||
| removeReferencesTo | ||
| ]; | ||
|
|
||
| configurePhase = | ||
| args.configurePhase or '' | ||
| configurePhase = '' | ||
| runHook preConfigure | ||
|
|
||
| export DUB_HOME="$NIX_BUILD_TOP/.dub" | ||
| mkdir -p "$DUB_HOME" | ||
|
|
||
| # register dub dependencies | ||
| ${lib.concatMapStringsSep "\n" (dep: '' | ||
| dub fetch ${dep.pname}@${dep.version} --cache=user --skip-registry=standard --registry=file://${dubRegistryBase}/${dep.pname} | ||
| '') dubDeps} | ||
|
|
||
| # register git dependencies | ||
| ${lib.concatMapStringsSep "\n" (dep: '' | ||
| mkdir -p "$DUB_HOME/packages/${dep.pname}/${dep.version}" | ||
| cp -r --no-preserve=all ${dep.src} "$DUB_HOME/packages/${dep.pname}/${dep.version}/${dep.pname}" | ||
| '') gitDeps} | ||
|
|
||
| dubFlags+=("--compiler=${lib.getExe compiler}") | ||
| runHook postConfigure | ||
| ''; | ||
|
|
||
| buildPhase = | ||
| args.buildPhase or '' | ||
| runHook preBuild | ||
|
|
||
| dub build ${combinedBuildFlags} | ||
|
|
||
| runHook postBuild | ||
| ''; | ||
|
|
||
| doCheck = args.doCheck or false; | ||
| doCheck = args.doCheck or false; | ||
|
|
||
| checkPhase = | ||
| args.checkPhase or '' | ||
| runHook preCheck | ||
| nativeCheckInputs = [ | ||
| (dubCheckHook.override { inherit dub; }) | ||
| ]; | ||
|
|
||
| dub test ${combinedTestFlags} | ||
| preFixup = '' | ||
| ${args.preFixup or ""} | ||
|
|
||
| runHook postCheck | ||
| find "$out" -type f -exec remove-references-to -t ${compiler} '{}' + | ||
| ''; | ||
|
|
||
| preFixup = '' | ||
| ${args.preFixup or ""} | ||
|
|
||
| find "$out" -type f -exec remove-references-to -t ${compiler} '{}' + | ||
| ''; | ||
| disallowedReferences = args.disallowedReferences or [ compiler ]; | ||
|
|
||
| disallowedReferences = [ compiler ]; | ||
|
|
||
| meta = { | ||
| platforms = dub.meta.platforms; | ||
| } | ||
| // args.meta or { }; | ||
| } | ||
| ) | ||
| meta = { | ||
| platforms = dub.meta.platforms; | ||
| } | ||
| // args.meta or { }; | ||
| }; | ||
| } | ||
26 changes: 26 additions & 0 deletions
26
pkgs/build-support/dlang/builddubpackage/hooks/default.nix
philiptaron marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { callPackage }: | ||
|
|
||
| { | ||
| dubSetupHook = callPackage ( | ||
| { makeSetupHook }: | ||
| makeSetupHook { | ||
| name = "dub-setup-hook"; | ||
| } ./dub-setup-hook.sh | ||
| ) { }; | ||
|
|
||
| dubBuildHook = callPackage ( | ||
| { makeSetupHook, dub }: | ||
| makeSetupHook { | ||
| name = "dub-build-hook"; | ||
| propagatedBuildInputs = [ dub ]; | ||
| } ./dub-build-hook.sh | ||
| ) { }; | ||
|
|
||
| dubCheckHook = callPackage ( | ||
| { makeSetupHook, dub }: | ||
| makeSetupHook { | ||
| name = "dub-check-hook"; | ||
| propagatedBuildInputs = [ dub ]; | ||
| } ./dub-check-hook.sh | ||
| ) { }; | ||
| } |
13 changes: 13 additions & 0 deletions
13
pkgs/build-support/dlang/builddubpackage/hooks/dub-build-hook.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| dubBuildHook() { | ||
| runHook preBuild | ||
| echo "Executing dubBuildHook" | ||
TomaSajt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| dub build --skip-registry=all --build="${dubBuildType-"release"}" "${dubBuildFlags[@]}" "${dubFlags[@]}" | ||
|
|
||
| echo "Finished dubBuildHook" | ||
| runHook postBuild | ||
| } | ||
|
|
||
| if [[ -z "${dontDubBuild-}" && -z "${buildPhase-}" ]]; then | ||
| buildPhase=dubBuildHook | ||
| fi | ||
13 changes: 13 additions & 0 deletions
13
pkgs/build-support/dlang/builddubpackage/hooks/dub-check-hook.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| dubCheckHook() { | ||
| runHook preCheck | ||
| echo "Executing dubCheckHook" | ||
|
|
||
| dub test --skip-registry=all "${dubTestFlags[@]}" "${dubFlags[@]}" | ||
|
|
||
| echo "Finished dubCheckHook" | ||
| runHook postCheck | ||
| } | ||
|
|
||
| if [[ -z "${dontDubCheck-}" && -z "${checkPhase-}" ]]; then | ||
| checkPhase=dubCheckHook | ||
| fi |
19 changes: 19 additions & 0 deletions
19
pkgs/build-support/dlang/builddubpackage/hooks/dub-setup-hook.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| dubSetupHook() { | ||
| echo "Executing dubSetupHook" | ||
|
|
||
| if [ -z "${dubDeps-}" ]; then | ||
| echo "Error: 'dubDeps' must be set when using dubSetupHook." | ||
| exit 1 | ||
| fi | ||
|
|
||
| export DUB_HOME="$NIX_BUILD_TOP"/.dub | ||
| echo "Configuring \$DUB_HOME ($DUB_HOME)" | ||
| cp -Tr "$dubDeps"/.dub "$NIX_BUILD_TOP"/.dub | ||
| chmod -R +w "$DUB_HOME" | ||
|
|
||
| echo "Finished dubSetupHook" | ||
| } | ||
|
|
||
| if [ -z "${dontDubSetup-}" ]; then | ||
| postPatchHooks+=(dubSetupHook) | ||
| fi |
81 changes: 81 additions & 0 deletions
81
pkgs/build-support/dlang/builddubpackage/import-dub-lock.nix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| { | ||
| lib, | ||
| runCommand, | ||
| linkFarm, | ||
| fetchurl, | ||
| fetchgit, | ||
| dub, | ||
| }: | ||
|
|
||
| { | ||
| pname, | ||
| version, | ||
| lock, | ||
| }: | ||
|
|
||
| let | ||
| makeDubDep = | ||
| { | ||
| pname, | ||
| version, | ||
| sha256, | ||
| }: | ||
| { | ||
| inherit pname version; | ||
| src = fetchurl { | ||
| name = "dub-${pname}-${version}.zip"; | ||
| url = "mirror://dub/${pname}/${version}.zip"; | ||
| inherit sha256; | ||
| }; | ||
| }; | ||
|
|
||
| makeGitDep = | ||
| { | ||
| pname, | ||
| version, | ||
| repository, | ||
| sha256, | ||
| }: | ||
| { | ||
| inherit pname version; | ||
| src = fetchgit { | ||
| url = repository; | ||
| rev = version; | ||
| inherit sha256; | ||
| }; | ||
| }; | ||
|
|
||
| lockJson = if lib.isPath lock then lib.importJSON lock else lock; | ||
| depsRaw = lib.mapAttrsToList (pname: args: { inherit pname; } // args) lockJson.dependencies; | ||
|
|
||
| dubDeps = map makeDubDep (lib.filter (args: !(args ? repository)) depsRaw); | ||
| gitDeps = map makeGitDep (lib.filter (args: args ? repository) depsRaw); | ||
|
|
||
| # a directory with multiple single element registries | ||
| # one big directory with all .zip files leads to version parsing errors | ||
| # when the name of a package is a prefix of the name of another package | ||
| dubRegistryBase = linkFarm "dub-registry-base" ( | ||
| map (dep: { | ||
| name = "${dep.pname}/${dep.pname}-${dep.version}.zip"; | ||
| path = dep.src; | ||
| }) dubDeps | ||
| ); | ||
|
|
||
| in | ||
| runCommand "${pname}-${version}-dub-deps" | ||
| { | ||
| nativeBuildInputs = [ dub ]; | ||
| } | ||
| '' | ||
| export DUB_HOME="$out/.dub" | ||
| mkdir -p "$DUB_HOME" | ||
| # register dub dependencies | ||
| ${lib.concatMapStringsSep "\n" (dep: '' | ||
| dub fetch ${dep.pname}@${dep.version} --cache=user --skip-registry=standard --registry=file://${dubRegistryBase}/${dep.pname} | ||
| '') dubDeps} | ||
| # register git dependencies | ||
| ${lib.concatMapStringsSep "\n" (dep: '' | ||
| mkdir -p "$DUB_HOME/packages/${dep.pname}/${dep.version}" | ||
| cp -r --no-preserve=all ${dep.src} "$DUB_HOME/packages/${dep.pname}/${dep.version}/${dep.pname}" | ||
| '') gitDeps} | ||
| '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| { callPackage }: | ||
|
|
||
| { | ||
| buildDubPackage = callPackage ./builddubpackage { }; | ||
| dub-to-nix = callPackage ./dub-to-nix { }; | ||
| importDubLock = callPackage ./builddubpackage/import-dub-lock.nix { }; | ||
| buildDubPackage = callPackage ./builddubpackage { }; | ||
| } | ||
| // import ./builddubpackage/hooks { inherit callPackage; } |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.