Skip to content

WIP: dependency repair modes #143

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ package_filegroup(
"//pkg/scalarule/mocks:filegroup",
"//pkg/semanticdb:filegroup",
"//pkg/starlarkeval:filegroup",
"//pkg/sweep:filegroup",
"//pkg/testutil:filegroup",
"//pkg/wildcardimport:filegroup",
"//rules:filegroup",
Expand Down
288 changes: 194 additions & 94 deletions build/stack/gazelle/scala/autokeep/autokeep.pb.go

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions build/stack/gazelle/scala/autokeep/autokeep.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ syntax = "proto3";

package build.stack.gazelle.scala.autokeep;

import "build/stack/gazelle/scala/parse/rule.proto";

option go_package = "github.com/stackb/scala-gazelle/build/stack/gazelle/scala/autokeep;autokeep";
option java_package = "build.stack.gazelle.scala.autokeep";
option java_multiple_files = true;
Expand All @@ -19,6 +17,7 @@ message ScalacError {
MissingSymbol missing_symbol = 3;
NotAMemberOfPackage not_a_member_of_package = 4;
BuildozerUnusedDep buildozer_unused_dep = 5;
TypeNotFound not_found = 6;
}
}

Expand All @@ -29,15 +28,21 @@ message MissingSymbol {
}

message NotAMemberOfPackage {
string package_name = 1;
string symbol = 2;
string source_file = 1;
string package_name = 2;
string symbol = 3;
}

message BuildozerUnusedDep {
string rule_label = 1;
string unused_dep = 2;
}

message TypeNotFound {
string source_file = 1;
string type = 2;
}

message RuleDeps {
string label = 1;
string build_file = 2;
Expand Down
47 changes: 28 additions & 19 deletions build/stack/gazelle/scala/parse/file.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions build/stack/gazelle/scala/parse/file.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ message File {
// tree is a JSON string representing the parse tree. This field is only
// populated when specifically requested during parsing.
string tree = 14;
// sha256 is the sha256 hash value of the file contents
string sha256 = 15;
}

// ClassList represents a set of files.
Expand Down
5 changes: 4 additions & 1 deletion cmd/autokeep/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ go_library(
srcs = ["autokeep.go"],
importpath = "github.com/stackb/scala-gazelle/cmd/autokeep",
visibility = ["//visibility:private"],
deps = ["//pkg/autokeep"],
deps = [
"//pkg/autokeep",
"//pkg/resolver",
],
)

go_binary(
Expand Down
7 changes: 6 additions & 1 deletion cmd/autokeep/autokeep.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/stackb/scala-gazelle/pkg/autokeep"
"github.com/stackb/scala-gazelle/pkg/resolver"
)

// autokeep is a program that consumes a scala-gazelle cache file, runs 'bazel
Expand Down Expand Up @@ -103,7 +104,11 @@ func run(cfg *config) error {
}

log.Printf("diagnostics: %+v", diagnostics)
keep := autokeep.MakeDeltaDeps(cfg.deps, diagnostics)

// FIXME(pcj): how to derive the global scope again from this command?
scope := resolver.NewTrieScope()

keep := autokeep.MakeDeltaDeps(diagnostics, scope, cfg.deps)
log.Printf("keep: %+v", keep)

if err := autokeep.ApplyDeltaDeps(keep, cfg.keep); err != nil {
Expand Down
9 changes: 8 additions & 1 deletion cmd/scalafileextract/scalafileextract.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func persistentWork(cfg *Config) error {
batchCfg.Cwd = cfg.Cwd

if err := batchWork(&batchCfg); err != nil {
return fmt.Errorf("performing persistent batch!: %v", err)
return fmt.Errorf("performing persistent batch: %v", err)
}

if err := protobuf.WriteDelimitedTo(&resp, os.Stdout); err != nil {
Expand Down Expand Up @@ -200,6 +200,13 @@ func extract(parser *parser.ScalametaParser, dir string, sourceFiles []string) (
return nil, fmt.Errorf(file.Error)
}
file.Filename = filenames[file.Filename]
if false {
sha256, err := collections.FileSha256(file.Filename)
if err != nil {
return nil, err
}
file.Sha256 = sha256
}
}

return response.Files, nil
Expand Down
6 changes: 5 additions & 1 deletion cmd/wildcardimportfixer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ func run(cfg *config) error {
BazelExecutable: cfg.bazelExe,
})

symbols, err := fixer.Fix(cfg.ruleLabel, cfg.targetFilename, cfg.importPrefix)
symbols, err := fixer.Fix(&wildcardimport.FixConfig{
RuleLabel: cfg.ruleLabel,
Filename: cfg.targetFilename,
ImportPrefix: cfg.importPrefix,
})
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emicklei/proto v1.9.0 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
Expand All @@ -32,7 +33,7 @@ require (
github.com/rs/zerolog v1.34.0 // indirect
github.com/stretchr/objx v0.1.0 // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.2.0 // indirect
golang.org/x/tools v0.2.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
Expand Down Expand Up @@ -163,6 +165,8 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
8 changes: 4 additions & 4 deletions go_repos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ def go_repositories():
name = "com_github_fsnotify_fsnotify",
build_file_proto_mode = "disable_global",
importpath = "github.com/fsnotify/fsnotify",
sum = "h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=",
version = "v1.6.0",
sum = "h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=",
version = "v1.9.0",
)
go_repository(
name = "com_github_ghodss_yaml",
Expand Down Expand Up @@ -554,8 +554,8 @@ def go_repositories():
name = "org_golang_x_sys",
build_file_proto_mode = "disable_global",
importpath = "golang.org/x/sys",
sum = "h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=",
version = "v0.12.0",
sum = "h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=",
version = "v0.13.0",
)
go_repository(
name = "org_golang_x_term",
Expand Down
11 changes: 5 additions & 6 deletions language/scala/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ load("@bazel_gazelle//:def.bzl", "gazelle_binary")
go_library(
name = "scala",
srcs = [
"cache.go",
"configure.go",
"conflict_resolver_registry.go",
"coverage.go",
Expand All @@ -21,11 +20,13 @@ go_library(
"imports.go",
"kinds.go",
"known_rule_registry.go",
"known_scope_registry.go",
"language.go",
"lifecycle.go",
"loads.go",
"package_marker_rule.go",
"progress.go",
"repair.go",
"resolve.go",
"scala_package.go",
"scala_rule.go",
Expand All @@ -49,6 +50,7 @@ go_library(
"//pkg/scalaconfig",
"//pkg/scalafiles",
"//pkg/scalarule",
"//pkg/sweep",
"//pkg/wildcardimport",
"@bazel_gazelle//config:go_default_library",
"@bazel_gazelle//label:go_default_library",
Expand Down Expand Up @@ -85,10 +87,6 @@ gazelle_binary(
go_test(
name = "scala_test",
srcs = [
# "coverage_test.go",
# "diff_test.go",
# "existing_scala_rule_test.go",
# "flags_test.go",
"coverage_test.go",
"diff_test.go",
"existing_scala_rule_test.go",
Expand Down Expand Up @@ -133,7 +131,6 @@ package_filegroup(
name = "filegroup",
srcs = [
"BUILD.bazel",
"cache.go",
"configure.go",
"conflict_resolver_registry.go",
"coverage.go",
Expand All @@ -152,13 +149,15 @@ package_filegroup(
"imports.go",
"kinds.go",
"known_rule_registry.go",
"known_scope_registry.go",
"language.go",
"language_test.go",
"lifecycle.go",
"loads.go",
"loads_test.go",
"package_marker_rule.go",
"progress.go",
"repair.go",
"resolve.go",
"scala.WORKSPACE",
"scala_package.go",
Expand Down
60 changes: 0 additions & 60 deletions language/scala/cache.go

This file was deleted.

Loading
Loading