]> Cypherpunks.ru repositories - goredo.git/blobdiff - targets.go
Raise copyright years in advance
[goredo.git] / targets.go
index 6459a2db5529d9061ce393b044073f62e9c2ba71..e19b90acb84e99c90acd5bc0d8c46e84d1313252 100644 (file)
@@ -1,6 +1,6 @@
 /*
 goredo -- djb's redo implementation on pure Go
-Copyright (C) 2020-2023 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2020-2024 Sergey Matveev <stargrave@stargrave.org>
 
 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
@@ -25,7 +25,6 @@ import (
 )
 
 func targetsCollect(root string, tgts map[string]struct{}) error {
-       root = mustAbs(root)
        dir, err := os.Open(root)
        if err != nil {
                return ErrLine(err)
@@ -72,9 +71,9 @@ func targetsCollect(root string, tgts map[string]struct{}) error {
 }
 
 func targetsWalker(tgts []string) ([]string, error) {
-       tgtsMap := map[string]struct{}{}
+       tgtsMap := make(map[string]struct{})
        for _, tgt := range tgts {
-               if err := targetsCollect(tgt, tgtsMap); err != nil {
+               if err := targetsCollect(mustAbs(tgt), tgtsMap); err != nil {
                        return nil, err
                }
        }
@@ -86,12 +85,15 @@ func targetsWalker(tgts []string) ([]string, error) {
 }
 
 func collectWholeDeps(
-       tgts map[string]struct{},
-       deps map[string]map[string]struct{},
-       seen map[string]struct{},
+       tgts map[string]*Tgt,
+       deps map[string]map[string]*Tgt,
+       seen map[string]*Tgt,
 ) {
-       for tgt := range tgts {
-               seen[tgt] = struct{}{}
-               collectWholeDeps(deps[tgt], deps, seen)
+       for _, tgt := range tgts {
+               if _, exists := seen[tgt.rel]; exists {
+                       continue
+               }
+               seen[tgt.rel] = tgt
+               collectWholeDeps(deps[tgt.rel], deps, seen)
        }
 }