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

arduino/sketches: build sketches as a module #7654

Merged
merged 1 commit into from
Aug 21, 2019

Conversation

cladmi
Copy link
Contributor

@cladmi cladmi commented Sep 28, 2017

Generate a module for arduino sketches in a subfolder of BINDIR.
This prevents issues when doing concurrent builds or out of tree build with readonly sources.

This fixes #5848

The concept is instead of generating a cpp file in the source directory, it is generated into the build directory. However, this requires defining a new module for this directory.
It is now generated during build and not parsing.
I did not addressed the "write atomically" as I think it is not necessary anymore.

To do this, I replaced the previous bash script by a Makefile script which creates the module as link target prerequisite.

Testing procedure

As it was not asked before, I will give a testing procedure:

Setup:

  • Clean
  • create bin
  • remove write permission in the application directory
git clean -xdf examples/arduino_hello-world
mkdir -p examples/arduino_hello-world/bin
chmod -w examples/arduino_hello-world
make -C examples/arduino_hello-world clean all BOARD=arduino-mega2560

Cleanup

  • chmod u+w examples/arduino_hello-world

It works with this PR.

It fails on master, as we try to write in the directory and so the main function is never declared.
You can also notice that the Permission denied are there before even starting to build. make clean also tries to create the file.

Fixes #5848

@smlng smlng added Area: arduino API Area: Arduino wrapper API Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation labels Sep 28, 2017
@cladmi
Copy link
Contributor Author

cladmi commented Nov 14, 2017

Finally updated the documentation.
I rebased with the current master branch.

My questions are:

  • what do you think about the concept?
  • do you think it would be better that Makefile.arduino_sketches.inc defined a function that we call after to create the rules or defining stuff directly in it is fine?

Copy link
Member

@jnohlgard jnohlgard left a comment

Choose a reason for hiding this comment

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

It makes sense to generate the sketch code in a separate module under BINDIR. Can we rename the Makefile.arduino_sketches.inc file though? We were moving away from the Makefile.* pattern and to a *.inc.mk pattern. Would it make sense to move these makefiles to /makefiles?

@mkdir -p $@

# Make everything rebuild if current makefile changes
CURMK = $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
Copy link
Member

Choose a reason for hiding this comment

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

You could use the lastword function instead

Copy link
Member

Choose a reason for hiding this comment

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

Better use a different name than CURMK. This file is included from the Makefile.include which means it will pollute the name space.

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 will change to lastword I learned it after writing this, and update to a namespaced variable name.

@cladmi
Copy link
Contributor Author

cladmi commented Nov 15, 2017

I will change the Makefile name too. Do I just add .mk or do you have a better naming idea?

However, I do not want to move it to makefiles. I think the content of makefiles should only contain files that are related to the general build system, but not module specific stuff.

@mkdir -p $@

# Make everything rebuild if current makefile changes
_ARDUINO_SKETCHES_MAKEFILE = $(lastword $(MAKEFILE_LIST))
Copy link
Member

Choose a reason for hiding this comment

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

I think this needs an immediate assignment (:=)to avoid the situation where MAKEFILE_LIST is updated by including another file later.

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 value is used directly and only in the two following lines, so following imports will not impact.
However, as I am not using immediate assignment, lastword is executed twice, so I will change.

@jnohlgard
Copy link
Member

@cladmi sounds reasonable. 👍 for arduino_sketches.inc.mk

@cladmi cladmi added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Nov 16, 2017
@cladmi
Copy link
Contributor Author

cladmi commented Nov 24, 2017

Can I rebase and squash ?

Copy link
Member

@jnohlgard jnohlgard left a comment

Choose a reason for hiding this comment

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

One question and one minor nit

@@ -0,0 +1,31 @@
# Compile together the Arduino sketches of the application
# They are declared a as new module $(SKETCH_MODULE) in $(SKETCH_MOD_DIR)
Copy link
Member

Choose a reason for hiding this comment

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

typo SKETCH_MOD_DIR -> SKETCH_MODULE_DIR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I missed this one.

# Building the module files
# Do not use $^ in receipes as Makefile is also a prerequisite
$(SKETCH_MODULE_DIR)/Makefile: $(SKETCH_MODULE_DIR)/$(SKETCH_CPP)
$(Q)echo 'SRCXX = $(SKETCH_CPP)' > $@
Copy link
Member

Choose a reason for hiding this comment

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

Is there any way this recipe can be called multiple times during the same build? (race condition clobbering the destination file)
For example if building multiple sketches in different source directories?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You cannot put sketches in multiple directories as post.snip is defining the main function.
As I understood it, its to replace the code you would put in your application directory by this arduino sketches thing. That's why SKETCHES are in APPDIR which is basically CURDIR.

@jnohlgard
Copy link
Member

OK to squash

@cladmi cladmi force-pushed the pr/arduino_sketches.cpp branch from cf6969f to 04756e5 Compare November 27, 2017 13:29
@cladmi
Copy link
Contributor Author

cladmi commented Nov 30, 2017

@smlng @haukepetersen do you agree with this version ?

@smlng
Copy link
Member

smlng commented Nov 30, 2017

untested ACK

@jnohlgard
Copy link
Member

I forgot about this one, I think it is pretty much ready for merge.

@cladmi
Copy link
Contributor Author

cladmi commented Feb 20, 2018

I noticed this one suffers from the same problem as all modules where deleting one of the SKETCHES would not trigger a rebuild.
I will force re-building the .cpp everytime to get the same behaviour as before.

There are different ways to properly fix it:

  • either generate an equivalent of .d file included by make
  • change the sketches.cpp to directly include the .sketch files and GCC would do the job of generating the .d file.

@cladmi cladmi force-pushed the pr/arduino_sketches.cpp branch from 04756e5 to cb5b52d Compare February 20, 2018 13:25
@cladmi cladmi added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Feb 27, 2018
@cladmi cladmi added this to the Release 2018.07 milestone Apr 12, 2018
@cladmi
Copy link
Contributor Author

cladmi commented Apr 12, 2018

I needs to modify this as now "link" is not the right target to depend anymore

@cladmi
Copy link
Contributor Author

cladmi commented Apr 19, 2018

I was thinking on putting this in APPDEPS but it has been put in BASELIBS by #4906 I will need to do a proper PR for fixing this.

@miri64
Copy link
Member

miri64 commented Dec 18, 2018

This was ACK'd almost a year ago. What's the hold-up?

@cladmi
Copy link
Contributor Author

cladmi commented Dec 18, 2018

As my previous comment said, as other PRs were merged I changed things in this one after it was ACK.

And I just noticed that, as we had the issue recently in another PR, the directory target will not work on mac as is as it is using make 3.81.
It may also have issues with parallel make -j clean all execution.

I will look into these ones when I find time.

@cladmi cladmi added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Dec 18, 2018
@cladmi cladmi force-pushed the pr/arduino_sketches.cpp branch from 3cdbe11 to d683826 Compare August 12, 2019 13:27
@cladmi
Copy link
Contributor Author

cladmi commented Aug 12, 2019

I removed the directory creation target and included it in the .cpp file creation.
I also now declare all generated files as BUILDDEPS to prevent any issues with clean all in parallel.

The handling of re-building is still done with a FORCE and doing it with .d files would be better handled globally.
I would squash the two commits together at the end.

@tcschmidt
Copy link
Member

@smlng this update needs a review

@smlng smlng added the Reviewed: 3-testing The PR was tested according to the maintainer guidelines label Aug 21, 2019
Copy link
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

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

tested ACK for arduino-uno, configuration and documentation looks good.

One question: why sys/arduino/arduino_sketches.inc.mk and not makefiles/arduino/arduino_sketches.inc.mk - and (as it is already in a subdir) call the file sketches.inc.mk?

Otherwise this is good to be merged.

@smlng
Copy link
Member

smlng commented Aug 21, 2019

also: please squash

@cladmi
Copy link
Contributor Author

cladmi commented Aug 21, 2019

One question: why sys/arduino/arduino_sketches.inc.mk and not makefiles/arduino/arduino_sketches.inc.mk - and (as it is already in a subdir) call the file sketches.inc.mk?

I find it really stupid as organization to not be in the sys/arduino directory.
Having a module specific handling in makefiles is putting specific code in your general purpose library.

For the arduino_sketches, I named it as I created the module with the name arduino_sketches. But indeed, there is already the arduino directory. I will push the change first (so you can see the diff) and then squash.

Generate a module for arduino sketches in a subfolder of BINDIR.
This prevents issues when doing concurrent builds or out of tree build with
readonly sources.

Declare all generated files as `BUILDDEPS` to be re-created after
`clean` on parrallel `clean all`.
@cladmi cladmi force-pushed the pr/arduino_sketches.cpp branch from c3035df to be30f07 Compare August 21, 2019 09:58
@cladmi
Copy link
Contributor Author

cladmi commented Aug 21, 2019

Why is it not showing the commit in the text description? it was this one to help you review: c3035df

@smlng
Copy link
Member

smlng commented Aug 21, 2019

I find it really stupid as organization to not be in the sys/arduino directory.
Having a module specific handling in makefiles is putting specific code in your general purpose library.

agreed, thanks for the explanation!

Copy link
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

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

retested ACK

@smlng smlng merged commit 8e08748 into RIOT-OS:master Aug 21, 2019
@cladmi cladmi deleted the pr/arduino_sketches.cpp branch August 21, 2019 13:34
@cladmi
Copy link
Contributor Author

cladmi commented Aug 21, 2019

Thank you for the review.

This now does not generate files while parsing dependencies anymore !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: arduino API Area: Arduino wrapper API Area: build system Area: Build system CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 3-testing The PR was tested according to the maintainer guidelines Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

arduino: Race condition in sys/arduino/Makefile.include
8 participants