make: add blob utility header#11870
Conversation
|
@smlng ping ;) |
|
To provide context vs #11497, this PR unifies current blob handling (which is duplicated in examples/javascript, examples/lua_REPL and examples/lua_basic, and one more coming in #2968) to a shared makefile. It is still using xxd & sed, which #11497 tries to replace with a custom make-based implementation. IMO, while I disagree with handling this using make itself, even should we agree on that, this PR provides a clean entry-point to do that. Thus the guts of #11497 could be hooked in easily by replacing the one xxd+sed line of this PR. But that should be a different discussion. |
tests/blob/Makefile
Outdated
|
|
||
| BLOBS += blobtest.txt | ||
|
|
||
| TEST_ON_CI_WHITELIST += all |
There was a problem hiding this comment.
This is not needed anymore, right ?!
|
@aabadie I accidentally over-force-pushed and then re-applied your suggestion commit. |
| DIRS += $(RIOTCPU)/$(CPU) $(RIOTBOARD)/$(BOARD) | ||
| DIRS += $(RIOTBASE)/core $(RIOTBASE)/drivers $(RIOTBASE)/sys | ||
|
|
||
| BLOBS = $(APPLICATION_BLOBS) |
There was a problem hiding this comment.
Why not move this line to makefiles/blob.inc.mk ? Since this file is also included by Makefile.base, it will be more consistent to handle this in the related file. This is untested so maybe this doesn't work because I'm missing something.
There was a problem hiding this comment.
If that line would be in blob.inc.mk, it would be used in every recursive make call (e.g., for every module). We only want it to be used for the application module. All other modules can directly use BLOBS.
From the corresponding commit description:
@kaspar030
make: pass BLOBS to makefiles/application.inc.mk
For regular modules, adding files to BLOBS is sufficient to create the
corresponding headers.
Application modules are different, as they use a minimal makefile
(makefiles.application.inc.mk) to build, thus application level
variables are not available.
This commit makes Makefile.include pass BLOBS to the application
Makefile as APPLICATION_BLOBS, and application.inc.mk use that variable
as value for BLOBS.
The indirection is necessary so submakefiles (e.g., those visited by
DIRS) do not hard override BLOBS.
There was a problem hiding this comment.
Is it possible to add a comment about that here instead of inside the commit message ?
There was a problem hiding this comment.
Now it is here, is that sufficient?
There was a problem hiding this comment.
I've added some doc to applications.inc.mk.
|
I was asked to have a look at this PR but I don't feel confident enough to give a valuable review on the Makefile changes. Especially because they touch I have more general comments btw:
So this means that this PR allows to embed blob defined in modules. The problem is that the test application doesn't show this. It's only applied to application blobs. Another aspect is that the current implementation only generates a header from a text file and include this to the build. Conceptually, this is not really a blob. |
|
I'll summarize a discussion we had AFK with @emmanuelsearch. Sorry for the long comment, and I don't mean to bash this PR- I feel that many of the ideas expressed here apply equally to other instances where we may be wanting to "abstract away" common functionality. All this would achieve is remove the need for the following snippet to exist in the application's makefile: JS_PATH = $(BINDIR)/js/$(MODULE)
# add directory of generated *.js.h files to include path
CFLAGS += -I$(JS_PATH)
# generate .js.h header files of .js files
JS = $(wildcard *.js)
JS_H = $(JS:%.js=$(JS_PATH)/%.js.h)
BUILDDEPS += $(JS_H) $(JS_PATH)/
include $(RIOTBASE)/Makefile.include
$(JS_PATH)/:
$(Q)mkdir -p $@
$(JS_H): $(JS_PATH)/%.js.h: %.js | $(JS_PATH)/
$(Q)xxd -i $< | sed 's/^unsigned/const unsigned/g' > $@That was taken from the jerryscript package. Lua has something similar. Note that header files will end up in a js-specific path. The propose module removes the need for this code, at the price of:
The reduced flexibility means that any deviation from the assumption that this new module does would require reverting back to the above snippet. Now, there are some very real problems which are not being solved by this or by anything currently in use. Many of these are actually limitations of our build system, unrelated to this PR.
In conclusion, I'm against too much convenience functions, since these have to be maintained too. |
If there's a use-case for that, it can be added. (e.g., by properly dealing with subfolders so blobs don't have to be in the module's folder.)
Did you encounter this use case before?
I agree.
Well, linking an object is a different function than creating data that is accessible from C from a binary. |
Well, I did, now |
|
| @@ -0,0 +1,2 @@ | |||
| BLOBS += blobtest.bin | |||
There was a problem hiding this comment.
thanks! It was blanked out by .gitignore...
|
|
and @cladmi are you actually planning to review? |
|
@kaspar030, do you think it's possible to achieve the same result without using SECONDEXPANSION ? |
|
|
||
| # make C and C++ objects of this module depend on generated headers, so they | ||
| # get re-build on changes to the blob files. | ||
| $(OBJC) $(OBJCXX): $(BLOB_H) |
There was a problem hiding this comment.
The comment is wrong, rebuilding would be done automatically from the .d generated files as the compilation is done with -MD -MP.
This also does not account for deleted files that the .d does.
This is only currently required to have the headers generated before compiling the C files, so with a : |$(BLOB_H) it would work too.
There was a problem hiding this comment.
I've updated the comment.
Using : |$(BLOB_H), no rebuild is triggered when changing a blob.
|
It looks like the If it really is, the Here as all targets are basically known and could be handled with a stupid handling that all targets depend on having created all the directories first: Or if you want one to one mapping: IIRC, the For the naming, I would not say it generates blobs as #11497 did, it is an RIOT/examples/javascript/Makefile Lines 58 to 59 in 255ce7d Adding directory variables creation is something that would be great globally in Makefile.base and Makefile.include added on its own instead of added here in the middle of another things that does not really need it. |
| $(BLOB_HDR_DIR)/.: | ||
| @mkdir -p $@ | ||
|
|
||
| $(BLOB_HDR_DIR)%/.: |
There was a problem hiding this comment.
Why not just %/.: it is a directory creation rule ?
Is it because of some make versions? I know some have issues with implicit rules sometime.
This also apply for the .PRECIOUS line.
The directory creation rule could also be put in common in Makefile.base instead of here.
There was a problem hiding this comment.
It could, but as is it is self-contained.
makefiles/blob.inc.mk
Outdated
|
|
||
| XXD ?= xxd | ||
|
|
||
| $(BLOB_H): $(BLOB_HDR_DIR)/. |
There was a problem hiding this comment.
not needed, I removed it.
It was asked for, and it makes sense, as e.g. jerryscript uses a "js/" subfolder. |
Does it hurt? |
correct. |
@cladmi, other than issues with variables containing dollarsigns, do you know any downsides of enabling SECONDEXPANSION globally? |
|
|
#12708, please rebase. |
|
aabadie
left a comment
There was a problem hiding this comment.
Just minor remaining things in the test. Otherwise that looks good. You can squash directly.
tests/blob/Makefile
Outdated
| @@ -0,0 +1,10 @@ | |||
| DEVELHELP ?= 0 | |||
There was a problem hiding this comment.
Why disabling DEVELHELP by default? I would keep it.
There was a problem hiding this comment.
yup, removed the line (default is 1)
tests/blob/tests/01-run.py
Outdated
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(run(testfunc, timeout=120)) |
There was a problem hiding this comment.
I don't think the custom timeout is required. The test is running fast enough.
There was a problem hiding this comment.
removed the timeout
For regular modules, adding files to BLOBS is sufficient to create the corresponding headers. Application modules are different, as they use a minimal makefile (makefiles.application.inc.mk) to build, thus application level variables are not available. This commit makes Makefile.include pass BLOBS to the application Makefile as APPLICATION_BLOBS, and application.inc.mk use that variable as value for BLOBS. The indirection is necessary so submakefiles (e.g., those visited by DIRS) do not hard override BLOBS.
|
@bergzand, we need your approval here. Are your concerns addressed ? |
Yes |
|
Thanks everyone! |
Contribution description
This PR adds a utility makefile that allows arbitrary files to be made available as headers.
This is supposed to be used with, e.g., lua, jerryscript, micropython for scripting language source files.
Testing procedure
Contains a test application. Check CI output.
Also, try changing the blobs and see if everything gets rebuilt correctly. Hammer this using
make -j ....Do the same with
BUILD_IN_DOCKER=1.Issues/PRs references
Simpler alternative to #11497.