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

dev-doctor: add check for the root directory #16205

Merged
merged 1 commit into from
May 20, 2021
Merged

dev-doctor: add check for the root directory #16205

merged 1 commit into from
May 20, 2021

Conversation

twpayne
Copy link
Contributor

@twpayne twpayne commented May 18, 2021

Currently Cilium's build infrastructure assumes that Cilium is checked
out in ${GOPATH}/src/github.com/cilium/cilium, and will fail in
unpredictable ways if it is not.

This PR adds a check to the dev-doctor target to alert developers when
this is the case.

Signed-off-by: Tom Payne tom@isovalent.com
Refs #11341

@twpayne twpayne added area/misc Impacts miscellaneous areas of the code not otherwise owned by another area. release-note/misc This PR makes changes that have no direct user impact. labels May 18, 2021
@twpayne twpayne requested a review from glibsm May 18, 2021 16:24
@twpayne twpayne requested a review from a team as a code owner May 18, 2021 16:24
@twpayne twpayne requested a review from aditighag May 18, 2021 16:24
return checkError, fmt.Sprintf("cannot get working directory: %s", err)
}

// Search upward through through parent directories to find the .git directory.
Copy link
Member

Choose a reason for hiding this comment

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

It's not immediately clear to me why we search upward. Is doctor run from any subdir in cilium rather than root, ro what's the main reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although running make dev-doctor will run from the root, folks might also run cd tools/dev-doctor && go run ..

Copy link
Member

@glibsm glibsm left a comment

Choose a reason for hiding this comment

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

Not sure about empty GOPATH, or maybe we don't even want to bother.

info, err := os.Stat(path.Join(dir, ".git"))
switch {
case err == nil && info.Mode().IsDir():
if dir != path.Join(os.Getenv("GOPATH"), "src", "github.com", "cilium", "cilium") {
Copy link
Member

Choose a reason for hiding this comment

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

if GOPATH=="" this could succeed even though in reality wouldn't work, right? Perhaps we could check for !!GOPATH first

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, done.


// A rootDirCheck checks that Cilium is checked out in
// ${GOPATH}/src/github.com/cilium/cilium.
type rootDirCheck struct{}
Copy link
Member

Choose a reason for hiding this comment

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

Why don't you extract ${GOPATH}/src/github.com/cilium/cilium to a default variable?

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, done.

info, err := os.Stat(path.Join(dir, ".git"))
switch {
case err == nil && info.Mode().IsDir():
if dir != path.Join(os.Getenv("GOPATH"), "src", "github.com", "cilium", "cilium") {
Copy link
Member

Choose a reason for hiding this comment

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

Check above comment at L27. This is can then be os.State(rootDirCheck.path)?

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, done.

@twpayne twpayne requested a review from aditighag May 19, 2021 08:13
Copy link
Member

@aditighag aditighag left a comment

Choose a reason for hiding this comment

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

Thanks, lgtm!

Currently Cilium's build infrastructure assumes that Cilium is checked
out in ${GOPATH}/src/github.com/cilium/cilium, and will fail in
unpredictable ways if it is not.

This PR adds a check to the dev-doctor target to alert developers when
this is the case.

Signed-off-by: Tom Payne <tom@isovalent.com>
@twpayne twpayne merged commit af183e0 into cilium:master May 20, 2021
@twpayne twpayne deleted the pr/twpayne/root-dir-check branch May 20, 2021 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/misc Impacts miscellaneous areas of the code not otherwise owned by another area. release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants