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

Build dependencies - processing order issues #9913

Open
19 of 22 tasks
cladmi opened this issue Sep 10, 2018 · 32 comments
Open
19 of 22 tasks

Build dependencies - processing order issues #9913

cladmi opened this issue Sep 10, 2018 · 32 comments
Assignees
Labels
Area: build system Area: Build system Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Type: tracking The issue tracks and organizes the sub-tasks of a larger effort

Comments

@cladmi
Copy link
Contributor

cladmi commented Sep 10, 2018

There currently are concurrency issues in the order dependencies are defined and used, and cpu dependencies cannot be easily parsed.

I plan to address this by moving the processing of Makefile.dep before including $(BOARD)/Makefile.include

Dependencies resolution uses the following variables

  • USEMODULE
  • USEPKG
  • FEATURES_
  • BOARD
  • CPU
  • CPU_FAM (which depend on files in CPU)
  • CPU_ARCH (which depend on files in CPU)
  • CPU_MODEL

Steps

Prerequisites cleanup

And even future improvement to remove multiple duplication between board/board_common cpu/cpu_common path:

  • With BOARD and CPU recursively including their Makefile.board and Makefile.cpu, define some BOARD_IMPLEMENTATION_DIRS like variables that can be re-used to remove duplication in Makefile, Makefile.deps, Makefile.include, Makefile.features.

Explanation

To summarize, the main Makefile.include does regarding modules:
(a more detailed version is available here https://gist.github.com/cladmi/1c5af63c753635b7cb173cf8311d0b5b)

include $(RIOTBOARD)/$(BOARD)/Makefile.features
    # Define FEATURES_PROVIDED
    # Include with hard written path CPU/Makefile.features

include $(RIOTBOARD)/$(BOARD)/Makefile.include
    # Defines CPU
    # Defines USEMODULE
    # Have specific behavior depending on USEMODULE/USEPKG
include $(RIOTBOARD)/$(CPU)/Makefile.include
    # Define USEMODULE
    # Have specific behavior depending on USEMODULE/USEPKG
    # Define module dependencies

include Makefile.dep
    # Resolve USEMODULE/USEPKG/FEATURES_USED using:
    # * USEMODULE
    # * USEPKG
    # * FEATURES_
    # * BOARD
    # * CPU
    # * CPU_FAM
    # * CPU_ARCH 

include $(RIOTBASE)/sys/Makefile.include
include $(RIOTBASE)/drivers/Makefile.include
-include $(USEPKG:%=$(RIOTPKG)/%/Makefile.include)
include $(RIOTMAKE)/bindist.inc.mk
    # These also add things to USEMODULE

The main Makefile.dep only includes $(BOARD)/Makefile.dep which may sometime also end up including hardwritten_cpu_name/Makefile.dep.

In the same time makefiles/info-global.inc.mk does:

include $(RIOTBOARD)/$(BOARD)/Makefile.features
include $(RIOTBASE)/Makefile.dep

And so never takes into account any of the dependencies defined in $(BOARD)/Makefile.include or any other Makeflie.include files.

@cladmi cladmi added State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet Area: build system Area: Build system Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR labels Sep 10, 2018
@cladmi cladmi self-assigned this Sep 10, 2018
@cladmi cladmi added the Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) label Sep 10, 2018
@cladmi
Copy link
Contributor Author

cladmi commented Sep 11, 2018

To not re-add another file for nothing, I thought about putting CPU in Makefile.features instead.

It would contain "everything that needs to be defined before being able to process dependencies".

@miri64
Copy link
Member

miri64 commented Sep 11, 2018

I'm unclear on what the problem is with CPU defined in Makefile.include...

@cladmi
Copy link
Contributor Author

cladmi commented Sep 12, 2018

Changing it is a mix of somehow required, it makes sense, do not repeat the same information 3 times, and many things in our makefiles have hard ordering requirements so leads to the proposed solution.

One hint that moving CPU earlier than Makefile.include is a good idea, is that right now the cpu name is already hardcoded in $(BOARD)/Makefile.features (or a common/Makefile.features):

-include $(RIOTCPU)/samd21/Makefile.features

Main issue

The first main issue that is causing me problems, is that board and CPUs need to declare dependencies, and some of their internal modules too. However, this is right now often done in $(BOARD)/Makefile.include and $(CPU)/Makefile.include but the dependencies are resolved later in Makefile.dep. So they use USEMODULE before it is defined.

One example is here:

# The following configuration is dependencies specific
# but they are resolved later
# Hack to know now if 'nordic_softdevice_ble' is used
include $(RIOTBOARD)/$(BOARD)/Makefile.dep
# special options when using SoftDevice
ifneq (,$(filter nordic_softdevice_ble,$(USEPKG)))

Another one here:
ifneq (,$(filter periph_flashpage periph_eeprom,$(FEATURES_REQUIRED)))
FEATURES_REQUIRED += periph_flash_common
endif

This one is even using FEATURES_REQUIRED to work because of course USEMODULE is not defined yet. But it fails if the main application only declares a dependency on a module that will add the FEATURES_REQUIRED as does the test in #9892 and the OTA task force branch.

Proposed solution

So for this I want to move the processing of dependencies, before parsing all modules Makefile.include files (boards, cpu, sys, drivers, pkgs).

Constraint

Moving the dependency handling before Makefile.include means to somehow do:

include $(RIOTBOARD)/$(BOARD)/Makefile.dep
include $(RIOTBOARD)/$(CPU)/Makefile.dep

...

include $(RIOTBOARD)/$(BOARD)/Makefile.include

Which would require having CPU defined.

I say somehow, because it could be $(BOARD)/Makefile.dep or one of its $(RIOTBOARD)/common/one_on_the_common/Makefile.dep that does it like we are doing for Makefile.features and directly includes the cpu_name/Makefile.dep

But I am not going to push toward having 3 times the cpu name defined between Makefile.features, Makefile.dep, Makefile.include.


Then on the somehow required:

The CPU variable is used in Makefile.dep

However, it is still concept a dependency that the board depends/uses on this cpu so makes sense to be explicit when resolving Makefile.dep.

@cladmi cladmi mentioned this issue Sep 20, 2018
@cladmi
Copy link
Contributor Author

cladmi commented Sep 20, 2018

We can also see this problem with the esp32 board that need to define CFLAGS depending on included modules. #9426

They could in theory be defined in inline if statement, but it is not a pattern used in other boards, and would be solved by re-ordering the processing.

@cladmi
Copy link
Contributor Author

cladmi commented Oct 31, 2018

Found another case showing the issue:

mips-malta is said supported for tests/pipe

make --no-print-directory -C tests/pipe/ info-boards-supported | grep mips-malta
acd52832 airfy-beacon arduino-due arduino-duemilanove arduino-mega2560 arduino-mkr1000 arduino-mkrfox1200 arduino-mkrzero arduino-uno arduino-zero avsextrem b-l072z-lrwan1 b-l475e-iot01a blackpill bluepill calliope-mini cc2538dk cc2650-launchpad cc2650stk chronos ek-lm4f120xl esp32-mh-et-live-minikit esp32-olimex-evb esp32-wemos-lolin-d32-pro esp32-wroom-32 esp32-wrover-kit esp8266-esp-12x esp8266-olimex-mod esp8266-sparkfun-thing f4vi1 feather-m0 firefly fox frdm-k22f frdm-k64f frdm-kw41z hifive1 ikea-tradfri iotlab-a8-m3 iotlab-m3 limifrog-v1 lobaro-lorabox maple-mini mbed_lpc1768 microbit mips-malta msb-430 msb-430h msba2 msbiot mulle native nrf51dongle nrf52840dk nrf52dk nrf6310 nucleo-f030r8 nucleo-f031k6 nucleo-f042k6 nucleo-f070rb nucleo-f072rb nucleo-f091rc nucleo-f103rb nucleo-f207zg nucleo-f302r8 nucleo-f303k8 nucleo-f303re
nucleo-f303ze nucleo-f334r8 nucleo-f401re nucleo-f410rb nucleo-f411re nucleo-f412zg nucleo-f413zh nucleo-f429zi nucleo-f446re nucleo-f446ze nucleo-f722ze nucleo-f746zg nucleo-f767zi nucleo-l031k6 nucleo-l053r8 nucleo-l073rz nucleo-l152re nucleo-l432kc nucleo-l433rc nucleo-l452re nucleo-l476rg nucleo-l496zg nz32-sc151 opencm904 openmote-b openmote-cc2538 pba-d-01-kw2x pic32-clicker pic32-wifire remote-pa remote-reva remote-revb ruuvitag samd21-xpro saml21-xpro samr21-xpro samr30-xpro seeeduino_arch-pro sensebox_samd21 slstk3401a slstk3402a sltb001a slwstk6000b slwstk6220a sodaq-autonomo sodaq-explorer sodaq-one spark-core stk3600 stk3700 stm32f0discovery stm32f3discovery stm32f429i-disc1 stm32f4discovery stm32f769i-disco stm32l476g-disco teensy31 telosb thingy52 ublox-c030-u201 udoo waspmote-pro wsn430-v1_3b wsn430-v1_4 yunjia-nrf51822 z1

But when compiling we get

make --no-print-directory -C tests/pipe/ BOARD=mips-malta
/home/harter/work/git/RIOT/makefiles/toolchain/gnu.inc.mk:18: objcopy not found. Hex file will not be created.
There are unsatisfied feature requirements: periph_uart


EXPECT ERRORS!


Because mips does USEMODULE += newlib in

cpu/mips32r2_common/Makefile.include:export USEMODULE += newlib

@cladmi
Copy link
Contributor Author

cladmi commented Nov 16, 2018

@MrKevinWeiss The issue I talk to you about with the dependencies processing

@aabadie
Copy link
Contributor

aabadie commented Dec 7, 2019

Is any work or progress to move the inclusion of Makefile.dep before Makefile.include?

Thanks for reviving this issue, which is still valid. I just had a look at it and there is still some work to be done, and in many different places. That will require several PRs before Makefile.dep can be included before Makefile.include.

@aabadie
Copy link
Contributor

aabadie commented Dec 7, 2019

@gschorcht, if you are interested, I have a branch where I started to move cpu dependencies in dedicated Makefile.dep. I'm hesitating to PR it. If you think it's worth, I'll do.

I could already see problems if we include Makefile.dep before board/cpus Makefile.include: some cpu add modules based on variables defined in board/cpu level Makefile.include (for example pic32, esp32). There's also the kinetis-info.mk that should be split I think (maybe @fjmolinas has some ideas here).

I haven't looked at esp.

@gschorcht
Copy link
Contributor

The ESP32 wont be a problem. For ESPs, some variables are defined dependent on some modules but not vise versa. Therefore, some module dependencies have to be defined at the very beginning of Makefile.include.

But, once Makefile.dep is included before Makefile.include, it will become possible to move all module dependency definitions to Makefile.dep and all dependent variable definitions to Makefile.include.

I'm hesitating to PR it. If you think it's worth, I'll do.

I think it is worth. It would be further step to cleanup the makefiles.

@gschorcht
Copy link
Contributor

@aabadie If you'd like, I can contribute the ESP changes to your branch.

@aabadie
Copy link
Contributor

aabadie commented Dec 7, 2019

If you'd like, I can contribute the ESP changes to your branch.

My branch is touching almost all CPUs so I think it will be difficult to review it and get it merged fast. Some reviewers may also ask to split it. I would prefer you open a separate PR for esp.

@gschorcht
Copy link
Contributor

OK, I see. It seems like a chicken-and-egg problem 😟 It's certainly not possible to split the PRs without affecting the compilability for some CPUs. On the other hand, I can't provide the changes as separate PRs until the include order is changed without affecting the compilability for the EPSs.

@aabadie
Copy link
Contributor

aabadie commented Dec 7, 2019

I think it is worth

Ok, then it's here: #12898

For ESP, you can still move forward to an intermediate state where non conditional dependencies could be moved to Makefile.dep.

This was referenced Jan 21, 2020
fjmolinas added a commit to fjmolinas/RIOT that referenced this issue Apr 2, 2020
nrf52 includes include $(RIOTBOARD)/$(BOARD)/Makefile.dep to know
if `nordic_softdevice_ble` is used, this changes dependency
resolution sinnce -include $(APPDIR)/Makefile.board.dep should
be resolved before.

This can be removed once RIOT-OS#9913 is if `nordic_softdevice` is
deprecated.
@aabadie
Copy link
Contributor

aabadie commented Jun 23, 2020

@fjmolinas @leandrolanzieri, what is the status of this issue ? Are all cpu dependencies addressed ?

@fjmolinas
Copy link
Contributor

@fjmolinas @leandrolanzieri, what is the status of this issue ? Are all cpu dependencies addressed ?

I think we are at a point where we could test changing the inclusion order, other than sketch_module I'm not sure what is in the way. Would be worth launching debugdependencies on a PR that changes the inclusion order.

@fjmolinas
Copy link
Contributor

I believe:

  • Move CPU dependencies to $(CPU)/Makefile.dep
  • Fix CPU dependencies not being parsed easily as reported first in
  • Move all BOARD/CPU dependencies to $(BOARD)/Makefile.dep and $(CPU)/Makefile.dep

are done, can you think of something that is missing @aabadie @leandrolanzieri?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Type: tracking The issue tracks and organizes the sub-tasks of a larger effort
Projects
None yet
Development

No branches or pull requests

7 participants