1
- // Package analyze uses bazel query to determine and locate missing imports
1
+ // Package analyze uses blaze query to determine and locate missing imports
2
2
// in TypeScript source files.
3
3
package analyze
4
4
@@ -10,13 +10,13 @@ import (
10
10
"regexp"
11
11
"strings"
12
12
13
- "github.com/bazelbuild/buildtools/edit"
13
+ "google3/net/proto2/go/proto"
14
+ "google3/third_party/bazel_buildifier/edit/edit"
14
15
"github.com/bazelbuild/rules_typescript/ts_auto_deps/platform"
15
16
"github.com/bazelbuild/rules_typescript/ts_auto_deps/workspace"
16
- "github.com/golang/protobuf/proto"
17
17
18
- appb "github.com/bazelbuild/buildtools/build_proto "
19
- arpb "github.com/bazelbuild/ rules_typescript/ts_auto_deps/proto"
18
+ appb "google3/third_party/bazel/src/main/protobuf/build_go_proto "
19
+ arpb "google3/third_party/bazel_rules/ rules_typescript/ts_auto_deps/proto/analyze_result_go_proto "
20
20
)
21
21
22
22
var (
@@ -97,7 +97,7 @@ func New(loader TargetLoader) *Analyzer {
97
97
98
98
// Analyze generates a dependency report for each target label in labels.
99
99
//
100
- // dir is the directory that ts_auto_deps should execute in. Must be a sub-directory
100
+ // dir is the directory that taze should execute in. Must be a sub-directory
101
101
// of the workspace root.
102
102
func (a * Analyzer ) Analyze (ctx context.Context , dir string , labels []string ) ([]* arpb.DependencyReport , error ) {
103
103
if len (labels ) == 0 {
@@ -124,14 +124,14 @@ func (a *Analyzer) Analyze(ctx context.Context, dir string, labels []string) ([]
124
124
return a .generateReports (labels , resolved )
125
125
}
126
126
127
- // resolvedTarget represents a Bazel target and all resolved information.
127
+ // resolvedTarget represents a Blaze target and all resolved information.
128
128
type resolvedTarget struct {
129
129
label string
130
130
// A map of all existing dependencies on a target at the time of analysis.
131
131
// The keys are labels and the values are thes loaded target.
132
132
dependencies map [string ]* appb.Rule
133
133
// A map of source file paths to their imports.
134
- imports map [string ][]* ts_auto_depsImport
134
+ imports map [string ][]* tazeImport
135
135
// rule is the original rule the target was constructed from.
136
136
rule * appb.Rule
137
137
// missingSources are source files which could not be opened on disk.
@@ -147,7 +147,7 @@ type resolvedTarget struct {
147
147
// setSources sets the sources on t. It returns an error if one of the srcs of
148
148
// t's rule isn't in loadedSrcs. It also sorts the sources into literal and
149
149
// generated sources, setting literalSourcePaths and generatedSourcePaths.
150
- // Returns an error if all the sources are generated - ts_auto_deps can't read the
150
+ // Returns an error if all the sources are generated - taze can't read the
151
151
// import statements to determine deps.
152
152
func (t * resolvedTarget ) setSources (loadedSrcs map [string ]* appb.Target ) error {
153
153
for _ , label := range listAttribute (t .rule , "srcs" ) {
@@ -220,7 +220,7 @@ func newResolvedTarget(r *appb.Rule) *resolvedTarget {
220
220
return & resolvedTarget {
221
221
label : r .GetName (),
222
222
dependencies : make (map [string ]* appb.Rule ),
223
- imports : make (map [string ][]* ts_auto_depsImport ),
223
+ imports : make (map [string ][]* tazeImport ),
224
224
rule : r ,
225
225
sources : make (map [string ]* appb.Target ),
226
226
}
@@ -264,7 +264,7 @@ func (a *Analyzer) resolveImportsForTargets(ctx context.Context, currentPkg, roo
264
264
return nil , err
265
265
}
266
266
}
267
- // only extract the imports out of the literal sources, since ts_auto_deps can't
267
+ // only extract the imports out of the literal sources, since taze can't
268
268
// see the contents of generated files
269
269
allLiteralSrcPaths , err := getAllLiteralSrcPaths (targets )
270
270
if err != nil {
@@ -302,7 +302,7 @@ func (a *Analyzer) resolveImportsForTargets(ctx context.Context, currentPkg, roo
302
302
func (a * Analyzer ) resolveImports (ctx context.Context , currentPkg , root string , targets map [string ]* resolvedTarget ) error {
303
303
for _ , target := range targets {
304
304
var paths []string
305
- needingResolution := make (map [string ][]* ts_auto_depsImport )
305
+ needingResolution := make (map [string ][]* tazeImport )
306
306
for _ , imports := range target .imports {
307
307
handlingImports:
308
308
for _ , imp := range imports {
@@ -363,7 +363,7 @@ var ambientModuleDeclRE = regexp.MustCompile("(?m)^\\s*declare\\s+module\\s+['\"
363
363
//
364
364
// If the import already has a knownTarget, findRuleProvidingImport will
365
365
// return the knownTarget.
366
- func (a * Analyzer ) findExistingDepProvidingImport (ctx context.Context , root string , rt * resolvedTarget , i * ts_auto_depsImport ) (string , error ) {
366
+ func (a * Analyzer ) findExistingDepProvidingImport (ctx context.Context , root string , rt * resolvedTarget , i * tazeImport ) (string , error ) {
367
367
if i .knownTarget != "" {
368
368
return i .knownTarget , nil
369
369
}
@@ -545,17 +545,17 @@ func (a *Analyzer) generateReport(target *resolvedTarget) (*arpb.DependencyRepor
545
545
// TypeScript declarations might declare arbitrary global symbols, so it
546
546
// is impossible to detect reliably if the import is being used (without
547
547
// compiling, at least). Report that the rule has no explicit import as a
548
- // warning, so that ts_auto_deps can decide to import remove or not based on a
548
+ // warning, so that taze can decide to import remove or not based on a
549
549
// flag.
550
550
warning := fmt .Sprintf ("WARNING: %s: keeping possibly used %s '%s'" , rule .GetLocation (), class , label )
551
551
report .Feedback = append (report .Feedback , warning )
552
552
case "css_library" :
553
- // Similar to ts_declaration, ts_auto_deps can't reliably detect if css_library
554
- // imports are being used, since ts_auto_deps can't currently parse @requirecss
553
+ // Similar to ts_declaration, taze can't reliably detect if css_library
554
+ // imports are being used, since taze can't currently parse @requirecss
555
555
// annotations. Unlike ts_declaration, there's no flag to remove them, so
556
556
// there's no need to report a warning.
557
557
default :
558
- // The contents of generated files aren't visible, so ts_auto_deps can't discover
558
+ // The contents of generated files aren't visible, so taze can't discover
559
559
// the import statements/deps that they contain. To be safe, don't remove
560
560
// any unused deps, since they might be used by the generated file(s).
561
561
if len (target .generatedSourcePaths ) == 0 {
0 commit comments