Skip to content

arduino/sketches: build sketches as a module#7654

Merged
smlng merged 1 commit into
RIOT-OS:masterfrom
cladmi:pr/arduino_sketches.cpp
Aug 21, 2019
Merged

arduino/sketches: build sketches as a module#7654
smlng merged 1 commit into
RIOT-OS:masterfrom
cladmi:pr/arduino_sketches.cpp

Conversation

@cladmi

@cladmi cladmi commented Sep 28, 2017

Copy link
Copy Markdown
Contributor

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
Comment thread sys/arduino/doc.txt Outdated
@cladmi

cladmi commented Nov 14, 2017

Copy link
Copy Markdown
Contributor Author

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?

@jnohlgard jnohlgard left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

cladmi commented Nov 15, 2017

Copy link
Copy Markdown
Contributor Author

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.

Comment thread sys/arduino/arduino_sketches.inc.mk Outdated
@mkdir -p $@

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

cladmi commented Nov 24, 2017

Copy link
Copy Markdown
Contributor Author

Can I rebase and squash ?

@jnohlgard jnohlgard left a comment

Copy link
Copy Markdown
Member

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

Comment thread sys/arduino/arduino_sketches.inc.mk Outdated
@@ -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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

cladmi commented Nov 30, 2017

Copy link
Copy Markdown
Contributor Author

@smlng @haukepetersen do you agree with this version ?

@smlng

smlng commented Nov 30, 2017

Copy link
Copy Markdown
Member

untested ACK

@jnohlgard

Copy link
Copy Markdown
Member

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

@cladmi

cladmi commented Feb 20, 2018

Copy link
Copy Markdown
Contributor Author

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

cladmi commented Apr 12, 2018

Copy link
Copy Markdown
Contributor Author

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

@cladmi

cladmi commented Apr 19, 2018

Copy link
Copy Markdown
Contributor Author

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

miri64 commented Dec 18, 2018

Copy link
Copy Markdown
Member

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

@cladmi

cladmi commented Dec 18, 2018

Copy link
Copy Markdown
Contributor Author

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

cladmi commented Aug 12, 2019

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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

@smlng smlng left a comment

Copy link
Copy Markdown
Member

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

smlng commented Aug 21, 2019

Copy link
Copy Markdown
Member

also: please squash

@cladmi

cladmi commented Aug 21, 2019

Copy link
Copy Markdown
Contributor Author

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

cladmi commented Aug 21, 2019

Copy link
Copy Markdown
Contributor Author

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

@smlng

smlng commented Aug 21, 2019

Copy link
Copy Markdown
Member

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!

@smlng smlng left a comment

Copy link
Copy Markdown
Member

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

cladmi commented Aug 21, 2019

Copy link
Copy Markdown
Contributor Author

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