kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/go/indexer/BUILD (about) 1 load("//kythe/go/test/tools/empty_corpus_checker:empty_corpus_test.bzl", "empty_corpus_test") 2 load("//tools:build_rules/shims.bzl", "go_library", "go_test") 3 load(":flags.bzl", "flag_constructor", "flag_constructors") 4 load(":testdata/go_indexer_test.bzl", "go_indexer_test") 5 load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 6 7 package(default_visibility = ["//kythe:default_visibility"]) 8 9 go_library( 10 name = "indexer", 11 srcs = [ 12 "emit.go", 13 "facts.go", 14 "indexer.go", 15 "markedsource.go", 16 ], 17 importpath = "kythe.io/kythe/go/indexer", 18 deps = [ 19 "//kythe/go/extractors/govname", 20 "//kythe/go/util/kytheuri", 21 "//kythe/go/util/log", 22 "//kythe/go/util/metadata", 23 "//kythe/go/util/ptypes", 24 "//kythe/go/util/schema/edges", 25 "//kythe/go/util/schema/facts", 26 "//kythe/go/util/schema/nodes", 27 "//kythe/proto:analysis_go_proto", 28 "//kythe/proto:common_go_proto", 29 "//kythe/proto:go_go_proto", 30 "//kythe/proto:metadata_go_proto", 31 "//kythe/proto:storage_go_proto", 32 "@com_github_golang_protobuf//proto:go_default_library", 33 "@org_bitbucket_creachadair_stringset//:stringset", 34 "@org_golang_x_tools//go/gcexportdata", 35 "@org_golang_x_tools//go/types/typeutil", 36 ], 37 ) 38 39 go_test( 40 name = "indexer_test", 41 size = "small", 42 srcs = ["indexer_test.go"], 43 # TODO(fromberger): Build this with a library rule. 44 data = [":testdata/foo.a"], 45 library = ":indexer", 46 deps = [ 47 "//kythe/go/test/testutil", 48 "//kythe/go/util/log", 49 "//kythe/go/util/metadata", 50 "//kythe/go/util/ptypes", 51 "//kythe/go/util/schema/edges", 52 "//kythe/proto:analysis_go_proto", 53 "//kythe/proto:go_go_proto", 54 "//kythe/proto:metadata_go_proto", 55 "//kythe/proto:storage_go_proto", 56 "@com_github_golang_protobuf//proto:go_default_library", 57 ], 58 ) 59 60 bzl_library( 61 name = "go_indexer_test_bzl", 62 srcs = ["testdata/go_indexer_test.bzl"], 63 visibility = ["//visibility:private"], 64 ) 65 66 go_indexer_test( 67 name = "builtin_test", 68 srcs = ["testdata/builtin.go"], 69 extra_goals = ["testdata/builtin.go"], 70 has_marked_source = True, 71 import_path = "builtin", 72 resolve_code_facts = True, 73 use_file_as_top_level_scope = True, 74 ) 75 76 go_indexer_test( 77 name = "genericstruct_test", 78 srcs = ["testdata/generics/genericstruct.go"], 79 has_marked_source = True, 80 ) 81 82 go_indexer_test( 83 name = "genericmethod_test", 84 srcs = ["testdata/generics/genericmethod.go"], 85 has_marked_source = True, 86 ) 87 88 go_indexer_test( 89 name = "genericinterface_test", 90 srcs = ["testdata/generics/genericinterface.go"], 91 has_marked_source = True, 92 ) 93 94 go_indexer_test( 95 name = "genericfunc_test", 96 srcs = ["testdata/generics/genericfunc.go"], 97 has_marked_source = True, 98 ) 99 100 go_indexer_test( 101 name = "genericdep_test", 102 srcs = ["testdata/generics/genericdep.go"], 103 has_marked_source = True, 104 deps = [":genericinterface_test"], 105 ) 106 107 go_indexer_test( 108 name = "syntax_test", 109 srcs = ["testdata/syntax.go"], 110 ) 111 112 go_indexer_test( 113 name = "deprecation_test", 114 srcs = ["testdata/basic/deprecation.go"], 115 ) 116 117 go_indexer_test( 118 name = "filenode_test", 119 srcs = ["testdata/basic/filenode.go"], 120 import_path = "test/basic", 121 ) 122 123 go_indexer_test( 124 name = "varref_test", 125 srcs = ["testdata/basic/varref.go"], 126 ) 127 128 go_indexer_test( 129 name = "funcall_test", 130 srcs = ["testdata/basic/funcall.go"], 131 import_path = "test/fun", 132 ) 133 134 go_indexer_test( 135 name = "funcallid_test", 136 srcs = ["testdata/basic/funcallid.go"], 137 extra_indexer_args = ["-emit_ref_call_over_identifier"], 138 import_path = "test/fun", 139 ) 140 141 go_indexer_test( 142 name = "functions_test", 143 srcs = ["testdata/basic/functions.go"], 144 import_path = "test/fun", 145 ) 146 147 go_indexer_test( 148 name = "package_test", 149 srcs = ["testdata/basic/packages.go"], 150 import_path = "test/pkg", 151 ) 152 153 go_indexer_test( 154 name = "vardef_test", 155 srcs = ["testdata/basic/vardef.go"], 156 ) 157 158 go_indexer_test( 159 name = "typespec_test", 160 srcs = ["testdata/basic/typespec.go"], 161 ) 162 163 go_indexer_test( 164 name = "locals_test", 165 srcs = ["testdata/basic/locals.go"], 166 ) 167 168 go_indexer_test( 169 name = "writes_test", 170 srcs = ["testdata/basic/writes.go"], 171 ) 172 173 go_indexer_test( 174 name = "imports_test", 175 srcs = ["testdata/basic/imports.go"], 176 ) 177 178 go_indexer_test( 179 name = "scopes_test", 180 srcs = ["testdata/basic/scopes.go"], 181 emit_anchor_scopes = True, 182 ) 183 184 go_indexer_test( 185 name = "scopes_test_fs", 186 srcs = ["testdata/basic/scopes.go"], 187 emit_anchor_scopes = True, 188 use_fast_solver = True, 189 ) 190 191 go_indexer_test( 192 name = "comment_test", 193 srcs = ["testdata/basic/comments.go"], 194 ) 195 196 go_indexer_test( 197 name = "doc_test", 198 srcs = ["testdata/basic/docs.go"], 199 ) 200 201 go_indexer_test( 202 name = "unsafe_test", 203 srcs = ["testdata/unsafe.go"], 204 ) 205 206 go_indexer_test( 207 name = "satisfies_test", 208 srcs = ["testdata/basic/satisfies.go"], 209 ) 210 211 go_indexer_test( 212 name = "structref_test", 213 srcs = ["testdata/basic/structref.go"], 214 ) 215 216 go_indexer_test( 217 name = "inline_test", 218 srcs = ["testdata/basic/inline.go"], 219 metadata_suffix = ".linkage", 220 ) 221 222 go_indexer_test( 223 name = "code_rendered_test", 224 srcs = ["testdata/code/rendered.go"], 225 has_marked_source = True, 226 import_path = "rendered", 227 resolve_code_facts = True, 228 deps = [":builtin_test"], 229 ) 230 231 go_indexer_test( 232 name = "code_function_test", 233 srcs = ["testdata/code/funcdecl.go"], 234 has_marked_source = True, 235 import_path = "funcdecl", 236 ) 237 238 go_indexer_test( 239 name = "code_interface_test", 240 srcs = ["testdata/code/interface.go"], 241 has_marked_source = True, 242 import_path = "test/iface", 243 ) 244 245 go_indexer_test( 246 name = "code_var_test", 247 srcs = ["testdata/code/pkgvar.go"], 248 has_marked_source = True, 249 import_path = "pkgvar", 250 ) 251 252 go_indexer_test( 253 name = "code_struct_test", 254 srcs = ["testdata/code/structtype.go"], 255 has_marked_source = True, 256 import_path = "structtype", 257 ) 258 259 go_indexer_test( 260 name = "code_method_test", 261 srcs = ["testdata/code/methdecl.go"], 262 has_marked_source = True, 263 import_path = "methdecl", 264 ) 265 266 go_indexer_test( 267 name = "override_test", 268 srcs = ["testdata/override.go"], 269 ) 270 271 go_indexer_test( 272 name = "metadata_test", 273 srcs = ["testdata/meta.go"], 274 data = ["testdata/meta.go.linkage"], 275 metadata_suffix = ".linkage", 276 ) 277 278 go_indexer_test( 279 name = "anchors_test", 280 srcs = ["testdata/basic/anchors.go"], 281 ) 282 283 go_indexer_test( 284 name = "anonymous_test", 285 srcs = ["testdata/basic/anonymous.go"], 286 ) 287 288 go_indexer_test( 289 name = "anonref_test", 290 srcs = ["testdata/basic/anonref.go"], 291 deps = [":anonymous_test"], 292 ) 293 294 go_indexer_test( 295 name = "structinit_test", 296 srcs = ["testdata/structinit.go"], 297 ) 298 299 go_indexer_test( 300 name = "initcall_test", 301 srcs = ["testdata/initcall.go"], 302 ) 303 304 go_indexer_test( 305 name = "packageinit_test", 306 srcs = ["testdata/basic/packageinit.go"], 307 import_path = "test/pkginit", 308 ) 309 310 go_indexer_test( 311 name = "packageinit_file_test", 312 srcs = ["testdata/basic/packageinit_file.go"], 313 import_path = "test/pkginit", 314 use_file_as_top_level_scope = True, 315 ) 316 317 go_indexer_test( 318 name = "types_test", 319 srcs = ["testdata/types.go"], 320 has_marked_source = True, 321 ) 322 323 go_indexer_test( 324 name = "types_test_fs", 325 srcs = ["testdata/types.go"], 326 has_marked_source = True, 327 use_fast_solver = True, 328 ) 329 330 go_indexer_test( 331 name = "dep.v2", 332 srcs = ["testdata/dep.v2.go"], 333 ) 334 335 go_indexer_test( 336 name = "dependent_test", 337 srcs = ["testdata/dependent.go"], 338 has_marked_source = True, 339 deps = [ 340 ":dep.v2", 341 ":types_test", 342 ], 343 ) 344 345 go_indexer_test( 346 name = "tappcorpus_test", 347 srcs = ["testdata/basic/tappcorpus.go"], 348 use_compilation_corpus_for_all = True, 349 ) 350 351 empty_corpus_test( 352 name = "empty_corpus_test", 353 entries = ":tappcorpus_test_entries.entries.gz", 354 ) 355 356 go_indexer_test( 357 name = "stdlibimport_test", 358 srcs = ["testdata/basic/stdlibimport.go"], 359 extra_extractor_args = [ 360 "--use_default_corpus_for_stdlib", 361 "--corpus=kythe", 362 ], 363 use_compilation_corpus_for_all = True, 364 ) 365 366 # Test that extracting and indexing a go package that imports standard libraries 367 # does not contain entries in the "golang.org" corpus when 368 # --use_default_corpus_for_stdlib is enabled. 369 empty_corpus_test( 370 name = "stdlibimport_corpus_test", 371 allowed_corpora = ["kythe"], 372 entries = ":stdlibimport_test_entries.entries.gz", 373 ) 374 375 go_indexer_test( 376 name = "stdliboverride_test", 377 srcs = ["testdata/basic/stdliboverride.go"], 378 extra_extractor_args = [ 379 "--corpus=kythe", 380 ], 381 override_stdlib_corpus = "STDLIB_OVERRIDE", 382 use_compilation_corpus_for_all = True, 383 ) 384 385 standard_flags = { 386 # Standard func(name, default, desc) flags in the "flag" package. 387 "flag": [ 388 "Bool", 389 "Duration", 390 "Float64", 391 "Int", 392 "Int64", 393 "String", 394 "Uint", 395 "Uint64", 396 ], 397 } 398 399 standard_var_flags = { 400 # Standard func(var, name, default, desc) flags in the "flag" package. 401 "flag": [ 402 "BoolVar", 403 "DurationVar", 404 "Float64Var", 405 "Int64Var", 406 "IntVar", 407 "StringVar", 408 "TextVar", 409 "Uint64Var", 410 "UintVar", 411 ], 412 } 413 414 custom_flags = [ 415 # Func flag constructors in the "flag" package. 416 flag_constructor( 417 description_arg_position = 1, 418 func_name = "Func", 419 name_arg_position = 0, 420 pkg_path = "flag", 421 ), 422 flag_constructor( 423 description_arg_position = 1, 424 func_name = "BoolFunc", 425 name_arg_position = 0, 426 pkg_path = "flag", 427 ), 428 # Var flag constructor w/o a default in the "flag" package. 429 flag_constructor( 430 description_arg_position = 2, 431 func_name = "Var", 432 name_arg_position = 1, 433 pkg_path = "flag", 434 var_arg_position = 0, 435 ), 436 ] 437 438 flag_constructors( 439 name = "standard_flags", 440 custom_flags = custom_flags, 441 standard_flags = standard_flags, 442 standard_var_flags = standard_var_flags, 443 ) 444 445 flag_constructors( 446 name = "test_flags", 447 custom_flags = custom_flags, 448 standard_flags = standard_flags | { 449 "flags": ["CustomFlag"], 450 }, 451 standard_var_flags = standard_var_flags, 452 ) 453 454 go_indexer_test( 455 name = "flags_test", 456 srcs = ["testdata/flags.go"], 457 data = [":test_flags"], 458 extra_indexer_args = [ 459 "-flag_constructors=$(location :test_flags)", 460 ], 461 ) 462 463 # load(":testdata/go_indexer_test.bzl", "go_integration_test") 464 # TODO(#2375): (closed?) requires MarkedSource resolution in pipeline 465 # go_integration_test( 466 # name = "marked_source_integration_test", 467 # srcs = ["testdata/integration/marked_source.go"], 468 # file_tickets = [ 469 # "kythe:?path=src/test/marked_source/marked_source.go", 470 # ], 471 # has_marked_source = True, 472 # )