- doFileRelPath := doFile
- ents := strings.Split(cwd, "/")
- ents = ents[len(ents)-upLevels:]
- dirPrefix := path.Join(ents...)
- cwdOrig := cwd
- for i := 0; i < upLevels; i++ {
- cwd = path.Join(cwd, "..")
- doFileRelPath = path.Join("..", doFileRelPath)
- }
- cwd = path.Clean(cwd)
- doFilePath := path.Join(cwd, doFile)
- basename := tgt
- runErr := RunError{Tgt: tgtOrig}
- if strings.HasPrefix(doFile, "default.") {
- basename = tgt[:len(tgt)-(len(doFile)-len("default.")-len(".do"))-1]
- runErr.DoFile = doFileRelPath
+ {
+ doFileRelPath, upLevels, err := findDo(fdDepW, fdDep.Name(), tgtH, tgtT)
+ if err != nil {
+ cleanup()
+ return TgtError{tgt, ErrLine(err)}
+ }
+ if doFileRelPath == "" {
+ cleanup()
+ return TgtError{tgt, errors.New("no .do found")}
+ }
+ ents := strings.Split(tgtH, "/")
+ ents = ents[len(ents)-upLevels:]
+ dirPrefix = path.Join(ents...)
+ ups := make([]string, 0, upLevels+2)
+ ups = append(ups, tgtH)
+ for i := 0; i < upLevels; i++ {
+ ups = append(ups, "..")
+ }
+ ups = append(ups, doFileRelPath)
+ cwd = path.Clean(path.Join(ups[:len(ups)-1]...))
+ doFile = NewTgt(path.Join(ups...))
+ doFileT = path.Base(doFile.a)
+ if strings.HasPrefix(doFileT, "default.") {
+ basename = basename[:len(basename)-(len(doFileT)-len("default.")-len(".do"))-1]
+ runErr.DoFile = doFile.rel
+ }