Skip to content
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

Problem with overriding mbed_lib.json configuration for private libraries #491

Open
byq77 opened this issue Jan 31, 2021 · 3 comments
Open

Comments

@byq77
Copy link

byq77 commented Jan 31, 2021

Problem description

Using mbed_app.json I am able to override configuration for my target that is defined by core mbed framework. However, if I try to override options defined by my own library it won't work.

Reproduction

Content of my lib directory:

lib
├── foo-lib
│   ├── foo.cpp
│   ├── foo.h
│   └── mbed_lib.json
└── README.md

mbed_lib.json looks like this:

{
    "name":"foo-lib",
    "macros":["FOO_STRING_1=\"FOO1\"" , "FOO_STRING_2=\"FOO2\""],
    "config":
    {
        "option":
        {
            "help": "Select foo string",
            "macro_name": "FOO_OPTION",
            "accepted_values": [0,1],
            "value": 0,
            "required": false
        }
    }
}

platform.ini:

[env:core2]
platform = ststm32
framework = mbed
board = core2
build_flags = 
    -I$PROJECTSRC_DIR/TARGET_CORE2
    -D PIO_FRAMEWORK_MBED_RTOS_PRESENT
    -D PIO_FRAMEWORK_EVENT_QUEUE_PRESENT
    -D MBED_BUILD_PROFILE_RELEASE
platform_packages =
    framework-mbed @ ~6.51506.0

core2 is my custom board. mbed_app.json:

{
    "config": {},
    "macros": [],
    "target_overrides": {
        "CORE2": {
            "events.shared-dispatch-from-application": 0,
            "events.shared-eventsize": 512,
            "events.shared-stacksize": 2048,
            "platform.default-serial-baud-rate": 230400,
            "platform.stdio-baud-rate": 230400,
        }
    }
}

My project builds without any problem if I don't override foo-lib option. In addition to that, generated mbed_config.h contains following lines:

// PlatformIO Library Dependency Finder (LDF)
#define FOO_STRING_1 "FOO1"
#define FOO_STRING_2 "FOO2"
#define FOO_OPTION 0

so it seems that mbed_lib.json is processed correctly. However, if I modify mbed_app.json:

{
    "target_overrides": {
        "CORE2": {
            "foo-lib.option": 1,
            ...
        }
    }
}

the build fails with error:

Attempt to override undefined parameter 'foo-lib.option' in 'application[CORE2]'
mbed build API internal error
@byq77
Copy link
Author

byq77 commented Feb 2, 2021

I found another issue that is connected to the one above. If I add my custom library as dependency using lib_deps (github url) in platformio.ini no mbed configuration is generated despite library containing mbed_lib.json. Also platformio dependency manager adds library.json file to that library:

{
  "name": "core2-imu-driver",
  "version": "0.0.0+20210202130906"
}

If I move said library from libdeps to my project's lib directory the result is the same. However, if I remove the library.json file from that library LDF system successfully generates the configuration.

@Copper-Bot
Copy link

Hi,

I confirm the last message from @byq77. The library.json has to be deleted to get PIO generates the configuration from the mbed_lib.json of the lib. Do we have to open a new issue about that ?

I am using PIO 5.2.2 on Windows 10.

@Copper-Bot
Copy link

Copper-Bot commented Oct 27, 2021

Hello again @byq77,

I just resolve the problem about the mbed_lib.json not used by PIO:
You have to add the right builder in the library.json file, in our case MbedLibBuilder:

{
  "name": "lib_test_pio",
  "version": "0.0.1",
  "description": "test lib to get mbed_lib json working",
  "keywords": "test, pio, mbed_lib",
  "build": {
    "builder": "MbedLibBuilder"
  }
}

I recommend adding the library.json file in your library repository, to get sure PIO will interpret correctly.

But for other libraries around the web that doesn't have a library.json file ... well that could be a problem, because PIO use PlatformIOLibBuilder by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants