Skip to content

CMake: remove MBED_PATH and use <PROJECT-NAME>_SOURCE_DIR/MODULE_PATH instead #14516

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

Merged
merged 8 commits into from
Apr 15, 2021

Conversation

0xc0170
Copy link
Contributor

@0xc0170 0xc0170 commented Apr 8, 2021

Summary of changes

This PR is helping UNITTESTS so it should be merged prior #14426 - they need to use files within Mbed OS and already defines project().

We used MBED_PATH previously, it's own defined variable for Mbed OS project root. Usage were to reference CMake scripts or files out of it's current source tree.

The approach should be to use cmake module path for listfiles like .cmake to find them. Note, due to our target labels, some CMake files are hidden so include must be also protected if it touches conditionally added library (for instance TFM).

For CMakeLists.txt files, use mbed-os_SOURCE_DIR - this is useful for CMakeLists.txt. For listfiles like .cmake files, please use CMAKE_CURRENT_LIST_DIR (as they are included).

Impact of changes

Migration actions required

Documentation


Pull request type

[x] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[x] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers


This enables multiple variables we can use. One of them is source dir for a project.

It will replace MBED_PATH in the tree.
@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Apr 8, 2021
@ciarmcom ciarmcom requested a review from a team April 8, 2021 13:00
@ciarmcom
Copy link
Member

ciarmcom commented Apr 8, 2021

@0xc0170, thank you for your changes.
@ARMmbed/mbed-os-maintainers please review.

@0xc0170
Copy link
Contributor Author

0xc0170 commented Apr 8, 2021

@rwalton-arm @rajkan01 Please review

@0xc0170
Copy link
Contributor Author

0xc0170 commented Apr 8, 2021

To do once approved:

  • I'll check docs if we reference MBED_PATH there
  • clean up examples, remove MBED_PATH there as well as it's not required anymore

@rajkan01
Copy link
Contributor

rajkan01 commented Apr 8, 2021

@0xc0170 Instead of going with mbed-os_SOURCE_DIR, we can make use of CMake PROJECT_NAME and CMAKE_PROJECT_NAME variable like for example ${PROJECT_NAME}_SOURCE_DIR what is your thoughts

@0xc0170
Copy link
Contributor Author

0xc0170 commented Apr 8, 2021

@0xc0170 Instead of going with mbed-os_SOURCE_DIR, we can make use of CMake PROJECT_NAME and CMAKE_PROJECT_NAME variable like for example ${PROJECT_NAME}_SOURCE_DIR what is your thoughts

The current way it is to explicitly use mbed-os project name as a reference rather than the last/current project name. Wouldn't this be a problem when Mbed OS is taken as a component or we have multiple projects in the tree ?

@@ -3,10 +3,10 @@

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../.. CACHE INTERNAL "")
set(mbed-os_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../.. CACHE INTERNAL "")
Copy link
Contributor

@rajkan01 rajkan01 Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a current implementation, every greentea test has its CMakeLists.txt similar to the application CMake. Why do we need to change into mbed-os_SOURCE_DIR? this will be a problem when we do "Separate GreenTea from Mbed"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, this is setting it. I missed it during refactoring, I'll remove all

@rajkan01
Copy link
Contributor

rajkan01 commented Apr 8, 2021

@0xc0170 Instead of going with mbed-os_SOURCE_DIR, we can make use of CMake PROJECT_NAME and CMAKE_PROJECT_NAME variable like for example ${PROJECT_NAME}_SOURCE_DIR what is your thoughts

The current way it is to explicitly use mbed-os project name as a reference rather than the last/current project name. Wouldn't this be a problem when Mbed OS is taken as a component or we have multiple projects in the tree ?

In the case of mbed os is taken as a component or multiple projects in the tree, how the way the CMake file gets included decides the PROJECT_NAME but mbed-os root CMake retains PROJECT_NAME as a mbed-os, but it will be a problem

set(TEST_TARGET mbed-connectivity-ble-cordio-hci-driver)

include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake)
include(${mbed-os_SOURCE_DIR}/tools/cmake/mbed_greentea.cmake)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed to comment here, Do we need to change this as well because if it is top-level CMake similar to application one then PROJECT_NAME and CMAKE_PROJECT_NAME will be mbed-connectivity-ble-cordio-hci-driver and the mbed-os_SOURCE_DIR variable is not yet created

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test should not care where it is.

How we create greentea shall be changed and this MBED_PATH should be fixed there. I'll create a separate issue for greentea tests, how they use MBED_PATH and get mbed-os in. I'll revert the changes here.

I'll keep this to fix the Mbed OS files (excluding greentea tests).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #14523 and I'll revert now greentea tests changes.

@0xc0170 0xc0170 force-pushed the fix-cmake-project-name branch 2 times, most recently from 2e4ce1c to 25c5de3 Compare April 8, 2021 16:03
@0xc0170
Copy link
Contributor Author

0xc0170 commented Apr 8, 2021

Updated, greentea tests removed from this PR. They need different fix unfortunately.

@@ -3,7 +3,7 @@

set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")

include(${MBED_PATH}/tools/cmake/app.cmake)
include(${mbed-os_SOURCE_DIR}/tools/cmake/app.cmake)
Copy link
Contributor

@rajkan01 rajkan01 Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we fix this as part of #14523? and revert this change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

rajkan01
rajkan01 previously approved these changes Apr 9, 2021
Copy link
Contributor

@rajkan01 rajkan01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mergify mergify bot added needs: CI and removed needs: review labels Apr 9, 2021
@@ -1,7 +1,7 @@
# Copyright (c) 2020-2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

include(${MBED_PATH}/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/mbed_set_post_build_tfm.cmake)
include(${mbed-os_SOURCE_DIR}/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/mbed_set_post_build_tfm.cmake)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we can use CMAKE_MODULE_PATH to avoid hard coding all of the include paths. We could set the module directories in mbed-os/CMakeLists and then include modules with e.g include(mbed_set_post_build_tfm) in other files. The benefit of this approach, in my view, is if we ever move the location of these files we will have fewer changes to make.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, I'll check how we can create the modules for our scripts

@@ -17,7 +17,7 @@ function(mbed_post_build_tfm_sign_image
set(mbed_target_name ${mbed_target})
set(post_build_command
COMMAND ${Python3_EXECUTABLE}
${MBED_PATH}/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/generate_mbed_image.py
${mbed-os_SOURCE_DIR}/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/generate_mbed_image.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this not be reduced to ${CMAKE_CURRENT_LIST_DIR}/generate_mbed_image.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are in the targets area, not in the tools so current list dir points to targets/ somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, this path is incorrect. I'll fix it.

@@ -12,11 +12,11 @@ include(${MBED_CONFIG_PATH}/mbed_config.cmake)
# Load toolchain file
if(NOT CMAKE_TOOLCHAIN_FILE OR MBED_TOOLCHAIN_FILE_USED)
set(MBED_TOOLCHAIN_FILE_USED TRUE CACHE INTERNAL "")
include(${MBED_PATH}/tools/cmake/toolchain.cmake)
include(${mbed-os_SOURCE_DIR}/tools/cmake/toolchain.cmake)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${CMAKE_CURRENT_LIST_DIR}/toolchain.cmake?

Copy link
Contributor Author

@0xc0170 0xc0170 Apr 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, fixed in the later commit.

endif()

# Specify available build profiles and add options for the selected build profile
include(${MBED_PATH}/tools/cmake/profile.cmake)
include(${mbed-os_SOURCE_DIR}/tools/cmake/profile.cmake)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${CMAKE_CURRENT_LIST_DIR}/profile.cmake?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, fixed in the later commit.

@@ -3,7 +3,7 @@

set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")

include(${MBED_PATH}/tools/cmake/app.cmake)
include(${mbed-os_SOURCE_DIR}/tools/cmake/app.cmake)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${CMAKE_CURRENT_LIST_DIR}/app.cmake?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, fixed in the later commit. I realized we should use list dir in tools

@@ -29,4 +29,4 @@ else()
endif()
endif()

include(${MBED_PATH}/tools/cmake/profiles/${LOWERCASE_CMAKE_BUILD_TYPE}.cmake)
include(${mbed-os_SOURCE_DIR}/tools/cmake/profiles/${LOWERCASE_CMAKE_BUILD_TYPE}.cmake)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${CMAKE_CURRENT_LIST_DIR}/profiles/${LOWERCASE_CMAKE_BUILD_TYPE}.cmake?

@@ -12,11 +12,11 @@ include(${MBED_CONFIG_PATH}/mbed_config.cmake)
# Load toolchain file
if(NOT CMAKE_TOOLCHAIN_FILE OR MBED_TOOLCHAIN_FILE_USED)
set(MBED_TOOLCHAIN_FILE_USED TRUE CACHE INTERNAL "")
include(${mbed-os_SOURCE_DIR}/tools/cmake/toolchain.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/toolchain.cmake)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see you changed these in a later commit. It would be easier to review if we didn't make changes to already reviewed commits later on in the PR.

Copy link
Contributor Author

@0xc0170 0xc0170 Apr 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not want to push force while it's being reviewed but I can clean it up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be easier to review if we didn't make changes to already reviewed commits later on in the PR.

I do not follow. I fixed earlier commit in the subsequent one. how else can I make review easier without rebasing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually would force push, but marking them as fixup commits would also work for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for force push but that is hard for some reviewers so I can mark as fixu and later rebase to get them out of history.

@mbed-ci
Copy link

mbed-ci commented Apr 13, 2021

Jenkins CI Test : ❌ FAILED

Build Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM
jenkins-ci/mbed-os-ci_cmake-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️

@0xc0170
Copy link
Contributor Author

0xc0170 commented Apr 13, 2021

Errors are legit, I'll fix them

@0xc0170 0xc0170 force-pushed the fix-cmake-project-name branch from b16a3b1 to 3abf9d5 Compare April 14, 2021 12:06
0xc0170 added 7 commits April 14, 2021 13:09
- list files included via module path
- <project-name>_SOURCE_DIR for sources that are out of the current processed CMake
- CMAKE_CURRENT_LIST_DIR for listfiles
As we still use target labels, TFM is not visible to CMake. Protect include of their scripts with the same mechanism.
Excluding greentea tests, they will be fixed separately (more work needed).
All files within tools/cmake can now include within tools/cmake. We do not expose
internal folders like core/profiles/toolchains.
They should be included via toolchain file (mbed_toolchain in our case).
CMAKE_CURRENT_LIST_DIR behaves differently in functions. We store it in the CMakeLists itself, so anyone
calling a function would get the actual list dir where the scripts are.

To illustrate: if I call a function from src/CMakelists.txt, function located in src/scripts, `CMAKE_CURRENT_LIST_DIR` in the function would point
to the src/ folder but not to src/scripts.
To avoid conflicts as we expose our CMake list files via CMAKE_MODULE_PATH. Some files already include it, this
aligns the rest of files.

I leave app.cmake as it is - it's user facing and it would be breaking change. We can clean this one for the next major version.
Update CMAKE_MODULE_PATH at once place.

Note, we update also CMAKE_MODULE_PATH in app.cmake. This is temporary until we get a proper way to include
Mbed Os (removing app.cmake need to be included by an application).
@0xc0170 0xc0170 force-pushed the fix-cmake-project-name branch from 3abf9d5 to 121c828 Compare April 14, 2021 12:10
@0xc0170
Copy link
Contributor Author

0xc0170 commented Apr 14, 2021

I fixed an issue with TFM. I can't still build MUSCA though - a path in python script is incorrect. :/ I'll find out what has changed.

@0xc0170
Copy link
Contributor Author

0xc0170 commented Apr 14, 2021

CI started, I would like to see if it can reproduce my testing locally and if so will compare the logs.

@mbed-ci
Copy link

mbed-ci commented Apr 14, 2021

Jenkins CI Test : ✔️ SUCCESS

Build Number: 2 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-test ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️
jenkins-ci/mbed-os-ci_tfm-integration ✔️

@mbed-ci
Copy link

mbed-ci commented Apr 14, 2021

Jenkins CI Test : ✔️ SUCCESS

Build Number: 3 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️
jenkins-ci/mbed-os-ci_cmake-example-test ✔️
jenkins-ci/mbed-os-ci_tfm-integration ✔️

@0xc0170
Copy link
Contributor Author

0xc0170 commented Apr 15, 2021

@rajkan01 I'll merge this now, you can update unittests to remove using MBED_PATH completely.

@0xc0170 0xc0170 merged commit 1fd4cfd into ARMmbed:master Apr 15, 2021
@0xc0170 0xc0170 deleted the fix-cmake-project-name branch April 15, 2021 12:00
@mergify mergify bot removed the ready for merge label Apr 15, 2021
@mbedmain mbedmain removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants