How to properly override source .mc files for specific device in jungles?

Hi,
I have a problem with overriding source .mc files. I'm trying to set source for low memory devices (fr45, swim2).
I created .mc files and set source path in .jungle file.
Looks like it works properly for fr45 but not for Swim2.
Is this a good way to override source files?
Any help would be appreciated. Thanks.
Here's part of my jungle file:
 
project.manifest = manifest.xml

# Reset the base source path to include only source files in the source folder. The
# default source path includes source files in the project folder and all subfolders.
base.sourcePath = source

# Low memory devices.
fr45.sourcePath = source-lowmem
garminswim2.sourcePath = source-lowmem
  • Monkey doesn't support any kind of compiler directives in source code?

  • Monkey doesn't support any kind of compiler directives in source code?

    If you mean line-by-line conditional compilation like C/C++/C#, the answer is no.

    You can exclude modules, classes, methods and non-local variables using annotations and build exclusions in jungle files. This allows you to have multiple versions of the same method for different devices, for example. This isn't a perfect solution for removing code for low memory devices, because you end up having to implement functions with empty bodies (for example), which wastes a small amount of memory.

    If you use build exclusions and empty functions, this third-party prettier extension may be able to optimize away the empty functions.

    You could also roll your own line-by-line conditional compilation solution with the C preprocessor. For example:

    forums.garmin.com/.../solution-for-line-by-line-mc-conditional-compilation

  • You can also use jungles to include different mc files based on the device or feature.  One example for me is for mapping, I have different files for devices with on-device maps and those where I draw a breadcrumb trail.  Less clutter than annotations, no functions with empty bodies, and an easier way to reduce size.

  • Here's a bit of the monkey.jungle I use for maps/no maps:

    project.manifest = manifest.xml
    srcBase=source
    resBase=resources
    
    #maps Stuff
    base.sourcePath=$(srcBase);source-nomaps
    base.resourcePath=$(resBase)
    
    # tested with maps
    fenix5x.sourcePath = $(srcBase);source-maps
    fenix5x.resourcePath = $(resBase);resources-maps

    Different source for maps, as well as some additional resources I use with the maps.

  • You can also use jungles to include different mc files based on the device or feature.  One example for me is for mapping, I have different files for devices with on-device maps and those where I draw a breadcrumb trail.  Less clutter than annotations, no functions with empty bodies, and an easier way to reduce size.

    That is literally what the original post said and they posted an example similar to yours. Not to mention that they said it didn't work for them with the garminswim2 device (for whatever reason).

    The person who responded to that asked if Monkey C supports compiler directives, which implies that they understood the original post and they are asking for an alternative. I responded to that person.

    No offense but do you bother to actually read any of the posts and understand the context in which questions are asked and answers are given?

  • Thank you all for the reply.

    I have not tested on the real device but on the simulator I got:

    Error: Out Of Memory Error
    Details: Failed invoking <symbol>
    Stack: 
      - onUpdate() at ...\SimpleTDB\source-lowmem\SimpleTDBView.mc:140 0x100005b4 

    I thought that it doesn't work because I saw that memory usage on the simulator is higher on swim2 than fr45. But when I have read the source path in error stack I understood that swim2 uses correct source path (source-lowmem). I don't know why I didn't notice it before. I'm sorry for this.

    But if the path is correct why fr45 consumes 41.8kb and swim2 - 46.5 and I got out of memory error on the sim? Looks like I missed something. Shouldn't the memory usage of these devices be the same?  

    I think I need more coffee and one day off to figure it out.

  • But if the path is correct why fr45 consumes 41.8kb and swim2 - 46.5 and I got out of memory error on the sim? Looks like I missed something. Shouldn't the memory usage of these devices be the same?  

    That's weird. For both devices, compiler.json and simulator.json are almost identical, except fr45 lacks antialiasing support. I built the Analog sample for both devices, and their memory usage is identical.