more explicit workdir check for builder, closes #139

Этот коммит содержится в:
gedi 2018-10-07 01:06:26 +03:00
родитель ea9eeaa197
коммит 5ed33995bd
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 56604CDCCC201556
2 изменённых файлов: 51 добавлений и 19 удалений

Просмотреть файл

@ -85,30 +85,42 @@ func Build(bin string) error {
return fmt.Errorf("failed to compile package: %s, reason: %v, output: %s", pkg.Name, err, string(out)) return fmt.Errorf("failed to compile package: %s, reason: %v, output: %s", pkg.Name, err, string(out))
} }
// let go do the dirty work and compile test // build and compile the tested package.
// package with it's dependencies. Older go
// versions does not accept existing file output
// so we create a temporary executable which will
// removed.
temp := fmt.Sprintf(filepath.Join("%s", "temp-%d.test"), os.TempDir(), time.Now().UnixNano())
// builds and compile the tested package.
// generated test executable will be removed // generated test executable will be removed
// since we do not need it for godog suite. // since we do not need it for godog suite.
// we also print back the temp WORK directory // we also print back the temp WORK directory
// go has built. We will reuse it for our suite workdir. // go has built. We will reuse it for our suite workdir.
out, err = exec.Command("go", "test", "-c", "-work", "-o", temp).CombinedOutput() out, err = exec.Command("go", "test", "-c", "-work", "-o", os.DevNull).CombinedOutput()
if err != nil { if err != nil {
return fmt.Errorf("failed to compile tested package: %s, reason: %v, output: %s", pkg.Name, err, string(out)) return fmt.Errorf("failed to compile tested package: %s, reason: %v, output: %s", pkg.Name, err, string(out))
} }
defer os.Remove(temp)
// extract go-build temporary directory as our workdir // extract go-build temporary directory as our workdir
workdir = strings.TrimSpace(string(out)) lines := strings.Split(strings.TrimSpace(string(out)), "\n")
if !strings.HasPrefix(workdir, "WORK=") { // it may have some compilation warnings, in the output, but these are not
return fmt.Errorf("expected WORK dir path, but got: %s", workdir) // considered to be errors, since command exit status is 0
for _, ln := range lines {
if !strings.HasPrefix(ln, "WORK=") {
continue
}
workdir = strings.Replace(ln, "WORK=", "", 1)
break
}
// may not locate it in output
if workdir == testdir {
return fmt.Errorf("expected WORK dir path to be present in output: %s", string(out))
}
// check whether workdir exists
stats, err := os.Stat(workdir)
if os.IsNotExist(err) {
return fmt.Errorf("expected WORK dir: %s to be available", workdir)
}
if !stats.IsDir() {
return fmt.Errorf("expected WORK dir: %s to be directory", workdir)
} }
workdir = strings.Replace(workdir, "WORK=", "", 1)
testdir = filepath.Join(workdir, pkg.ImportPath, "_test") testdir = filepath.Join(workdir, pkg.ImportPath, "_test")
} else { } else {
// still need to create temporary workdir // still need to create temporary workdir

Просмотреть файл

@ -87,7 +87,7 @@ func Build(bin string) error {
return fmt.Errorf("failed to compile package: %s, reason: %v, output: %s", pkg.Name, err, string(out)) return fmt.Errorf("failed to compile package: %s, reason: %v, output: %s", pkg.Name, err, string(out))
} }
// builds and compile the tested package. // build and compile the tested package.
// generated test executable will be removed // generated test executable will be removed
// since we do not need it for godog suite. // since we do not need it for godog suite.
// we also print back the temp WORK directory // we also print back the temp WORK directory
@ -98,11 +98,31 @@ func Build(bin string) error {
} }
// extract go-build temporary directory as our workdir // extract go-build temporary directory as our workdir
workdir = strings.TrimSpace(string(out)) lines := strings.Split(strings.TrimSpace(string(out)), "\n")
if !strings.HasPrefix(workdir, "WORK=") { // it may have some compilation warnings, in the output, but these are not
return fmt.Errorf("expected WORK dir path, but got: %s", workdir) // considered to be errors, since command exit status is 0
for _, ln := range lines {
if !strings.HasPrefix(ln, "WORK=") {
continue
}
workdir = strings.Replace(ln, "WORK=", "", 1)
break
}
// may not locate it in output
if workdir == testdir {
return fmt.Errorf("expected WORK dir path to be present in output: %s", string(out))
}
// check whether workdir exists
stats, err := os.Stat(workdir)
if os.IsNotExist(err) {
return fmt.Errorf("expected WORK dir: %s to be available", workdir)
}
if !stats.IsDir() {
return fmt.Errorf("expected WORK dir: %s to be directory", workdir)
} }
workdir = strings.Replace(workdir, "WORK=", "", 1)
testdir = filepath.Join(workdir, "b001") testdir = filepath.Join(workdir, "b001")
} else { } else {
// still need to create temporary workdir // still need to create temporary workdir