-
Notifications
You must be signed in to change notification settings - Fork 38
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
Add a vendor make target for updating go module files #108
Conversation
bca3201
to
e26b6e6
Compare
e26b6e6
to
d9288a2
Compare
f624832
to
8815bf2
Compare
1eb3ae9
to
dbf0a40
Compare
Makefile
Outdated
MOD_TIDY_TARGETS := $(patsubst %,mod-tidy-%,$(MOD_TARGETS)) | ||
MOD_VERIFY_TARGETS := $(patsubst %,mod-verify-%,$(MOD_TARGETS)) | ||
|
||
$(MOD_TIDY_TARGETS): mod-tidy-%: |
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.
What is the purpose of mod-tidy-%
here in $(MOD_TIDY_TARGETS): mod-tidy-%
? AFAICT, it will evaluate to empty.
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.
This is how pattern targets are constructed. The %
in the rule matches the last part of the target and allows $(*)
to be used in the commands.
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.
Have you tried checking what, for instance, that mod-tidy-%
evaluates to in the $(MOD_TIDY_TARGETS): mod-tidy-%
rule with something like this:
$(MOD_TIDY_TARGETS): mod-tidy-%:
echo "*** prerequisites for '$@' => '$^' ***"
$(Q)echo "Running $@... in $(abspath ./cmd/$(*))"
$(Q)(cd $(abspath ./cmd/$(*)) && ${GO} mod tidy)
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.
That's not how pattern targets are constructed IMO. In a pattern target there must be a %
(exactly one) in the target. Then you can have one or more %
in the prerequisites which are then replaced with the same stem. In $(MOD_TIDY_TARGETS) there are 0 %
s. That's where my whole confusion is coming from. The way how I originally misread you rule definition definitely does not make any sense. The way how I now more carefully read your rule... I don't understand what it means.
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.
In the rule as written:
$(MOD_TIDY_TARGETS): mod-tidy-%:
there are no prerequisites defined. This is a static pattern rule of the form:
targets ...: target-pattern: dep-patterns ...
commands
In this case, dep-patterns
is empty.
From the docs:
The target-pattern and dep-patterns say how to compute the dependencies of each target. Each target is matched against the target-pattern to extract a part of the target name, called the stem. This stem is substituted into each of the dep-patterns to make the dependency names (one from each dep-pattern).
If we then expand this we have:
mod-tidy-cdi mod-tidy-validate: mod-tidy-%:
Meaning that this will effectively result in two "rules" with the stem matching cdi
and validate
respectively. This ensures that the commands associated with the rule have $(*)
set to cdi
and validate
repspectively.
As a note, I use these kinds of rules in our Makefiles to cover cases where we are adding new commands, for example. Here, I generate the top-level targets using wildcards and use replacements and static pattern rules to define generic targets. This means that no make changes are required to add new commands.
If we think that this is excessive for this repo, I can expand these rules instead.
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.
there are no prerequisites defined. This is a static pattern rule of the form:
Thank you ! That is exactly the snippet I was looking for in the same piece of documentation yesterday, but I failed to find it.
Makefile
Outdated
$(Q)echo "Running $@... in $(abspath ./cmd/$(*))" | ||
$(Q)(cd $(abspath ./cmd/$(*)) && ${GO} mod tidy) | ||
|
||
$(MOD_VERIFY_TARGETS): mod-verify-%: mod-tidy-% |
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.
What is the purpose of mod-verify-% mod-tidy-%
here ? I think they will evaluate to empty. Shouldn't this be instead
$(MOD_VERIFY_TARGETS): $(MOD_TIDY_TARGETS)
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.
That said, I think strictly in the make
sense something like mod-verify-%: mod-tidy-%
is more correct: "whenever verifying a module, tidy it up first"...
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.
This means that each mod-verify-%
target depends on its specific mod-tidy-%
target. This means that for each one tidy
is run before verify
.
I don't think that we need to enforce the global dependencies here i.e: before ANY verify target is run, run ALL tidy targets.
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.
But a simple mod-verify-%: mod-tidy-%
would already cover that dependency. There is no need for the $(MOD_VERIFY_TARGETS):
there in the beginning.
And I actually misread that whole line before posting my original comment. I thought it said $(MOD_VERIFY_TARGETS): mod-verify-% mod-tidy-%
...
But even now with that more careful look, I have to say that I still don't understand what does that extra $(MOD_VERIFY_TARGETS):
accomplishes there... Actually and I wasn't even aware you could write a rule like that... or if I ever did I've long forgotten since.
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.
Without the initial part the pattern rules are not matched. Afk at the moment, so let me find a docs link tomorrow.
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.
dbf0a40
to
5829772
Compare
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'm still confused about whether this makes sense and what does the extra variable-target in the beginning means:
$(CMD_MOD_TIDY_TARGETS): mod-tidy-%: mod-tidy-root
But if others (know and) are fine with that then I'm fine with it too.
@bart0sh ?
5829772
to
0139ef8
Compare
looks good to me overall. One thing though. Do we need this level of granularity? Would it be enough and simpler to have only 2 targets |
Signed-off-by: Evan Lezar <[email protected]>
…s are up to date This change adds mod-tidy and mod-verify make targets that mirror what is done for containerd. This should ensure that the module files in the root as well as in subfolders are up to date. Signed-off-by: Evan Lezar <[email protected]>
Signed-off-by: Evan Lezar <[email protected]>
It does guarantee it if directories are sorted:
I don't feel strongly about it though. I think this could be simpler and clearer this way, but I'm generally ok with your version. |
0139ef8
to
b86c208
Compare
This change adds a
vendor
make target that runsgo mod tidy
for the root module as well as each of thecmd
submodules.The
vendor
target is adapted from thecontainerd
makefile.This also converts
cmd/validate
to a submodule.