X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=ifchange.go;h=128d1afbef6eaea5fdd1681af86cb1339ec8f738;hb=bf96757828d2ae663f5f54147c0e229f74fc9357;hp=fe1c2a853a64e79192f5a99a1b183adf74fc05aa;hpb=0b3f0c3c467fcfaaad3cb01ca00513b838fd75e6;p=goredo.git diff --git a/ifchange.go b/ifchange.go index fe1c2a8..128d1af 100644 --- a/ifchange.go +++ b/ifchange.go @@ -1,6 +1,6 @@ /* -goredo -- redo implementation on pure Go -Copyright (C) 2020 Sergey Matveev +goredo -- djb's redo implementation on pure Go +Copyright (C) 2020-2021 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,6 +27,7 @@ func collectDeps( cwd, tgtOrig string, level int, deps map[string]map[string]struct{}, + includeSrc bool, ) []string { cwd, tgt := cwdAndTgt(path.Join(cwd, tgtOrig)) depPath := path.Join(cwd, RedoDir, tgt+DepSuffix) @@ -60,7 +61,10 @@ func collectDeps( if dep == "" { return alwayses } - if dep == tgt || isSrc(cwd, dep) { + if dep == tgt { + continue + } + if !includeSrc && isSrc(cwd, dep) { continue } if !returnReady { @@ -68,11 +72,14 @@ func collectDeps( if m, ok := deps[depRel]; ok { m[tgtRel] = struct{}{} } else { - m = make(map[string]struct{}, 0) + m = map[string]struct{}{} m[tgtRel] = struct{}{} deps[depRel] = m } - alwayses = append(alwayses, collectDeps(cwd, dep, level+1, deps)...) + alwayses = append( + alwayses, + collectDeps(cwd, dep, level+1, deps, includeSrc)..., + ) } } return alwayses @@ -84,7 +91,7 @@ func buildDependants(tgts []string) map[string]struct{} { seen := map[string]struct{}{} deps := map[string]map[string]struct{}{} for _, tgtInitial := range tgts { - for _, tgt := range collectDeps(Cwd, tgtInitial, 0, deps) { + for _, tgt := range collectDeps(Cwd, tgtInitial, 0, deps, false) { if tgt != tgtInitial { seen[tgt] = struct{}{} } @@ -109,12 +116,12 @@ func buildDependants(tgts []string) map[string]struct{} { } ok := true for i := 0; i < len(seen); i++ { - ok = ok && isOkRun(<-errs) + ok = isOkRun(<-errs) && ok } Jobs.Wait() close(errs) if !ok { - trace(CDebug, "alwayses failed, skipping depdendants") + trace(CDebug, "alwayses failed, skipping dependants") return nil } @@ -139,7 +146,7 @@ RebuildDeps: jobs := 0 queueSrc = []string{} for _, tgt := range queue { - ood, err := isOOD(Cwd, tgt, 0, seen) + ood, err := isOODWithTrace(Cwd, tgt, 0, seen) if err != nil { trace(CErr, "dependant error: %s, skipping dependants", err) return nil @@ -156,7 +163,7 @@ RebuildDeps: jobs++ } for i := 0; i < jobs; i++ { - ok = ok && isOkRun(<-errs) + ok = isOkRun(<-errs) && ok } if !ok { trace(CDebug, "dependants failed, skipping them") @@ -173,9 +180,12 @@ RebuildDeps: func ifchange(tgts []string, forced, traced bool) (bool, error) { jsInit() - defer jsAcquire("ifchange exiting") + if !IsTopRedo { + defer jsAcquire("ifchange exiting") + } defer Jobs.Wait() seen := buildDependants(tgts) + oodTgtsClear() trace(CDebug, "building %d targets: %v", len(tgts), tgts) jobs := 0 errs := make(chan error, len(tgts)) @@ -183,12 +193,12 @@ func ifchange(tgts []string, forced, traced bool) (bool, error) { var err error for _, tgt := range tgts { if _, ok := seen[tgt]; ok { - trace(CDebug, "%s was already build as a dependenant", tgt) + trace(CDebug, "%s was already build as a dependant", tgt) continue } ood = true if !forced { - ood, err = isOOD(Cwd, tgt, 0, seen) + ood, err = isOODWithTrace(Cwd, tgt, 0, seen) if err != nil { return false, err } @@ -207,7 +217,7 @@ func ifchange(tgts []string, forced, traced bool) (bool, error) { } ok := true for ; jobs > 0; jobs-- { - ok = ok && isOkRun(<-errs) + ok = isOkRun(<-errs) && ok } return ok, nil }