Mos.yml conditional files in fs directory

#1
  1. My goal is: [describe your goal]
    To be able to conditionally select in the yml file which files to include from the fs directory

  2. My actions are: [describe your actions - code, commands, etc]

  3. The result I see is: [show the result - log, etc]
    If I have fileA. fileB and fileC in the fs directory I would like to be able to select which of these to compile into the esps32 directory.

  4. My expectation & question is: [describe your expectation and your question]
    Select in yml file to conditionally add a subset of possible files from the fs directory into the product file system

#2

You can use build_vars to select the files to included in the filesystem:

filesystem:
  - fs/common0

build_vars:
  FILES: 0

conds:
  - when: build_vars.FILES == "0"
    apply:
      filesystem:
        - fs/f00
        - fs/f01
  - when: build_vars.FILES == "1"
    apply:
      filesystem:
        - fs/f10
        - fs/f11

Build with the option e.g. --build-var FILES=1

mos ls
ca.pem
common0
conf0.json
f10
f11
1 Like
#3

where should the files be located in my APP structure? I tried putting them in src and the root, but they didn’t show up after the build (mos ls)

#4

That’s what you were asking for.

#6

What I see happening is that every file I put in the fs directory ends up in the product fs directory. It doesn’t matter what I set the conditions too. Therefor I assumed the conditional files needed to go somewhere else for the build process.

#7

Did you add --build-var FILES=1 to the build command?

#8

No, I added it to the other build_vars in the mos.yml file

#9

Did you keep the top level filesystem section?

filesystem:
  - fs

Remove it, otherwise it will add all the files in the fs directory regardless the selection made by the build_vars.

#10

No luck with any of your suggestions. It seems I either get everything in the fs directory or nothing.
Updated to 2.14 - no difference.
Is there a “don’t include” option to remove from fs directory on build?

#11

I’m not sure what you are doing wrong.

Here is an example which uses the idea I presented earlier.

#12

definitely something strange going on. I downloaded your example from git. Built it and flashed it. ran “mos ls” and got back:
image
Build was done thru the mos build command in the GUI (2.14.0)

#13

Thru command line:

#14

Yes, I tested too on Windows and it does not work.
I usually build on Debian where it works.

#15

I found a workaround that works on Windows:

filesystem:
  - fs\dummy
  - fs/common0
1 Like
#16

Wow good find and thanks for posting the example in GIT.
Big help for the next person that needs this.