1# 2# Copyright 2019 The Abseil Authors. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# https://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16 17load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") 18load( 19 "//absl:copts/configure_copts.bzl", 20 "ABSL_DEFAULT_COPTS", 21 "ABSL_DEFAULT_LINKOPTS", 22 "ABSL_TEST_COPTS", 23) 24 25package(default_visibility = ["//visibility:public"]) 26 27licenses(["notice"]) 28 29cc_library( 30 name = "path_util", 31 hdrs = [ 32 "internal/path_util.h", 33 ], 34 copts = ABSL_DEFAULT_COPTS, 35 linkopts = ABSL_DEFAULT_LINKOPTS, 36 visibility = [ 37 "//absl/flags:__pkg__", 38 ], 39 deps = [ 40 "//absl/base:config", 41 "//absl/strings", 42 ], 43) 44 45cc_library( 46 name = "program_name", 47 srcs = [ 48 "internal/program_name.cc", 49 ], 50 hdrs = [ 51 "internal/program_name.h", 52 ], 53 copts = ABSL_DEFAULT_COPTS, 54 linkopts = ABSL_DEFAULT_LINKOPTS, 55 visibility = [ 56 "//absl/flags:__pkg__", 57 ], 58 deps = [ 59 ":path_util", 60 "//absl/base:config", 61 "//absl/base:core_headers", 62 "//absl/strings", 63 "//absl/synchronization", 64 ], 65) 66 67cc_library( 68 name = "config", 69 srcs = [ 70 "usage_config.cc", 71 ], 72 hdrs = [ 73 "config.h", 74 "usage_config.h", 75 ], 76 copts = ABSL_DEFAULT_COPTS, 77 linkopts = ABSL_DEFAULT_LINKOPTS, 78 deps = [ 79 ":path_util", 80 ":program_name", 81 "//absl/base:config", 82 "//absl/base:core_headers", 83 "//absl/strings", 84 "//absl/synchronization", 85 ], 86) 87 88cc_library( 89 name = "marshalling", 90 srcs = [ 91 "marshalling.cc", 92 ], 93 hdrs = [ 94 "marshalling.h", 95 ], 96 copts = ABSL_DEFAULT_COPTS, 97 linkopts = ABSL_DEFAULT_LINKOPTS, 98 deps = [ 99 "//absl/base:config", 100 "//absl/base:core_headers", 101 "//absl/base:log_severity", 102 "//absl/strings", 103 "//absl/strings:str_format", 104 ], 105) 106 107cc_library( 108 name = "commandlineflag_internal", 109 srcs = [ 110 "internal/commandlineflag.cc", 111 ], 112 hdrs = [ 113 "internal/commandlineflag.h", 114 ], 115 copts = ABSL_DEFAULT_COPTS, 116 linkopts = ABSL_DEFAULT_LINKOPTS, 117 deps = [ 118 "//absl/base:config", 119 "//absl/base:fast_type_id", 120 ], 121) 122 123cc_library( 124 name = "commandlineflag", 125 srcs = [ 126 "commandlineflag.cc", 127 ], 128 hdrs = [ 129 "commandlineflag.h", 130 ], 131 copts = ABSL_DEFAULT_COPTS, 132 linkopts = ABSL_DEFAULT_LINKOPTS, 133 deps = [ 134 ":commandlineflag_internal", 135 "//absl/base:config", 136 "//absl/base:fast_type_id", 137 "//absl/strings", 138 "//absl/types:optional", 139 ], 140) 141 142cc_library( 143 name = "private_handle_accessor", 144 srcs = [ 145 "internal/private_handle_accessor.cc", 146 ], 147 hdrs = [ 148 "internal/private_handle_accessor.h", 149 ], 150 copts = ABSL_DEFAULT_COPTS, 151 linkopts = ABSL_DEFAULT_LINKOPTS, 152 visibility = [ 153 "//absl/flags:__pkg__", 154 ], 155 deps = [ 156 ":commandlineflag", 157 ":commandlineflag_internal", 158 "//absl/base:config", 159 "//absl/strings", 160 ], 161) 162 163cc_library( 164 name = "reflection", 165 srcs = [ 166 "reflection.cc", 167 ], 168 hdrs = [ 169 "internal/registry.h", 170 "reflection.h", 171 ], 172 copts = ABSL_DEFAULT_COPTS, 173 linkopts = ABSL_DEFAULT_LINKOPTS, 174 deps = [ 175 ":commandlineflag", 176 ":commandlineflag_internal", 177 ":config", 178 ":private_handle_accessor", 179 "//absl/base:config", 180 "//absl/base:core_headers", 181 "//absl/container:flat_hash_map", 182 "//absl/strings", 183 "//absl/synchronization", 184 ], 185) 186 187cc_library( 188 name = "flag_internal", 189 srcs = [ 190 "internal/flag.cc", 191 ], 192 hdrs = [ 193 "internal/flag.h", 194 "internal/sequence_lock.h", 195 ], 196 copts = ABSL_DEFAULT_COPTS, 197 linkopts = ABSL_DEFAULT_LINKOPTS, 198 visibility = ["//absl/base:__subpackages__"], 199 deps = [ 200 ":commandlineflag", 201 ":commandlineflag_internal", 202 ":config", 203 ":marshalling", 204 ":reflection", 205 "//absl/base", 206 "//absl/base:config", 207 "//absl/base:core_headers", 208 "//absl/memory", 209 "//absl/meta:type_traits", 210 "//absl/strings", 211 "//absl/synchronization", 212 "//absl/utility", 213 ], 214) 215 216cc_library( 217 name = "flag", 218 srcs = [ 219 "flag.cc", 220 ], 221 hdrs = [ 222 "declare.h", 223 "flag.h", 224 ], 225 copts = ABSL_DEFAULT_COPTS, 226 linkopts = ABSL_DEFAULT_LINKOPTS, 227 deps = [ 228 ":config", 229 ":flag_internal", 230 ":reflection", 231 "//absl/base", 232 "//absl/base:config", 233 "//absl/base:core_headers", 234 "//absl/strings", 235 ], 236) 237 238cc_library( 239 name = "usage_internal", 240 srcs = [ 241 "internal/usage.cc", 242 ], 243 hdrs = [ 244 "internal/usage.h", 245 ], 246 copts = ABSL_DEFAULT_COPTS, 247 linkopts = ABSL_DEFAULT_LINKOPTS, 248 visibility = [ 249 "//absl/flags:__pkg__", 250 ], 251 deps = [ 252 ":commandlineflag", 253 ":config", 254 ":flag", 255 ":flag_internal", 256 ":path_util", 257 ":private_handle_accessor", 258 ":program_name", 259 ":reflection", 260 "//absl/base:config", 261 "//absl/base:core_headers", 262 "//absl/container:flat_hash_map", 263 "//absl/strings", 264 ], 265) 266 267cc_library( 268 name = "usage", 269 srcs = [ 270 "usage.cc", 271 ], 272 hdrs = [ 273 "usage.h", 274 ], 275 copts = ABSL_DEFAULT_COPTS, 276 linkopts = ABSL_DEFAULT_LINKOPTS, 277 deps = [ 278 ":usage_internal", 279 "//absl/base:config", 280 "//absl/base:core_headers", 281 "//absl/strings", 282 "//absl/synchronization", 283 ], 284) 285 286cc_library( 287 name = "parse", 288 srcs = ["parse.cc"], 289 hdrs = [ 290 "internal/parse.h", 291 "parse.h", 292 ], 293 copts = ABSL_DEFAULT_COPTS, 294 linkopts = ABSL_DEFAULT_LINKOPTS, 295 deps = [ 296 ":commandlineflag", 297 ":commandlineflag_internal", 298 ":config", 299 ":flag", 300 ":flag_internal", 301 ":private_handle_accessor", 302 ":program_name", 303 ":reflection", 304 ":usage", 305 ":usage_internal", 306 "//absl/base:config", 307 "//absl/base:core_headers", 308 "//absl/strings", 309 "//absl/synchronization", 310 ], 311) 312 313############################################################################ 314# Unit tests in alphabetical order. 315 316cc_test( 317 name = "commandlineflag_test", 318 size = "small", 319 srcs = [ 320 "commandlineflag_test.cc", 321 ], 322 copts = ABSL_TEST_COPTS, 323 linkopts = ABSL_DEFAULT_LINKOPTS, 324 deps = [ 325 ":commandlineflag", 326 ":commandlineflag_internal", 327 ":config", 328 ":flag", 329 ":private_handle_accessor", 330 ":reflection", 331 "//absl/memory", 332 "//absl/strings", 333 "@com_google_googletest//:gtest_main", 334 ], 335) 336 337cc_test( 338 name = "config_test", 339 size = "small", 340 srcs = [ 341 "config_test.cc", 342 ], 343 copts = ABSL_TEST_COPTS, 344 linkopts = ABSL_DEFAULT_LINKOPTS, 345 deps = [ 346 ":config", 347 "@com_google_googletest//:gtest_main", 348 ], 349) 350 351cc_test( 352 name = "flag_test", 353 size = "small", 354 srcs = [ 355 "flag_test.cc", 356 "flag_test_defs.cc", 357 ], 358 copts = ABSL_TEST_COPTS, 359 linkopts = ABSL_DEFAULT_LINKOPTS, 360 deps = [ 361 ":config", 362 ":flag", 363 ":flag_internal", 364 ":marshalling", 365 ":reflection", 366 "//absl/base:core_headers", 367 "//absl/base:malloc_internal", 368 "//absl/strings", 369 "//absl/time", 370 "@com_google_googletest//:gtest_main", 371 ], 372) 373 374cc_binary( 375 name = "flag_benchmark", 376 testonly = 1, 377 srcs = [ 378 "flag_benchmark.cc", 379 ], 380 copts = ABSL_TEST_COPTS, 381 linkopts = select({ 382 "//conditions:default": [], 383 }) + ABSL_DEFAULT_LINKOPTS, 384 tags = ["benchmark"], 385 visibility = ["//visibility:private"], 386 deps = [ 387 "flag_benchmark.lds", 388 ":flag", 389 ":marshalling", 390 ":parse", 391 ":reflection", 392 "//absl/strings", 393 "//absl/time", 394 "//absl/types:optional", 395 "@com_github_google_benchmark//:benchmark_main", 396 ], 397) 398 399cc_test( 400 name = "marshalling_test", 401 size = "small", 402 srcs = [ 403 "marshalling_test.cc", 404 ], 405 copts = ABSL_TEST_COPTS, 406 linkopts = ABSL_DEFAULT_LINKOPTS, 407 deps = [ 408 ":marshalling", 409 "@com_google_googletest//:gtest_main", 410 ], 411) 412 413cc_test( 414 name = "parse_test", 415 size = "small", 416 srcs = [ 417 "parse_test.cc", 418 ], 419 copts = ABSL_TEST_COPTS, 420 linkopts = ABSL_DEFAULT_LINKOPTS, 421 deps = [ 422 ":flag", 423 ":parse", 424 ":reflection", 425 ":usage_internal", 426 "//absl/base:raw_logging_internal", 427 "//absl/base:scoped_set_env", 428 "//absl/strings", 429 "//absl/types:span", 430 "@com_google_googletest//:gtest_main", 431 ], 432) 433 434cc_test( 435 name = "path_util_test", 436 size = "small", 437 srcs = [ 438 "internal/path_util_test.cc", 439 ], 440 copts = ABSL_TEST_COPTS, 441 linkopts = ABSL_DEFAULT_LINKOPTS, 442 deps = [ 443 ":path_util", 444 "@com_google_googletest//:gtest_main", 445 ], 446) 447 448cc_test( 449 name = "program_name_test", 450 size = "small", 451 srcs = [ 452 "internal/program_name_test.cc", 453 ], 454 copts = ABSL_TEST_COPTS, 455 linkopts = ABSL_DEFAULT_LINKOPTS, 456 deps = [ 457 ":program_name", 458 "//absl/strings", 459 "@com_google_googletest//:gtest_main", 460 ], 461) 462 463cc_test( 464 name = "reflection_test", 465 size = "small", 466 srcs = [ 467 "reflection_test.cc", 468 ], 469 copts = ABSL_TEST_COPTS, 470 linkopts = ABSL_DEFAULT_LINKOPTS, 471 deps = [ 472 ":commandlineflag_internal", 473 ":flag", 474 ":marshalling", 475 ":reflection", 476 ":usage_internal", 477 "//absl/memory", 478 "//absl/strings", 479 "@com_google_googletest//:gtest_main", 480 ], 481) 482 483cc_test( 484 name = "sequence_lock_test", 485 size = "small", 486 timeout = "moderate", 487 srcs = [ 488 "internal/sequence_lock_test.cc", 489 ], 490 copts = ABSL_TEST_COPTS, 491 linkopts = ABSL_DEFAULT_LINKOPTS, 492 shard_count = 31, 493 deps = [ 494 ":flag_internal", 495 "//absl/base", 496 "//absl/container:fixed_array", 497 "//absl/time", 498 "@com_google_googletest//:gtest_main", 499 ], 500) 501 502cc_test( 503 name = "usage_config_test", 504 size = "small", 505 srcs = [ 506 "usage_config_test.cc", 507 ], 508 copts = ABSL_TEST_COPTS, 509 linkopts = ABSL_DEFAULT_LINKOPTS, 510 deps = [ 511 ":config", 512 ":path_util", 513 ":program_name", 514 "//absl/strings", 515 "@com_google_googletest//:gtest_main", 516 ], 517) 518 519cc_test( 520 name = "usage_test", 521 size = "small", 522 srcs = [ 523 "internal/usage_test.cc", 524 ], 525 copts = ABSL_TEST_COPTS, 526 linkopts = ABSL_DEFAULT_LINKOPTS, 527 deps = [ 528 ":config", 529 ":flag", 530 ":parse", 531 ":path_util", 532 ":program_name", 533 ":reflection", 534 ":usage", 535 ":usage_internal", 536 "//absl/strings", 537 "@com_google_googletest//:gtest", 538 ], 539) 540