Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dead code #784

Merged
merged 1 commit into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 0 additions & 94 deletions pkg/skaffold/build/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,96 +18,12 @@ package build

import (
"fmt"
"path/filepath"
"sort"
"strings"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/bazel"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/v1alpha2"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

// DependencyMap is a bijection between artifacts and the files they depend on.
type DependencyMap struct {
artifacts []*v1alpha2.Artifact
pathToArtifacts map[string][]*v1alpha2.Artifact
}

//TODO(@r2d4): Figure out best UX to support configuring this blacklist
var ignoredPrefixes = []string{"vendor", ".git"}

func (d *DependencyMap) Paths() []string {
allPaths := []string{}
for path := range d.pathToArtifacts {
allPaths = append(allPaths, path)
}
sort.Strings(allPaths)
return allPaths
}

func (d *DependencyMap) ArtifactsForPaths(paths []string) []*v1alpha2.Artifact {
m := map[*v1alpha2.Artifact]struct{}{}
for _, p := range paths {
artifacts := d.pathToArtifacts[p]
for _, a := range artifacts {
m[a] = struct{}{}
}
}
artifacts := []*v1alpha2.Artifact{}
for a := range m {
artifacts = append(artifacts, a)
}
return artifacts
}

func NewDependencyMap(artifacts []*v1alpha2.Artifact) (*DependencyMap, error) {
m, err := pathToArtifactMap(artifacts)
if err != nil {
return nil, errors.Wrap(err, "generating path to artifact map")
}

return NewExplicitDependencyMap(artifacts, m), nil
}

func NewExplicitDependencyMap(artifacts []*v1alpha2.Artifact, pathToArtifacts map[string][]*v1alpha2.Artifact) *DependencyMap {
return &DependencyMap{
artifacts: artifacts,
pathToArtifacts: pathToArtifacts,
}
}

func pathToArtifactMap(artifacts []*v1alpha2.Artifact) (map[string][]*v1alpha2.Artifact, error) {
m := make(map[string][]*v1alpha2.Artifact)

for _, a := range artifacts {
deps, err := DependenciesForArtifact(a)
if err != nil {
return nil, errors.Wrapf(err, "getting dependencies for artifact %s", a.ImageName)
}
logrus.Infof("Source code dependencies %s: %s", a.ImageName, deps)

for _, dep := range deps {
//TODO(r2d4): what does the ignore workspace look like for bazel?
ignored, err := isIgnored(dep)
if err != nil {
return nil, errors.Wrapf(err, "calculating ignored files for artifact %s", a.ImageName)
}

if ignored {
logrus.Debugf("Ignoring %s for artifact dependencies", dep)
continue
}

path := filepath.Join(a.Workspace, dep)
m[path] = append(m[path], a)
}
}

return m, nil
}

// DependenciesForArtifact is used in tests.
var DependenciesForArtifact = dependenciesForArtifact

Expand All @@ -121,13 +37,3 @@ func dependenciesForArtifact(a *v1alpha2.Artifact) ([]string, error) {

return nil, fmt.Errorf("undefined artifact type: %+v", a.ArtifactType)
}

func isIgnored(path string) (bool, error) {
for _, ignoredPrefix := range ignoredPrefixes {
if strings.HasPrefix(path, ignoredPrefix) {
return true, nil
}
}

return false, nil
}
80 changes: 0 additions & 80 deletions pkg/skaffold/build/deps_test.go

This file was deleted.