Skip to content

Commit

Permalink
Improved platform filtering for the package mgmt
Browse files Browse the repository at this point in the history
  • Loading branch information
a9183756-gh committed Sep 20, 2020
1 parent d9cbd82 commit 953b2e6
Show file tree
Hide file tree
Showing 37 changed files with 789 additions and 364 deletions.
160 changes: 11 additions & 149 deletions Arduino-toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -86,159 +86,20 @@ if (NOT _BOARD_SETUP_COMPLETED)
endif()
endif()

# Wrap it in a function so that the scope of variables are within
# the function
function(IndexBoardsAndSetupBoard)
# Wrap it in a function so that the scope of variables are within
# the function
function(BoardSetupWorkflow)

# Find ARDUINO_INSTALL_PATH, ARDUINO_PACKAGE_PATH and
# ARDUNIO_SKETCHBOOK_PATH
InitializeArduinoPackagePathList()

# Download and index the packages, and install the platforms from the
# given board manager URL list if any
set(_json_file "")
set(_install_url "")
set(_ref_url_list)
if (NOT "${ARDUINO_BOARD_MANAGER_URL}" STREQUAL "")

set(ARDUINO_BOARD_MANAGER_URL "${ARDUINO_BOARD_MANAGER_URL}"
CACHE STRING "Arduino Board Manager URL" FORCE)

# Split comma seperated list of URLs
string(REPLACE "," ";" _url_list
"${ARDUINO_BOARD_MANAGER_URL}")

# First one in the list should contain the required board
list(GET _url_list 0 _install_url)
set(_ref_url_list "${_url_list}")
list(REMOVE_AT _ref_url_list 0)

# Download the package of the install URL
if (NOT EXISTS "${_install_url}")
BoardManager_DownloadPackage(${_install_url}
JSON_FILES_LIST _json_file REQUIRED)
else()
set(_json_file "${_install_url}")
endif()
IndexArduinoPackages(${_json_file})

set(ARDUINO_ENABLE_PACKAGE_MANAGER TRUE)

else()

IndexArduinoPackages()

endif()

if (NOT "${ARDUINO_BOARD_MANAGER_REF_URL}" STREQUAL "")
set(ARDUINO_BOARD_MANAGER_REF_URL "${ARDUINO_BOARD_MANAGER_REF_URL}"
CACHE STRING
"Arduino Board Manager URL only for reference platforms/tools"
FORCE)
endif()

list(APPEND _ref_url_list ${ARDUINO_BOARD_MANAGER_REF_URL})
# Download all other reference only URLs
if (NOT "${_ref_url_list}" STREQUAL "")
BoardManager_DownloadPackage(${_ref_url_list}
JSON_FILES_LIST _ref_json_files)
if (_ref_json_files)
IndexArduinoPackages(${_ref_json_files})
endif()
endif()

if (DEFINED ARDUINO_NO_INSTALLED_REFERENCES)
set(ARDUINO_NO_INSTALLED_REFERENCES
"${ARDUINO_NO_INSTALLED_REFERENCES}" CACHE STRING
"Set this option to ignore any installed platforms as references"
FORCE)
endif()

# Index all the pre-installed packages
if (NOT "${ARDUINO_BOARD_MANAGER_URL}" STREQUAL "" AND
NOT "${ARDUINO_NO_INSTALLED_REFERENCES}")

IndexArduinoPackages()

endif()

# Find the necessary platforms
set(_needed_pl_list)
set(_report_error TRUE)
packages_find_platforms(pl_list JSON_FILES ${_json_file}
INSTALL_PREFERRED)
if(NOT "${ARDUINO_PLATFORM}" STREQUAL "")

# Find the platforms that can be installed from the board given
platforms_find_platform_in_list("${pl_list}" "${ARDUINO_PLATFORM}"
_needed_pl_list)

elseif (NOT "${ARDUINO_BOARD}" STREQUAL "")

# Find the platforms that can be installed from the board given
boards_find_platform_in_list("${pl_list}" "${ARDUINO_BOARD}"
_needed_pl_list)

elseif (NOT "${ARDUINO_BOARD_MANAGER_URL}" STREQUAL "")

# install all the platforms in the board manager URL, if board
# or platform is not specified explicitly
set(_needed_pl_list "${pl_list}")

else()

# In case of no mention of board or platform or board manager URL,
# Package management is used only for installing reference tools
# and platforms. So no need to report error.
set(_report_error FALSE)
endif()

if(NOT _needed_pl_list AND _report_error)
#message("Available platforms: ${pl_list}")
#message(WARNING
# "Not sure which Arduino platform is needed! Provide the correct "
# "board manager URL of the board using the option "
# "-DARDUINO_BOARD_MANAGER_URL=<URL>.")
endif()

# Filter out those that are not installed
set(_install_pl_list "")
foreach(_needed_pl IN LISTS _needed_pl_list)
packages_get_platform_property("${_needed_pl}" "/installed"
_b_installed)
if (NOT _b_installed)
list(APPEND _install_pl_list "${_needed_pl}")
endif()
endforeach()

# Install the necessary platforms. TODO Unnecessary installation for
# boards that are already installed
if (_install_pl_list)
if (ARDUINO_ENABLE_PACKAGE_MANAGER)
foreach(pl_id IN LISTS _install_pl_list)
BoardManager_InstallPlatform("${pl_id}" RESULT_VARIABLE
_result)
if (NOT _result EQUAL 0)
message(WARNING "Installing platform '${pl_id}' failed!!! "
"Corresponding boards won't be available for tests.")
endif()
endforeach()
else()
#string(REPLACE ";" ", " _install_pl_list "${_install_pl_list}")
#message(WARNING
# "Need to install the Arduino boards ${_install_pl_list}. "
# "Try with the option -DARDUINO_ENABLE_PACKAGE_MANAGER=TRUE, "
# "for local installation in the build directory.")
endif()
endif()

# Index all the installed platforms and boards
IndexArduinoBoards("ard_boards" JSON_FILES ${_json_file})
# Call the common workflow for setting up the platform, which includes
# installing the necessary platform (if package management is enabled),
# and indexing the boards based on the platform. The platform to be
# setup is identified using the board options which we already loaded.
PlatformSetupWorkflow()

# Select one of the boards as selected in BoardOptions.cmake or in
# cmake-gui or other mechanisms. If none selected, this call will
# generate options in CMake Cache and BoardOptions.cmake to allow
# later selection of the board
# later selection of the board.
SelectArduinoBoard(ard_boards)
set(ARDUINO_BOARD_IDENTIFIER "${ARDUINO_BOARD_IDENTIFIER}"
PARENT_SCOPE)
Expand All @@ -256,7 +117,8 @@ endfunction()

if (NOT _BOARD_SETUP_COMPLETED)

IndexBoardsAndSetupBoard()
BoardSetupWorkflow()

set(CMAKE_SYSTEM_CUSTOM_CODE
"include(\"${CMAKE_BINARY_DIR}/ArduinoSystem.cmake\")"
)
Expand Down
Loading

0 comments on commit 953b2e6

Please sign in to comment.