-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
tools/bazel.ps1
and tools/bazel.bat
on Windows
- Loading branch information
1 parent
b484ae2
commit 7275167
Showing
3 changed files
with
188 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package core | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"testing" | ||
) | ||
|
||
func TestMaybeDelegateToNoWrapper(t *testing.T) { | ||
tmpDir, err := ioutil.TempDir("", "TestMaybeDelegateToNoWrapper") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer os.RemoveAll(tmpDir) | ||
|
||
os.MkdirAll(tmpDir, os.ModeDir | 0700) | ||
ioutil.WriteFile(filepath.Join(tmpDir, "WORKSPACE"), []byte(""), 0600) | ||
ioutil.WriteFile(filepath.Join(tmpDir, "BUILD"), []byte(""), 0600) | ||
|
||
entrypoint := maybeDelegateToWrapperFromDir("bazel_real", tmpDir, true) | ||
expected := "bazel_real" | ||
|
||
if entrypoint != expected { | ||
t.Fatalf("Expected to delegate bazel to %q, but got %q", expected, entrypoint) | ||
} | ||
} | ||
|
||
func TestMaybeDelegateToNoNonExecutableWrapper(t *testing.T) { | ||
tmpDir, err := ioutil.TempDir("", "TestMaybeDelegateToNoNonExecutableWrapper") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer os.RemoveAll(tmpDir) | ||
|
||
os.MkdirAll(tmpDir, os.ModeDir | 0700) | ||
ioutil.WriteFile(filepath.Join(tmpDir, "WORKSPACE"), []byte(""), 0600) | ||
ioutil.WriteFile(filepath.Join(tmpDir, "BUILD"), []byte(""), 0600) | ||
|
||
os.MkdirAll(filepath.Join(tmpDir, "tools"), os.ModeDir | 0700) | ||
ioutil.WriteFile(filepath.Join(tmpDir, "tools", "bazel"), []byte(""), 0600) | ||
|
||
entrypoint := maybeDelegateToWrapperFromDir("bazel_real", tmpDir, true) | ||
expected := "bazel_real" | ||
|
||
if entrypoint != expected { | ||
t.Fatalf("Expected to delegate bazel to %q, but got %q", expected, entrypoint) | ||
} | ||
} | ||
|
||
func TestMaybeDelegateToStandardWrapper(t *testing.T) { | ||
var tmpDir, err = ioutil.TempDir("", "TestMaybeDelegateToStandardWrapper") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer os.RemoveAll(tmpDir) | ||
|
||
os.MkdirAll(tmpDir, os.ModeDir | 0700) | ||
ioutil.WriteFile(filepath.Join(tmpDir, "WORKSPACE"), []byte(""), 0600) | ||
ioutil.WriteFile(filepath.Join(tmpDir, "BUILD"), []byte(""), 0600) | ||
|
||
os.MkdirAll(filepath.Join(tmpDir, "tools"), os.ModeDir | 0700) | ||
ioutil.WriteFile(filepath.Join(tmpDir, "tools", "bazel"), []byte(""), 0700) | ||
|
||
entrypoint := maybeDelegateToWrapperFromDir("bazel_real", tmpDir, true) | ||
expected := filepath.Join(tmpDir, "tools", "bazel") | ||
|
||
if entrypoint != expected { | ||
t.Fatalf("Expected to delegate bazel to %q, but got %q", expected, entrypoint) | ||
} | ||
} | ||
|
||
func TestMaybeDelegateToPowershellWrapper(t *testing.T) { | ||
tmpDir, err := ioutil.TempDir("", "TestMaybeDelegateToPowershellWrapper") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer os.RemoveAll(tmpDir) | ||
|
||
os.MkdirAll(tmpDir, os.ModeDir | 0700) | ||
ioutil.WriteFile(filepath.Join(tmpDir, "WORKSPACE"), []byte(""), 0600) | ||
ioutil.WriteFile(filepath.Join(tmpDir, "BUILD"), []byte(""), 0600) | ||
|
||
os.MkdirAll(filepath.Join(tmpDir, "tools"), os.ModeDir | 0700) | ||
ioutil.WriteFile(filepath.Join(tmpDir, "tools", "bazel.ps1"), []byte(""), 0700) | ||
|
||
entrypoint := maybeDelegateToWrapperFromDir("bazel_real", tmpDir, true) | ||
expected := filepath.Join(tmpDir, "tools", "bazel.ps1") | ||
|
||
// Only windows platforms use powershell wrappers | ||
if runtime.GOOS != "windows" { | ||
expected = "bazel_real" | ||
} | ||
|
||
if entrypoint != expected { | ||
t.Fatalf("Expected to delegate bazel to %q, but got %q", expected, entrypoint) | ||
} | ||
} | ||
|
||
func TestMaybeDelegateToBatchWrapper(t *testing.T) { | ||
tmpDir, err := ioutil.TempDir("", "TestMaybeDelegateToBatchWrapper") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer os.RemoveAll(tmpDir) | ||
|
||
os.MkdirAll(tmpDir, os.ModeDir | 0700) | ||
ioutil.WriteFile(filepath.Join(tmpDir, "WORKSPACE"), []byte(""), 0600) | ||
ioutil.WriteFile(filepath.Join(tmpDir, "BUILD"), []byte(""), 0600) | ||
|
||
os.MkdirAll(filepath.Join(tmpDir, "tools"), os.ModeDir | 0700) | ||
ioutil.WriteFile(filepath.Join(tmpDir, "tools", "bazel.bat"), []byte(""), 0700) | ||
|
||
entrypoint := maybeDelegateToWrapperFromDir("bazel_real", tmpDir, true) | ||
expected := filepath.Join(tmpDir, "tools", "bazel.bat") | ||
|
||
// Only windows platforms use batch wrappers | ||
if runtime.GOOS != "windows" { | ||
expected = "bazel_real" | ||
} | ||
|
||
if entrypoint != expected { | ||
t.Fatalf("Expected to delegate bazel to %q, but got %q", expected, entrypoint) | ||
} | ||
} | ||
|
||
func TestMaybeDelegateToPowershellOverBatchWrapper(t *testing.T) { | ||
tmpDir, err := ioutil.TempDir("", "TestMaybeDelegateToPowershellOverBatchWrapper") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer os.RemoveAll(tmpDir) | ||
|
||
os.MkdirAll(tmpDir, os.ModeDir | 0700) | ||
ioutil.WriteFile(filepath.Join(tmpDir, "WORKSPACE"), []byte(""), 0600) | ||
ioutil.WriteFile(filepath.Join(tmpDir, "BUILD"), []byte(""), 0600) | ||
|
||
os.MkdirAll(filepath.Join(tmpDir, "tools"), os.ModeDir | 0700) | ||
ioutil.WriteFile(filepath.Join(tmpDir, "tools", "bazel.ps1"), []byte(""), 0700) | ||
ioutil.WriteFile(filepath.Join(tmpDir, "tools", "bazel.bat"), []byte(""), 0700) | ||
|
||
entrypoint := maybeDelegateToWrapperFromDir("bazel_real", tmpDir, true) | ||
expected := filepath.Join(tmpDir, "tools", "bazel.ps1") | ||
|
||
// Only windows platforms use powershell or batch wrappers | ||
if runtime.GOOS != "windows" { | ||
expected = "bazel_real" | ||
} | ||
|
||
if entrypoint != expected { | ||
t.Fatalf("Expected to delegate bazel to %q, but got %q", expected, entrypoint) | ||
} | ||
} |