Skip to content

windows: reduce dependency of go-shell, make build succeed on windows#47

Merged
sdurrheimer merged 1 commit into
prometheus:masterfrom
martinlindhe:dont-fail-silently
Oct 12, 2016
Merged

windows: reduce dependency of go-shell, make build succeed on windows#47
sdurrheimer merged 1 commit into
prometheus:masterfrom
martinlindhe:dont-fail-silently

Conversation

@martinlindhe

@martinlindhe martinlindhe commented Sep 29, 2016

Copy link
Copy Markdown
Contributor

This makes promu successfully compile https://github.com/martinlindhe/wmi_exporter on Windows. Tested on Win 7.

The issues were:

  • go-shell swallowed erroring commands, making it harder to debug
  • go-shell Run() incorrectly escaped command line parameters, producing impossible command line.

There is still some dependencies on go-shell, but they seem to be pretty trivial to replace with stdlib code.

Fixes #44

This was triggered by trying to provide build info to wmi_exporter (prometheus-community/windows_exporter#24)

@martinlindhe

martinlindhe commented Sep 29, 2016

Copy link
Copy Markdown
Contributor Author

Possible fallout, on circleci can be seen


>> building binaries

 >   promu

flag provided but not defined: -a -tags 'netgo static_build'

usage: build [-o output] [-i] [build flags] [packages]

Parameter is coming from .promu.yml build.flags.

To fix, need to split up flags on spaces outside quotes. Working on a update...

@martinlindhe

martinlindhe commented Sep 29, 2016

Copy link
Copy Markdown
Contributor Author

To fix, need to split up flags on spaces outside quotes. Working on a update...

Patch updated with a fix and a test.

Ready for review!

Comment thread cmd/shell.go Outdated
func runCommand(name string, arg ...string) error {
if viper.GetBool("verbose") {
cmdText := name + " " + strings.Join(arg, " ")
fmt.Fprintln(os.Stderr, " > ", cmdText)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why Stderr ? This is not a error message.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nevermind, this is how set -x is working. I would prefer a + prefix instead of >, like a regular command trace.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because the corresponding code in go-shell wrote to stderr, see https://github.com/progrium/go-shell/blob/master/shell.go#L142

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed from > to +, patch updated

Comment thread cmd/shell.go Outdated
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Given that this is not a promu command, I think it would be better to move it in the util folder like the retry package.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Re-using the shell name collides with already imported go-shell, so renamed it to "sh"

Comment thread cmd/build.go Outdated
"time"

shell "github.com/progrium/go-shell"
"github.com/prometheus/promu/util/sh"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nits: we generally like to split internal and external packages. Could you move the ulil/sh at the end of the import section with a empty line between external and internal packages.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, patch updated and squashed

Comment thread cmd/crossbuild.go Outdated

"github.com/mcuadros/go-version"
"github.com/progrium/go-shell"
"github.com/prometheus/promu/util/sh"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here, external/internal package separation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread cmd/tarball.go Outdated
"path/filepath"

"github.com/progrium/go-shell"
"github.com/prometheus/promu/util/sh"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here, external/internal package separation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@sdurrheimer sdurrheimer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok, seems good to me.
I think there is more work to do for good Windows compatibility, but the most important, I guess, is the build command. This one work now with your changes, thanks.

We should also be able to get rid of the go-shell package. I will work on that.

@grobie your thoughts ?

Comment thread util/sh/sh.go Outdated
return cmd.Run()
}

// ShellQuote ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since we have sh package, we can rename this to Quote.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done, patch updated

Comment thread util/sh/sh.go
)

// RunCommand ...
func RunCommand(name string, arg ...string) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Possible to have real comment sentence here for exposed function ? Like RunCommand executes a shell command.

Same for ShellQuote and SplitParameters.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done, patch updated

@grobie grobie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Getting rid of go-shell sounds good to me, its error handling doesn't seem to be very explicit.

@sdurrheimer
sdurrheimer merged commit d776156 into prometheus:master Oct 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants