Skip to content

Commit

Permalink
Merge pull request cli#3846 from cli/build-windows-fix
Browse files Browse the repository at this point in the history
Improvements to build script on Windows
  • Loading branch information
mislav authored Jun 15, 2021
2 parents 741f768 + bd01566 commit dd3aac7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions script/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go run script\build.go %*
21 changes: 20 additions & 1 deletion script/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package main

import (
"errors"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -136,8 +137,14 @@ func date() string {

func sourceFilesLaterThan(t time.Time) bool {
foundLater := false
_ = filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
// Ignore errors that occur when the project contains a symlink to a filesystem or volume that
// Windows doesn't have access to.
if path != "." && isAccessDenied(err) {
fmt.Fprintf(os.Stderr, "%s: %v\n", path, err)
return nil
}
return err
}
if foundLater {
Expand All @@ -151,6 +158,9 @@ func sourceFilesLaterThan(t time.Time) bool {
}
}
if info.IsDir() {
if name := filepath.Base(path); name == "vendor" || name == "node_modules" {
return filepath.SkipDir
}
return nil
}
if path == "go.mod" || path == "go.sum" || (strings.HasSuffix(path, ".go") && !strings.HasSuffix(path, "_test.go")) {
Expand All @@ -160,9 +170,18 @@ func sourceFilesLaterThan(t time.Time) bool {
}
return nil
})
if err != nil {
panic(err)
}
return foundLater
}

func isAccessDenied(err error) bool {
var pe *os.PathError
// we would use `syscall.ERROR_ACCESS_DENIED` if this script supported build tags
return errors.As(err, &pe) && strings.Contains(pe.Err.Error(), "Access is denied")
}

func rmrf(targets ...string) error {
args := append([]string{"rm", "-rf"}, targets...)
announce(args...)
Expand Down

0 comments on commit dd3aac7

Please sign in to comment.