Skip to content
Discussions/App Development/Daml.yaml source parameter, is it a single value or a listForum ↗

Daml.yaml source parameter, is it a single value or a list

App Development16 posts438 views3 likesLast activity Feb 2022
CO
cohen.avrahamOP
Feb 2022

in the daml.yaml file, there is a parameter called “source” which its default value is “daml”. This is the root folder of the project.
Can I have 2 folders defined for it? If not, how can I import a daml source file which is not under that root folder? (for example, a third party code which I want to use in my project, without placing it under my main root folder).

Thanks,

CO
cocreature
Feb 2022

It can only reference a single folder. For third-party code, I recommend including it as a dependency by building it separately and then pointing to the resulting DAR in your daml.yaml. I recommend the Working with Dependencies section of the Daml intro for an introduction for this.

CO
cohen.avraham
Feb 2022

G-d willing

Thanks @cocreature, I am aware to the dependencies in daml an worked with it already.
The reason for my question was since I opened a project in daml in which it contained 2 folders that had daml source files inside. One of the folders was the one that was defined in the daml.yaml file, while the other wasn’t (of course). So, I thought maybe there is a way to link that folder to the main source folder in some way.
Since I don’t find any reason to do it (creating 2 source folders under the project main folder), I thought that maybe there is a way to link the 2 folders.

CO
cocreature
Feb 2022

There is the option of symlinking one into the other and there are also some other ways to make it work, see Behaviour of relative paths in `source:` in multi-dar projects - #6 by cocreature for some details.

That said, I’d usually recommend against that. I think you’re much better off in splitting things into separate packages. Do you have a specific reason why that’s not an option for you?

CO
cohen.avraham
Feb 2022

Well, I am dealing with an ongoing project that is already running (and I cannot change its design). So, I need to find a way to import one source file from root directory A into a daml file which is under root directory B.

By the way, I read your comment in the attached link, however, I didn’t really understand how to do it exactly.
So, assuming my project folder is Finance, which has a “daml” folder inside. This “daml” folder is defined in the “source” parameter inside the daml.yaml file.
Inside the Finance folder there is another root directory (not under the “daml” folder) named “CreditCards”. Inside the “CreditCards” folder I have “Cards” folder that contains daml source files.
How can I define the “CreditCards” folder to be used in my project?

CO
cocreature
Feb 2022

If the third-party code is in an already deployed project, then it’s not just recommended to refer to it as a (data-)dependency, it is required. If you include it as a source file in your own project then you’ll produce a copy of the template with the same module & template name but a different package id. To the ledger that template is completely separate from the original one so you’re not actually referring to the already running copy.

As for the second part, you can use build-options: ["--include=Finance/CreditCards/Cards"] but again this is not going to work. You’ll produce a copy of the template not a reference to the original one.

CO
cohen.avraham
Feb 2022
cocreature:

gle folder. For third-party code, I recommend including it as a dependency by building it separately and then pointing to the resulting DAR in you

The “CreditCards” folder is not going to be built twice, as it is part of the same project. . Just think of 2 different responsibilities in the same project where each one is responsible to a different root directory. Also, keep in mind that I need to accept this structure. So my question is how can I do it?

Let’s make it more specific. I will use shorter names for simplicity. There is a project folder named: “A”, and the root folder in daml.yaml is set to “B” (which is, of course, a sub folder of “A”). Inside folder “B” I have a sub folder named “C” which has a file named File1.daml inside of it.
The definition of File1.daml is “module C.File1 where”
Now, folder “A” has another sub folder named “D”, which also has a sub folder named “E”. Inside “E” there is a file named “File2.daml” which is defined as: “module E.File2 where”.
What I need to do is import File2 into File1. And when I type inside File1 the following line:
import E.File2, this line is generating an error (since folder E is not a sub folder of “B”). Here is a tree view of the project.
image

I need to import File2.daml into File1.daml. How can I do it?

CO
cocreature
Feb 2022

What is the module name of File1 and File2, i.e., the module ??? line at the top of those files?

CO
cohen.avraham
Feb 2022

for the example let’s assume:
module C.File1 where…
module E.File2 where…

CO
cocreature
Feb 2022

Alright, then add the following to your daml.yaml:

build-options:
  - --include=D

Then both Daml studio and daml build should be able to resolve the import.

Keep in mind though the caveat I mentioned in https://discuss.daml.com/t/behaviour-of-relative-paths-in-source-in-multi-dar-projects/3988/6: Only modules that are referenced from one of the roots, i.e. ,the files in your source directory will be included in the DAR. There is no way to change this at the moment. However, you can create a module somewhere within your source directory which just imports all other modules to make sure they are included.

CO
cohen.avraham
Feb 2022

Thank you very much @cocreature,
I do need to learn more thoroughly that specific post you linked to understanding exactly how it works.
I appreciate it a lot.

CO
cohen.avraham
Feb 2022

I added to the daml.yaml file the following line:
build-options:

  • –include=D
    and, in the C.File1,daml file I added the following line:
    import E.File2
    However, it did not work for me. It says:
    "Could not find module `E.Flie2’
    It is not a module in the current program, or in any known package.

Any idea what is the problem, or am I missing something in here?

Thanks,

CO
cocreature
Feb 2022

Not sure if you just typoed this here or have an actual typo but the error message says E.Flie2 instead of E.File2. If that’s not it, can you share the test project you’re using here?

CO
cohen.avraham
Feb 2022

G-d willing

It was just a typo in here (I didn’t do any copy & paste).
I attached the file as a reference for my sample code
daml code.zip (516.4 KB)

CO
cocreature
Feb 2022

I think you might have forgotten to save that file. Your zip file just includes an empty file which produces this compile error:

Compiling root to a DAR.
File:     D/E/File2.daml
Hidden:   no
Range:    1:1-2:1
Source:   parser
Severity: DsError
Message:  Missing module name, e.g. 'module ... where'.

After adding module E.File2 where to that file, the file is found and compiled properly and you get a type error in the other file:

Compiling root to a DAR.
File:     B/C/File1.daml
Hidden:   no
Range:    8:13-8:21
Source:   typecheck
Severity: DsError
Message: 
  B/C/File1.daml:8:13: error:
  • Expecting one more argument to ‘Scenario’
  Expected a type, but ‘Scenario’ has kind ‘* -> *’
  • In the type signature: testScript : Scenario

After fixing that by changing it to testScript : Scenario () the project compiles as expected.

CO
cohen.avraham
Feb 2022

G-d willing

@cocreature, both of the things that you mentioned were typed correctly on my side - apparently, both files weren’t saved, and, the problem still exists on my side.
However, I restarted Studio Code and the problem is gone. Now it works. I guess there is some kind of refresh in Studio Code in relation to Daml (at least on my machine).
Thank a lot I really appreciate your help as it is now works exactly as needed. :+1:

← Back to Discussions