-
Notifications
You must be signed in to change notification settings - Fork 17
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
[POC] Elm json "source-directories" support #27
base: master
Are you sure you want to change the base?
[POC] Elm json "source-directories" support #27
Conversation
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.
commented not so obvious parts of the diff.
@@ -6,27 +6,47 @@ with (import nixpkgs config); | |||
|
|||
let | |||
mkDerivation = | |||
{ srcs ? ./elm-srcs.nix | |||
, src |
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.
replaced by srcs
, targets ? [] | ||
, versionsDat ? ./versions.dat | ||
}: | ||
stdenv.mkDerivation { | ||
inherit name src; | ||
inherit name srcs; | ||
sourceRoot = "."; |
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.
this can be hardcoded - we place generated elm.json with correct paths and the prefix elm make
with right dirs.
-- TODO: there is likely to be even better abstraction | ||
tryLookup :: HashMap Text Value -> Text -> Either Elm2NixError Value | ||
tryLookup hm key = maybeToRight (KeyNotFound key) (HM.lookup key hm) | ||
where |
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.
reused between parseElmJsonDeps
and parseElmJsonSrcs
ce64e0f
to
f7b8cc8
Compare
srcdir = "${srcdir}"; | ||
targets = ["./Main"]; |
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.
BREAKING change: Main.Entry
=> ./Main/Entry
. Supports custom extensions like UPDATE: elm compiler will no longer support entries like this.Main.js.elm
or Main.html.elm
and entries from different sources (relative path from current dir).
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.
Can we revert this then?
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.
unfortunetely this is still required.
Imagine you have source-directories
like this defined in elm.json
:
"source-directories": [
"./src",
"./src2",
"../lib"
]
Now when you set targets = [ "Main" ]
it's not clear in which directory this main should be located. It can be any one of those.
Another issue is that with current dir. Imagine having this elm.json
:
"source-directories": [
".",
"../lib"
]
since I've used srcs
attribute in derivation nix will create structure as:
- $pwd # contains files form
.
, is named after current durectory - lib # contains files from
../lib
this is why Main is prefixed with ./
. We need to replace this ./
prefix with the name of directory to which builder placed actual source from current dir.
I wonder if there is any builtin helper that would help to resolve paths in a way nix does it when srcs
attribute on mkDerivation is used. I belive this is done in a this shellscript
pure (Vector.head dirs) | ||
|
||
lastDir :: FilePath -> FilePath | ||
lastDir = foldl (\path c -> if c == '/' then "" else path <> [c]) "" |
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.
not the most efficient way to implement this but quite concise
@domenkozar This is ready for a review. principles followed:
Some of the functions are not exactly most optimal or robust (path handling mostly). |
"type": "application", | ||
"source-directories": [ | ||
".", | ||
"../b-src/src" |
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.
tests #6
{ | ||
"type": "application", | ||
"source-directories": [ | ||
".", |
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.
tests #19
stringifySrcs xs = | ||
"[\n" | ||
<> foldr (\i acc -> " " <> i <> "\n" <> acc) "" xs | ||
<> " ]" |
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.
todo: use QuasiQuotes
Sorry for taking this long, I've just moved over the continent and don't have immediate time to review this work. Hope you're ok waiting a few more days or so. |
no worries. I'm busy as well. Take your time, there is no need to rush anything. Given the nature of these changes, I expect this to take maybe even a few weeks still |
What is the status of this pull request? Also, correct me if I'm wrong, but once merged could it help us import private elm packages? |
I'm not sure how you emulate private packages but if you use |
c9c7ad2
to
81bfde0
Compare
At this moment this is only proof of concept that needs to be discussed and polished.Related to #6 and #19
This is an attempt to implement
source-directories
(elm.json) compatibility for both code generation and nix derivations.Background
Elm make performs lookups for modules based on optional
source-directories
attr inelm.json
file. If this attribute is not present./src
is a default destination where it looks for.elm
files.foo/A.elm
withinbar/B.elm
asimport A
andimport B
if bothfoo
andbar
are defined insource-directories
elm make foo/A.elm bar/B.elm
as well (as an entry).../../baz
Implementation
Because of this, we need to use
srcs
instead ofsrc
.srcs
attribute is currently generated in Haskell fromelm.json
. Paths like../foo
are also valid and needs to be supported. In the case of.
(current directory) nix seems to be using the name of the current directory. This means that["../foo", "."]
withinapp
results in 2 directoriesfoo app
. Because of changes in directories structure, newelm.json
must be produced during the build - done via nix.Details will be in source comments.