- 
                Notifications
    You must be signed in to change notification settings 
- Fork 83
Makefile: unconditionally build plugins #209
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
Conversation
668c83d    to
    a41ba0a      
    Compare
  
            
          
                Makefile
              
                Outdated
          
        
      | $(BIN_PATH)/%: plugins/%/* | ||
| $(Q)echo "Building $@..."; \ | ||
| cd $(dir $<) && $(GO_BUILD) -o $@ . | ||
| build-plugin-%: | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if a pattern as is used in containerd (using a FORCE target) would make sense, so that the targets still correlate with the path they're built in https://github.com/containerd/containerd/blob/da60207dc4b13b91bcee8a7ded48fc6dd022a96c/Makefile#L236
That said, there's probably more to do in this Makefile to make it fit standard conventions; https://github.com/containerd/containerd/blob/da60207dc4b13b91bcee8a7ded48fc6dd022a96c/Makefile#L236
# Base path used to install.
# The files will be installed under `$(DESTDIR)/$(PREFIX)`.
# The convention of `DESTDIR` was changed in containerd v1.6.
PREFIX        ?= /usr/local
BINDIR        ?= $(PREFIX)/bin
DATADIR       ?= $(PREFIX)/share
DOCDIR        ?= $(DATADIR)/doc
MANDIR        ?= $(DATADIR)/manThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have strong opinions, whatever the maintainers accept. I have no personal passion for makefile wizardry, just want the make target to work for me 😅
That said, there's probably more to do in this Makefile to make it fit standard conventions
Agree on that :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think FORCE is better than .PHONY. It is semantically accurate, while .PHONY is not if targets are files to be built.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marquiz @thaJeztah I don't want to bikeshed (too much) about the Makefile, so I just note here that if we go by @thaJeztah suggestions, then we end up with a much smaller diff and (as a bikeshedder-bonus) we keep file-based targets:
diff --git a/Makefile b/Makefile
index 71f52d6..e01b448 100644
--- a/Makefile
+++ b/Makefile
@@ -98,14 +98,16 @@ clean-cache:
 # plugins build targets
 #
 
-$(BIN_PATH)/%: plugins/%/*
+$(BIN_PATH)/% build/bin/%: FORCE
        $(Q)echo "Building $@..."; \
-       cd $(dir $<) && $(GO_BUILD) -o $@ .
+       $(GO_BUILD) -C plugins/$(notdir $@) -o $(abspath $@) .
 
-$(BIN_PATH)/wasm: plugins/wasm/
+$(BIN_PATH)/wasm build/bin/wasm: FORCE
        $(Q)echo "Building $@..."; \
        mkdir -p $(BIN_PATH) && \
-       cd $(dir $<) && GOOS=wasip1 GOARCH=wasm $(GO_BUILD) -o $@ -buildmode=c-shared .
+       GOOS=wasip1 GOARCH=wasm $(GO_BUILD) -C plugins/$(notdir $@) -o $(abspath $@) -buildmode=c-shared .
+
+FORCE:Also, we could also use then -C for consistency in testing-related rules since it seems to work there as well, with a small extra patch:
klitkey1-mobl1 nri $ git diff 
diff --git a/Makefile b/Makefile
index 610d8f6..117656e 100644
--- a/Makefile
+++ b/Makefile
@@ -132,10 +132,10 @@ ginkgo-tests:
        $(GO_CMD) tool cover -html=$(COVERAGE_PATH)/coverprofile -o $(COVERAGE_PATH)/coverage.html
 
 test-ulimits:
-       $(Q)cd ./plugins/ulimit-adjuster && $(GO_TEST) -v
+       $(Q)$(GO_TEST) -C plugins/ulimit-adjuster -v
 
 test-device-injector:
-       $(Q)cd ./plugins/device-injector && $(GO_TEST) -v
+       $(Q)$(GO_TEST) -C plugins/device-injector -v
 
 codecov: SHELL := $(shell which bash)
 codecov:        
          
                Makefile
              
                Outdated
          
        
      | $(Q)echo "Building plugin wasm..."; \ | ||
| mkdir -p $(BIN_PATH) && \ | ||
| cd $(dir $<) && GOOS=wasip1 GOARCH=wasm $(GO_BUILD) -o $@ -buildmode=c-shared . | ||
| cd plugins/wasm && GOOS=wasip1 GOARCH=wasm $(GO_BUILD) -o $(BIN_PATH)/wasm -buildmode=c-shared . | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, current versions of Go also allows for a -C <path> argument, which can safe some headaches on having to cd to a directory ("and back again" in some cases).
From go help build;
The build flags are shared by the build, clean, get, install, list, run,
and test commands:
	-C dir
		Change to dir before running the command.
		Any files named on the command line are interpreted after
		changing directories.
		If used, this flag must be the first one in the command line.
	-a
		force rebuilding of packages that are already up-to-date.
a41ba0a    to
    979670e      
    Compare
  
    | Updated to use FORCE. Changed the target so that I'm able to do  | 
| 
 Ha! I'm definitely not a Makefile aficionado myself. Or at least; I can make them work for my own needs, but it always takes me 10 tries to write them to be "mostly correct" to fit standards. Either  w.r.t. fixing the  I recently found that the OpenSSF "best practices" also has it as one of the requirements (for "silver"); https://www.bestpractices.dev/en/projects/1271?criteria_level=1#quality 
 (in addition to); 
 | 
Changes the build targets of plugins to always unconditionally execute without trying to check dependencies. The previous make targets were faulty, e.g. changing something in the library didn't rebuild the plugins. This is a simple and stupid fix that I believe is good enough - building the plugins is really fast and go compiler caching makes it super fast for "unnecessary" builds. Signed-off-by: Markus Lehtonen <markus.lehtonen@intel.com>
979670e    to
    d92ebd6      
    Compare
  
    | Update: implemented @klihub's suggestions to make the diff a tad smaller | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure why not
LGTM
Changes the build targets of plugins to effectively "phony", always unconditionally running the build without trying to check dependencies. The previous make targets were faulty, e.g. changing something in the library didn't rebuild the plugins. This is a simple and stupid fix that I believe is good enough - building the plugins is really fast and go compiler caching makes it super fast for "unnecessary" builds.
NOTE: If merged, obsoletes #207