Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions buildifier/buildifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,10 @@ func main() {
build.DisableRewrites = c.DisableRewrites
build.AllowSort = c.AllowSort

differ, deprecationWarning := differ.Find()
differ := differ.Find()
if c.DiffCommand != "" {
differ.Cmd = c.DiffCommand
differ.MultiDiff = c.MultiDiff
} else {
if deprecationWarning && c.Mode == "diff" {
fmt.Fprintf(os.Stderr, "buildifier: selecting diff program with the BUILDIFIER_DIFF, BUILDIFIER_MULTIDIFF, and DISPLAY environment variables is deprecated, use flags -diff_command and -multi_diff instead\n")
}
}

b := buildifier{c, differ}
Expand Down
43 changes: 3 additions & 40 deletions differ/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"fmt"
"os"
"os/exec"
"runtime"
"strings"
)

// Invocation of different diff commands, according to environment variables.
Expand Down Expand Up @@ -90,45 +88,10 @@ func (d *Differ) Run() error {
}

// Find returns the differ to use, using various environment variables.
Comment thread
Ahajha marked this conversation as resolved.
Outdated
func Find() (*Differ, bool) {
func Find() (*Differ) {
Comment thread
Ahajha marked this conversation as resolved.
Outdated
d := &Differ{}
deprecationWarning := false
if cmd := os.Getenv("BUILDIFIER_DIFF"); cmd != "" {
deprecationWarning = true
d.Cmd = cmd
}

// Load MultiDiff setting from environment.
knowMultiDiff := false
if md := os.Getenv("BUILDIFIER_MULTIDIFF"); md == "0" || md == "1" {
deprecationWarning = true
d.MultiDiff = md == "1"
knowMultiDiff = true
}
d.Cmd = "diff --unified"

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.

high

Removing the Windows fallback to FC will break buildifier -mode=diff on Windows environments that do not have bash and diff installed.

When d.Cmd is set to "diff --unified", the Differ.run method attempts to execute it via /usr/bin/env bash, which is not available on standard Windows systems. Keeping the FC fallback for Windows ensures that diffing continues to work out-of-the-box on Windows.

Note: You will also need to add "runtime" back to the imports list at the top of this file.

	if runtime.GOOS == "windows" {
		d.Cmd = "FC"
	} else {
		d.Cmd = "diff --unified"
	}
References
  1. When modifying code, ensure that changes are consistent with previous behavior, especially if the previous behavior was intentional.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hmm, I'm not sure about this one. #520 marked this path as deprecated too, but I'm wondering the reason for making the sole Windows path here deprecated.


if d.Cmd != "" {
if !knowMultiDiff {
lower := strings.ToLower(d.Cmd)
d.MultiDiff = strings.Contains(lower, "tkdiff") &&
isatty(1) && os.Getenv("DISPLAY") != ""
}
} else {
if !knowMultiDiff {
d.MultiDiff = isatty(1) && os.Getenv("DISPLAY") != ""
if d.MultiDiff {
deprecationWarning = true
}
}
if d.MultiDiff {
d.Cmd = "tkdiff"
} else {
if runtime.GOOS == "windows" {
deprecationWarning = true
d.Cmd = "FC"
} else {
d.Cmd = "diff --unified"
}
}
}
return d, deprecationWarning
return d
}