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

Portable plugin executable check for Windows platform #367

Merged
merged 2 commits into from
Aug 15, 2019

Conversation

navidshaikh
Copy link
Collaborator

@navidshaikh navidshaikh commented Aug 15, 2019

Fixes #365

Proposed Changes

The code used for checking whether plugin is executable or not in plugin verifier
does not build for Windows. Builds Windows and non-Windows platform plugin verifier separately

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Aug 15, 2019
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: navidshaikh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 15, 2019
@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 15, 2019
@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-client-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/kn/commands/plugin/plugin_verifier.go 78.2% 74.2% -3.9

@navidshaikh
Copy link
Collaborator Author

kn builds with this change for Windows

➜  client git:(fix-365)  GO111MODULE=on GOOS=windows GOARCH=amd64 go build -mod=vendor ./cmd/... && ll kn.exe
-rwxr-xr-x. 1 nshaikh nshaikh 36M Aug 15 18:21 kn.exe

@duglin
Copy link
Contributor

duglin commented Aug 15, 2019

I'm not sure we should remove the check since having a non-executable text file in your PATH is valid, but shouldn't show up as a plug-in when you plugin list.

If the real issue is that we can't compile certain files in Windows, can we just use golang's "build tags" and have the Windows version of that func be a no-op ?

@navidshaikh
Copy link
Collaborator Author

build tags are added per file basis AFAIK, we have executable check done as method, let mecheck if I can do better to fix this

@navidshaikh
Copy link
Collaborator Author

I tried and separated the non Windows platform check in separate file and add +build !windows build flag to it, however that non-windows-platform check has to be referenced in original plugin verifier and not-building it for windows makes it undefined

pkg/kn/commands/plugin/plugin_verifier.go:131:9: undefined: checkForNonWindowsExecutable

may be we'll need to delegate the executable check to underlying platform

@mattmoor mattmoor removed their request for review August 15, 2019 14:19
@duglin
Copy link
Contributor

duglin commented Aug 15, 2019

can't you put the funcs that have linux vs windows versions into their own files and then only compile with the OS specific version?

@navidshaikh
Copy link
Collaborator Author

Wondering how come the nightly build has it built https://github.com/knative/client/blob/master/docs/README.md#installing-kn
or is it pointing to last built kn before plugin verifier PR merged in

@navidshaikh
Copy link
Collaborator Author

can't you put the funcs that have linux vs windows versions into their own files and then only compile with the OS specific version?

You are right! Didn't do better yet to fix this. :-/

@navidshaikh navidshaikh changed the title Removes check whether plugin is executable Portable plugin executable check for Windows platform Aug 15, 2019
 builds Windows and non-Windows platform plugin verifier separately
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !windows
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

builds for non-Windows platform

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So, when we mention GOOS=windows while building cross platform binary it skips this file and picks up Windows specific version defining the needed methods / functions to verify plugin on Windows platform.

@@ -0,0 +1,190 @@
// Copyright © 2019 The Knative Authors
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed all the functions which are in plugin_verifier.go which are specific to non-Windows platform

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like a lot of that code could be in a common file and limit the plugin_verifier_windows.go with only the Windows code. Is there a reason you could not do this?

@navidshaikh
Copy link
Collaborator Author

Builds for all platform now

21:15 ➜  client git:(fix-365) ✗  ./hack/build-cross.sh 
🚧 🐧 Building for Linux
🚧 🍏 Building for macOS
🚧 🎠 Building for Windows
21:15 ➜  client git:(fix-365) ✗  ll kn-*
-rwxr-xr-x. 1 nshaikh nshaikh 36M Aug 15 21:15 kn-darwin-amd64
-rwxr-xr-x. 1 nshaikh nshaikh 36M Aug 15 21:15 kn-linux-amd64
-rwxr-xr-x. 1 nshaikh nshaikh 36M Aug 15 21:15 kn-windows-amd64.exe

Used the code from hack/release.sh in hack/build-cross.sh as below

21:16 ➜  client git:(fix-365) ✗  tail -n 17 hack/build-cross.sh
source $(dirname $0)/../vendor/knative.dev/test-infra/scripts/release.sh
source $(dirname $0)/build-flags.sh

ld_flags="$(build_flags $(dirname $0)/..)"
pkg="github.com/knative/client/pkg/kn/commands"
version="${TAG}"
# Use vYYYYMMDD-<hash>-local for the version string, if not passed.
[[ -z "${version}" ]] && version="v${BUILD_TAG}-local"

export GO111MODULE=on
export CGO_ENABLED=0
echo "🚧 🐧 Building for Linux"
GOOS=linux GOARCH=amd64 go build -mod=vendor -ldflags "${ld_flags}" -o ./kn-linux-amd64 ./cmd/...
echo "🚧 🍏 Building for macOS"
GOOS=darwin GOARCH=amd64 go build -mod=vendor -ldflags "${ld_flags}" -o ./kn-darwin-amd64 ./cmd/...
echo "🚧 🎠 Building for Windows"
GOOS=windows GOARCH=amd64 go build -mod=vendor -ldflags "${ld_flags}" -o ./kn-windows-amd64.exe ./cmd/...

@navidshaikh
Copy link
Collaborator Author

/test pull-knative-client-build-tests

  As we'll need either to mention, which file compiles for which
  platform.
@navidshaikh
Copy link
Collaborator Author

navidshaikh commented Aug 15, 2019

Summary:

  1. We don't compile syscall.Stat_t for Windows platform where it isn't available, but for all non-Windows platform
  2. Introduced plugin_verifier_windows.go which will be compiled only for Windows platform and doesn't include syscall.Stat_t in that file and respective methods / function.
    (We used suffix _windows.go to flag that)
  3. Based on the platform, respective file (plugin_verifier.go or plugin_verifier_windows.go) land into the binary.

This should unblock the cross-platform builds.

@navidshaikh
Copy link
Collaborator Author

navidshaikh commented Aug 15, 2019

@maximilien @sixolet @duglin : I've verified this PR by building it for cross platform as mentioned in above comments, I think this is ready for review.
(would be good if have it in and unblock our nightly build, current nightly build is 7 days old)

//Cc: @adrcunha

Copy link
Contributor

@maximilien maximilien left a comment

Choose a reason for hiding this comment

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

/ok_to_test

@@ -0,0 +1,190 @@
// Copyright © 2019 The Knative Authors
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like a lot of that code could be in a common file and limit the plugin_verifier_windows.go with only the Windows code. Is there a reason you could not do this?

@navidshaikh
Copy link
Collaborator Author

Seems like a lot of that code could be in a common file and limit the plugin_verifier_windows.go with only the Windows code. Is there a reason you could not do this?

@maximilien : It's the other way around actually, there are specific syscalls which are absent for
Windows platforms, in this case syscall.Stat_t.

And we can't reference the specific-platform-functions from a common function,
because those specific-platform-functions will be visited compile time, in all the platforms build (as we'll not mark build tags for file having common function).

We'll need to completely separate references and imports at compile time for Windows and non-Windows platforms, to mask the unavailable syscalls imports.

  1. Marking plugin_verifier.go file, which uses of syscall.Stat_t as +build !windows ,
    hides it compile time when GOOS=windows
  2. Having filename ending with _windows.go hides it compile time,
    when GOOS=linux or GOOS=darwin to avoid re-declaration of vars / functions.

@sixolet
Copy link
Contributor

sixolet commented Aug 15, 2019

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 15, 2019
@knative-prow-robot knative-prow-robot merged commit 54d024f into knative:master Aug 15, 2019
@maximilien
Copy link
Contributor

@maximilien : It's the other way around actually, there are specific syscalls which are absent for
Windows platforms, in this case syscall.Stat_t.

OK cool. Thanks. I have no way to test nor use Windows, so glad you are on it. Thx

@navidshaikh navidshaikh deleted the fix-365 branch August 16, 2019 06:07
dsimansk added a commit to dsimansk/client that referenced this pull request Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kn fails to build for Windows platform
7 participants