-
Notifications
You must be signed in to change notification settings - Fork 846
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
Refactoring proposition about Package/LocalPackage #5920
Comments
After digging a bit into the cabal types, it seems bringing in the PackageDescription from cabal as a (mostly) replacement for the Another possibility, which might bring the best of both world is to create a very similar structure to the PackageDescription from cabal with potentially additional data as well, something like : -- for instance for the subLibraries field in cabal's PackageDescription :
subLibraries :: [[Library](https://hackage.haskell.org/package/Cabal-syntax-3.8.1.0/docs/Distribution-Types-Library.html#t:Library)]
-- we have a stack counterpart like :
data StackLibrary = StackLibrary {
cabalLibrary :: Library,
shouldBeBuilt :: Boolean,
-- etc, some more fields
}
-- and then in the equivalent of PackageDescription for Stack (something like StackPackageDescription) we get :
subLibraries :: [StackLibrary]
|
Here's a more formal proposition of what I envison (I already began to work on this but It can change so any counter-proposition, request for change is welcome). I'll link this post into the stack-collaborators channel in slack and potentially post a summary of the comments/reactions (if any). Overall description and exampleOverall the idea is to bring as much of the component level information into cabal-like structured component datatypes. Here's the definition of the packageLibraries field of the Package type : packageLibraries :: !PackageLibraries -- ^ does the package have a buildable library stanza? And here's the (simplified) place where we define it : packageLibraries =
let mlib = do
lib <- library pkg
guard $ buildable $ libBuildInfo lib
Just lib
in
case mlib of
Nothing -> NoLibraries
Just _ -> HasLibraries foreignLibNames We can see here this field group different notions into one :
In many places we only pattern match on the ADT to know whether we have a buildable main library.
These would be Stack equivalent to the Cabal related types with only the necesary information for Slack : -- Stack foreign libraries.
--
-- [ForeignLib](https://hackage.haskell.org/package/Cabal-syntax/docs/Distribution-Types-Foreign-Libraries.html) is the Cabal equivalent.
--
data StackForeignLibrary =
StackForeignLibrary
{ name :: StackUnqualCompName
, buildInfo :: !StackBuildInfo
}
deriving (Show, Typeable)
-- Stack executable.
--
-- [Executable](https://hackage.haskell.org/package/Cabal-syntax/docs/Distribution-Types-Executable.html) is the Cabal equivalent.
--
data StackExecutable =
StackExecutable
{ name :: StackUnqualCompName
, buildInfo :: !StackBuildInfo
, modulePath :: FilePath
}
deriving (Show, Typeable)
-- etc Envisoned list of refactorings
I dont believe this is exhaustive, but it's the gist of it. Why do I believe this is good for stack ?
|
Hello @mpilgrem,
While trying to renew some effort on #5460, #5504, I envisoned a much needed refactoring first and a more iterative approach. The current merge request is old and too ambitious to land in any reasonable fashion.
So my proposal this time is much more limited and yet I believe very important. My assessment about the Package and LocalPackages type is that they are Cabal 1.0 oriented and they have very ad-hoc code for named components (tests, executables, benchmarks, libraries). This has very bad impacts on the codebase in many places and it should be fixed before trying any component based builds.
Here are some examples of what I mean :
And the main creation of such type is enlightened by an edifying comment :
I mean this is pretty crazy, see, enabling tests and benchmarks in a local package (that is, enabling component centric aaspects) is leading to the duplication of an entire Package type (with very package level information being duplicated) in lpTestBench. And this is only one example but many things are extremely unordered and feel bad and ad-hoc for the reader. That we have to resolvePackage in 4 different manners is very telling, again Package is keeping the very same information 4 times there (e.g. packageName, packageVersion, packageLicense ...)
And then we have the very 2017 explanation of what I'm saying here in the code comment :
The reason for this seems that the
Package
datatype has not been revised correctly since the introduction of proper named components in Cabal 2.0. I think addressing this issue is a top priority for the viability of the stack codebase in the future. I see two potential (broad) approach here, either we try to get closer to the Cabal datatypes and in particular to GenericPackageDescription which roughly is the Cabal counterpart of Package in stack. Or we try to build something way more factorized [than the current Package definition] with proper named components architecture in mind, something like :For what it's worth, @snoyberg was suggesting in 2017 that we pursue the first scenario here (pull in as much cabal-original- types as possible and relevant and add required info on top). This requires a digging in the Cabal provided datatypes to explore to what extent they are compatible with this or not.
Both scenarios are major refactorings.
Tell me what you think (besides, #5504 can be considered abandonned for now, I don't see how we can properly support components without having this refactoring first).
The text was updated successfully, but these errors were encountered: