Skip to content

CMake: better detection of memap dependencies #14205

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 12 commits into from
Feb 5, 2021
Merged

Conversation

multiplemonomials
Copy link
Contributor

@multiplemonomials multiplemonomials commented Jan 28, 2021

Summary of changes

The current CMake build system is a bit naive about executing memap. It just assumes that Python was found and that memap's dependencies (prettytable and intelhex) are installed. If this is not true, you'll get errors.

This PR adds a module I wrote a while ago, CheckPythonPackage.cmake, and uses it to verify that the correct python dependencies are installed. If they aren't, a warning will be printed and memap won't be run.

Broken out from #14010

Impact of changes

CMake will now work if the python dependencies are not installed instead of erroring.

Migration actions required

None needed.

Documentation

None needed.


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

@0xc0170

@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Jan 28, 2021
@ciarmcom ciarmcom requested review from 0xc0170 and a team January 28, 2021 04:00
@ciarmcom
Copy link
Member

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

Copy link
Contributor

@0xc0170 0xc0170 left a comment

Choose a reason for hiding this comment

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

@hugueskamba as we are porting post build hooks, this comes handy. please review

# Find Python and needed packages
find_package(Python3)
include(${CMAKE_CURRENT_LIST_DIR}/CheckPythonPackage.cmake)
check_python_package(intelhex HAVE_INTELHEX)
Copy link
Contributor

Choose a reason for hiding this comment

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

we should read requirement.txt in tools/cmake as we might need few packages more (we are adding post build hooks that rely on some security modules).

Copy link
Contributor

Choose a reason for hiding this comment

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

The below could check if any of req. are not installed, print a warning otherwise we got all we need

Copy link
Collaborator

Choose a reason for hiding this comment

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

The requirements.txt in the root directory should also be checked as it is the one that has the required packages for post build operations..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is possible but it's a bit harder because it means CMake needs to parse the "platform_system==XXXX" declarations that are used in that file.

Copy link
Contributor

Choose a reason for hiding this comment

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

The requirements.txt in the root directory should also be checked as it is the one that has the required packages for post build operations..

Let's keep Cmake reqs separate and do proper clean up of deps (drop in replacement once the old tools are removed).

@0xc0170 0xc0170 changed the title Better detection of memap dependencies CMake: better detection of memap dependencies Jan 28, 2021
# Find Python and needed packages
find_package(Python3)
include(${CMAKE_CURRENT_LIST_DIR}/CheckPythonPackage.cmake)
check_python_package(intelhex HAVE_INTELHEX)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The requirements.txt in the root directory should also be checked as it is the one that has the required packages for post build operations..

@multiplemonomials
Copy link
Contributor Author

@0xc0170 I just added a requirements.txt parser based on your request. I will warn though, it's a bit fragile and could break if weird package names are used.

@multiplemonomials
Copy link
Contributor Author

Also, what specifically is your policy about extra lines, could you please explain? I seem to have run afoul of it pretty badly.

@multiplemonomials
Copy link
Contributor Author

Oh one other thing. While you guys are here, do you know why the requirements.txt has so many pinned versions and "must be older than X" versions? This really causes problems trying to set up an environment, and in my experience it seems to run just fine with the latest/default versions of all packages.

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 28, 2021

Oh one other thing. While you guys are here, do you know why the requirements.txt has so many pinned versions and "must be older than X" versions? This really causes problems trying to set up an environment, and in my experience it seems to run just fine with the latest/default versions of all packages.

We should start fixing this. Therefore we create own req file for CMake, so we can add only what we use and test the latest packages. For some historic reasons older versions were used, it's not true anymore in many cases.

@0xc0170 I just added a requirements.txt parser based on your request. I will warn though, it's a bit fragile and could break if weird package names are used.

Can you illustrate ?

Also, what specifically is your policy about extra lines, could you please explain? I seem to have run afoul of it pretty badly.

I don't follow, can you reference the lines ? We got one extra line at end of every file (I noticed Github showed in some files here there is no empty line at the end of the files).

@multiplemonomials
Copy link
Contributor Author

multiplemonomials commented Jan 28, 2021

Can you illustrate ?

Added it to this PR: 5d77b3e

I don't follow, can you reference the lines ? We got one extra line at end of every file (I noticed Github showed in some files here there is no empty line at the end of the files).

Hugues asked me to add some extra blank lines, which I did. I'm just wondering since I'm required to add them, what is the formal policy on where blank lines are needed?

@multiplemonomials
Copy link
Contributor Author

Oh wait, you meant illustrate about the weird package names. I made the following assumptions:

  • No package names contain spaces or equals signs
  • For a package named X, lowercase(X) is the importable name of that package
  • The requirements file has either a newline, a "<", a ">", or a "=" after each package name.

@hugueskamba
Copy link
Collaborator

Can you illustrate ?

Added it to this PR: 5d77b3e

I don't follow, can you reference the lines ? We got one extra line at end of every file (I noticed Github showed in some files here there is no empty line at the end of the files).

Hugues asked me to add some extra blank lines, which I did. I'm just wondering since I'm required to add them, what is the formal policy on where blank lines are needed?

I asked to add a new line at the end of the file.
https://stackoverflow.com/questions/2287967/why-is-it-recommended-to-have-empty-line-in-the-end-of-a-source-file

0xc0170
0xc0170 previously approved these changes Jan 29, 2021
@mergify mergify bot added needs: CI and removed needs: review labels Jan 29, 2021
@ciarmcom ciarmcom added the stale Stale Pull Request label Jan 31, 2021
@ciarmcom
Copy link
Member

This pull request has automatically been marked as stale because it has had no recent activity. @ARMmbed/mbed-os-maintainers, please start CI to get the PR merged.

@mergify mergify bot dismissed 0xc0170’s stale review February 2, 2021 03:48

Pull request has been modified.

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 2, 2021

CI restarted


# set OUTPUT_VAR to whether PACKAGENAME was found
function(check_python_package PACKAGENAME OUTPUT_VAR)

Copy link
Contributor

Choose a reason for hiding this comment

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

@multiplemonomials In Mbed OS CMake code we are not using newline after function starts, Could you please remove the new line?


if(DEFINED ${OUTPUT_VAR})
if(${OUTPUT_VAR})

Copy link
Contributor

Choose a reason for hiding this comment

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

@multiplemonomials In Mbed OS CMake code we are not using newline after if condition, Could you please remove the new line?

if("${PY_INTERP_FOR_${OUTPUT_VAR}}" STREQUAL "${Python3_EXECUTABLE}")
set(NEED_TO_RUN_CHECK FALSE)
endif()

Copy link
Contributor

Choose a reason for hiding this comment

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

@multiplemonomials, Same comment as before, could you please remove the new line?


set(${OUTPUT_VAR} ${HAVE_PACKAGE} CACHE BOOL "Whether the Python package ${PACKAGENAME} was found" FORCE)
mark_as_advanced(${OUTPUT_VAR})

Copy link
Contributor

Choose a reason for hiding this comment

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

@multiplemonomials, Same comment as before, could you please remove the new line?

# Check python packages from requirements.txt
file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/requirements.txt PYTHON_REQUIREMENTS)
foreach(REQUIREMENT ${PYTHON_REQUIREMENTS})

Copy link
Contributor

Choose a reason for hiding this comment

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

@multiplemonomials, Same comment as before, could you please remove the new line?


# Look for a string from the start of each line that does not contain "<", ">", "=", or " ".
if(REQUIREMENT MATCHES "^([^<>= ]+)")

Copy link
Contributor

Choose a reason for hiding this comment

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

@multiplemonomials, Same comment as before, could you please remove the new line?

if(NOT HAVE_PYTHON_${PACKAGE_NAME_UCASE})
message(WARNING "Missing Python dependency ${PACKAGE_NAME}")
endif()

Copy link
Contributor

Choose a reason for hiding this comment

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

@multiplemonomials, Same comment as before, could you please remove the new line?

Comment on lines 44 to 46

message(FATAL_ERROR "Cannot parse line \"${REQUIREMENT}\" in requirements.txt")

Copy link
Contributor

Choose a reason for hiding this comment

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

@multiplemonomials, Same comment as before, could you please remove the new line?

set(HAVE_MEMAP_DEPS TRUE)
else()
set(HAVE_MEMAP_DEPS FALSE)

Copy link
Contributor

Choose a reason for hiding this comment

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

@multiplemonomials, Same comment as before, could you please remove the new line?

@mergify mergify bot added needs: work and removed needs: CI labels Feb 2, 2021
@multiplemonomials
Copy link
Contributor Author

OK just rebased

@mergify mergify bot dismissed 0xc0170’s stale review February 3, 2021 22:17

Pull request has been modified.

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 4, 2021

CI restarted

@mbed-ci
Copy link

mbed-ci commented Feb 4, 2021

Jenkins CI Test : ❌ FAILED

Build Number: 4 | 🔒 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

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 4, 2021

CI was aborted. We had some issue with it, I'll restart today.

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 4, 2021

CI started

@mbed-ci
Copy link

mbed-ci commented Feb 4, 2021

Jenkins CI Test : ✔️ SUCCESS

Build Number: 5 | 🔒 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_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_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_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-test ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️

@0xc0170 0xc0170 removed the needs: CI label Feb 5, 2021
@0xc0170 0xc0170 merged commit dd33463 into ARMmbed:master Feb 5, 2021
@mergify mergify bot removed the ready for merge label Feb 5, 2021
@mbedmain mbedmain added release-version: 6.8.0 Release-pending and removed release-type: patch Indentifies a PR as containing just a patch Release-pending labels Feb 16, 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.

7 participants