-
-
Notifications
You must be signed in to change notification settings - Fork 160
support multiple libraries in one package #717
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
Open
m1-s
wants to merge
1
commit into
NixOS:master
Choose a base branch
from
m1-s:subLibraries
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ module Distribution.Nixpkgs.Haskell.Derivation | |||||||||
| , cabalFlags, runHaddock, jailbreak, doCheck, doBenchmark, testFlags, testTargets, hyperlinkSource | ||||||||||
| , enableLibraryProfiling, enableExecutableProfiling, phaseOverrides, editedCabalFile, metaSection | ||||||||||
| , dependencies, setupDepends, benchmarkDepends, enableSeparateDataOutput, extraAttributes | ||||||||||
| , subLibraryDepends, subLibraryDependencies | ||||||||||
| ) | ||||||||||
| where | ||||||||||
|
|
||||||||||
|
|
@@ -50,6 +51,8 @@ data Derivation = MkDerivation | |||||||||
| , _executableDepends :: BuildInfo | ||||||||||
| , _testDepends :: BuildInfo | ||||||||||
| , _benchmarkDepends :: BuildInfo | ||||||||||
| , _subLibraryDepends :: Map String BuildInfo | ||||||||||
| , _subLibraryDependencies :: Map String [String] | ||||||||||
| , _configureFlags :: Set String | ||||||||||
| , _cabalFlags :: FlagAssignment | ||||||||||
| , _runHaddock :: Bool | ||||||||||
|
|
@@ -83,6 +86,8 @@ nullDerivation = MkDerivation | |||||||||
| , _executableDepends = error "undefined Derivation.executableDepends" | ||||||||||
| , _testDepends = error "undefined Derivation.testDepends" | ||||||||||
| , _benchmarkDepends = error "undefined Derivation.benchmarkDepends" | ||||||||||
| , _subLibraryDepends = mempty | ||||||||||
| , _subLibraryDependencies = mempty | ||||||||||
| , _configureFlags = error "undefined Derivation.configureFlags" | ||||||||||
| , _cabalFlags = error "undefined Derivation.cabalFlags" | ||||||||||
| , _runHaddock = error "undefined Derivation.runHaddock" | ||||||||||
|
|
@@ -102,15 +107,26 @@ nullDerivation = MkDerivation | |||||||||
|
|
||||||||||
| makeLenses ''Derivation | ||||||||||
|
|
||||||||||
| makeLensesFor [("_setupDepends", "dependencies"), ("_libraryDepends", "dependencies"), ("_executableDepends", "dependencies"), ("_testDepends", "dependencies"), ("_benchmarkDepends", "dependencies")] ''Derivation | ||||||||||
| -- | Traversal over all 'BuildInfo' values in a 'Derivation', including | ||||||||||
| -- the setup, library, executable, test, benchmark, and sub-library depends. | ||||||||||
| dependencies :: Traversal' Derivation BuildInfo | ||||||||||
| dependencies f drv = | ||||||||||
| (\s l e t b sl -> drv { _setupDepends = s, _libraryDepends = l, _executableDepends = e | ||||||||||
| , _testDepends = t, _benchmarkDepends = b, _subLibraryDepends = sl }) | ||||||||||
| <$> f (_setupDepends drv) | ||||||||||
| <*> f (_libraryDepends drv) | ||||||||||
| <*> f (_executableDepends drv) | ||||||||||
| <*> f (_testDepends drv) | ||||||||||
| <*> f (_benchmarkDepends drv) | ||||||||||
| <*> traverse f (_subLibraryDepends drv) | ||||||||||
|
|
||||||||||
| instance Package Derivation where | ||||||||||
| packageId = view pkgid | ||||||||||
|
|
||||||||||
| instance NFData Derivation | ||||||||||
|
|
||||||||||
| instance Pretty Derivation where | ||||||||||
| pPrint drv@MkDerivation {..} = funargs (map text ("mkDerivation" : toAscList inputs)) $$ vcat | ||||||||||
| pPrint drv@MkDerivation {_subLibraryDepends = subLibDeps, _subLibraryDependencies = subLibConsumerDeps, ..} = funargs (map text ("mkDerivation" : toAscList inputs)) $$ vcat | ||||||||||
| [ text "mkDerivation" <+> lbrace | ||||||||||
| , nest 2 $ vcat | ||||||||||
| [ attr "pname" $ doubleQuotes $ pPrint (packageName _pkgid) | ||||||||||
|
|
@@ -124,10 +140,12 @@ instance Pretty Derivation where | |||||||||
| , boolattr "isExecutable" (not _isLibrary || _isExecutable) _isExecutable | ||||||||||
| , boolattr "enableSeparateDataOutput" _enableSeparateDataOutput _enableSeparateDataOutput | ||||||||||
| , onlyIf (_setupDepends /= mempty) $ pPrintBuildInfo "setup" _setupDepends | ||||||||||
| , onlyIf (_libraryDepends /= mempty) $ pPrintBuildInfo "library" _libraryDepends | ||||||||||
| , onlyIf (mergedLibraryDepends /= mempty) $ pPrintBuildInfo "library" mergedLibraryDepends | ||||||||||
| , onlyIf (not (Map.null subLibDeps)) $ pPrintSubLibraryDepends subLibDeps | ||||||||||
| , onlyIf (_executableDepends /= mempty) $ pPrintBuildInfo "executable" _executableDepends | ||||||||||
| , onlyIf (_testDepends /= mempty) $ pPrintBuildInfo "test" _testDepends | ||||||||||
| , onlyIf (_benchmarkDepends /= mempty) $ pPrintBuildInfo "benchmark" _benchmarkDepends | ||||||||||
| , onlyIf (not (Map.null subLibConsumerDeps)) $ pPrintSubLibraryDependencies subLibConsumerDeps | ||||||||||
| , boolattr "enableLibraryProfiling" _enableLibraryProfiling _enableLibraryProfiling | ||||||||||
| , boolattr "enableExecutableProfiling" _enableExecutableProfiling _enableExecutableProfiling | ||||||||||
| , boolattr "doHaddock" (not _runHaddock) _runHaddock | ||||||||||
|
|
@@ -152,8 +170,39 @@ instance Pretty Derivation where | |||||||||
| Just derivKind' -> Set.fromList [derivKindFunction derivKind' | not isHackagePackage] | ||||||||||
| ] | ||||||||||
|
|
||||||||||
| -- For backwards compatibility, libraryHaskellDepends is emitted as the | ||||||||||
| -- union of the main library deps and all sub-library deps. New consumers | ||||||||||
| -- should prefer the separate subLibraryDepends attrset. | ||||||||||
| mergedLibraryDepends = _libraryDepends `mappend` foldMap id (Map.elems subLibDeps) | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Unless you want a strict version, then it would be:
Suggested change
|
||||||||||
|
|
||||||||||
| renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text (unFlagName f) | (f, enable) <- unFlagAssignment _cabalFlags ] | ||||||||||
| ++ map text (toAscList _configureFlags) | ||||||||||
| isHackagePackage = "mirror://hackage/" `isPrefixOf` derivUrl _src | ||||||||||
|
|
||||||||||
| postUnpack = string $ "sourceRoot+=/" ++ _subpath ++ "; echo source root reset to $sourceRoot" | ||||||||||
|
|
||||||||||
| pPrintSubLibraryDepends :: Map String BuildInfo -> Doc | ||||||||||
| pPrintSubLibraryDepends libs = vcat | ||||||||||
| [ text "subLibraryDepends" <+> equals <+> lbrace | ||||||||||
| , nest 2 $ vcat entries | ||||||||||
| , rbrace <> semi | ||||||||||
| ] | ||||||||||
| where | ||||||||||
| entries = [ vcat [ text (show name) <+> equals <+> lbrace | ||||||||||
| , nest 2 $ pPrintBuildInfo "" bi | ||||||||||
| , rbrace <> semi | ||||||||||
| ] | ||||||||||
| | (name, bi) <- Map.toAscList libs | ||||||||||
| , bi /= mempty | ||||||||||
| ] | ||||||||||
|
|
||||||||||
| pPrintSubLibraryDependencies :: Map String [String] -> Doc | ||||||||||
| pPrintSubLibraryDependencies deps = vcat | ||||||||||
| [ text "subLibraryDependencies" <+> equals <+> lbrace | ||||||||||
| , nest 2 $ vcat entries | ||||||||||
| , rbrace <> semi | ||||||||||
| ] | ||||||||||
| where | ||||||||||
| entries = [ listattrDoc (show pkgName) empty (map (doubleQuotes . text) subLibs) | ||||||||||
| | (pkgName, subLibs) <- Map.toAscList deps | ||||||||||
| ] | ||||||||||
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
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
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
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,28 @@ | ||
| cabal-version: 3.0 | ||
| name: sub-libraries | ||
| version: 0.1.0.0 | ||
| synopsis: Test case for sub-library support | ||
| license: BSD-3-Clause | ||
| build-type: Simple | ||
|
|
||
| library | ||
| exposed-modules: MyLib | ||
| build-depends: base >=4.14 | ||
| default-language: Haskell2010 | ||
|
|
||
| library public-sub | ||
| visibility: public | ||
| exposed-modules: PublicSub | ||
| build-depends: base, deepseq | ||
| default-language: Haskell2010 | ||
|
|
||
| library private-sub | ||
| visibility: private | ||
| exposed-modules: PrivateSub | ||
| build-depends: base, containers | ||
| default-language: Haskell2010 | ||
|
|
||
| executable demo | ||
| main-is: Main.hs | ||
| build-depends: base, sub-libraries, sub-libraries:public-sub | ||
| default-language: Haskell2010 |
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,22 @@ | ||
| { mkDerivation, base, containers, deepseq, lib }: | ||
| mkDerivation { | ||
| pname = "sub-libraries"; | ||
| version = "0.1.0.0"; | ||
| sha256 = "deadbeef"; | ||
| isLibrary = true; | ||
| isExecutable = true; | ||
| libraryHaskellDepends = [ base containers deepseq ]; | ||
| subLibraryDepends = { | ||
| "private-sub" = { | ||
| HaskellDepends = [ base containers ]; | ||
| }; | ||
| "public-sub" = { | ||
| HaskellDepends = [ base deepseq ]; | ||
| }; | ||
| }; | ||
| executableHaskellDepends = [ base ]; | ||
| doHaddock = false; | ||
| description = "Test case for sub-library support"; | ||
| license = lib.meta.getLicenseFromSpdxId "BSD-3-Clause"; | ||
| mainProgram = "demo"; | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: shouldn't those be
errorlike others?