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_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"]) # Apache 2.0 28 29cc_library( 30 name = "flag_internal", 31 srcs = [ 32 "internal/flag.cc", 33 ], 34 hdrs = [ 35 "internal/flag.h", 36 ], 37 copts = ABSL_DEFAULT_COPTS, 38 linkopts = ABSL_DEFAULT_LINKOPTS, 39 visibility = ["//absl/base:__subpackages__"], 40 deps = [ 41 ":config", 42 ":handle", 43 ":registry", 44 "//absl/base", 45 "//absl/base:config", 46 "//absl/base:core_headers", 47 "//absl/memory", 48 "//absl/strings", 49 "//absl/synchronization", 50 ], 51) 52 53cc_library( 54 name = "program_name", 55 srcs = [ 56 "internal/program_name.cc", 57 ], 58 hdrs = [ 59 "internal/program_name.h", 60 ], 61 copts = ABSL_DEFAULT_COPTS, 62 linkopts = ABSL_DEFAULT_LINKOPTS, 63 visibility = [ 64 "//absl/flags:__pkg__", 65 ], 66 deps = [ 67 ":path_util", 68 "//absl/base:config", 69 "//absl/base:core_headers", 70 "//absl/strings", 71 "//absl/synchronization", 72 ], 73) 74 75cc_library( 76 name = "path_util", 77 hdrs = [ 78 "internal/path_util.h", 79 ], 80 copts = ABSL_DEFAULT_COPTS, 81 linkopts = ABSL_DEFAULT_LINKOPTS, 82 visibility = [ 83 "//absl/flags:__pkg__", 84 ], 85 deps = [ 86 "//absl/base:config", 87 "//absl/strings", 88 ], 89) 90 91cc_library( 92 name = "config", 93 srcs = [ 94 "usage_config.cc", 95 ], 96 hdrs = [ 97 "config.h", 98 "usage_config.h", 99 ], 100 copts = ABSL_DEFAULT_COPTS, 101 linkopts = ABSL_DEFAULT_LINKOPTS, 102 deps = [ 103 ":path_util", 104 ":program_name", 105 "//absl/base:config", 106 "//absl/base:core_headers", 107 "//absl/strings", 108 "//absl/synchronization", 109 ], 110) 111 112cc_library( 113 name = "marshalling", 114 srcs = [ 115 "marshalling.cc", 116 ], 117 hdrs = [ 118 "marshalling.h", 119 ], 120 copts = ABSL_DEFAULT_COPTS, 121 linkopts = ABSL_DEFAULT_LINKOPTS, 122 deps = [ 123 "//absl/base:config", 124 "//absl/base:core_headers", 125 "//absl/base:log_severity", 126 "//absl/strings", 127 "//absl/strings:str_format", 128 ], 129) 130 131cc_library( 132 name = "handle", 133 hdrs = [ 134 "internal/commandlineflag.h", 135 ], 136 copts = ABSL_DEFAULT_COPTS, 137 linkopts = ABSL_DEFAULT_LINKOPTS, 138 visibility = [ 139 "//absl/flags:__pkg__", 140 ], 141 deps = [ 142 ":config", 143 ":marshalling", 144 "//absl/base:config", 145 "//absl/base:core_headers", 146 "//absl/strings", 147 "//absl/types:optional", 148 ], 149) 150 151cc_library( 152 name = "registry", 153 srcs = [ 154 "internal/registry.cc", 155 "internal/type_erased.cc", 156 ], 157 hdrs = [ 158 "internal/registry.h", 159 "internal/type_erased.h", 160 ], 161 copts = ABSL_DEFAULT_COPTS, 162 linkopts = ABSL_DEFAULT_LINKOPTS, 163 visibility = [ 164 "//absl/flags:__pkg__", 165 ], 166 deps = [ 167 ":config", 168 ":handle", 169 "//absl/base:config", 170 "//absl/base:core_headers", 171 "//absl/base:raw_logging_internal", 172 "//absl/strings", 173 "//absl/synchronization", 174 ], 175) 176 177cc_library( 178 name = "flag", 179 srcs = [ 180 "flag.cc", 181 ], 182 hdrs = [ 183 "declare.h", 184 "flag.h", 185 ], 186 copts = ABSL_DEFAULT_COPTS, 187 linkopts = ABSL_DEFAULT_LINKOPTS, 188 deps = [ 189 ":config", 190 ":flag_internal", 191 ":handle", 192 ":marshalling", 193 ":registry", 194 "//absl/base", 195 "//absl/base:config", 196 "//absl/base:core_headers", 197 "//absl/strings", 198 ], 199) 200 201cc_library( 202 name = "usage_internal", 203 srcs = [ 204 "internal/usage.cc", 205 ], 206 hdrs = [ 207 "internal/usage.h", 208 ], 209 copts = ABSL_DEFAULT_COPTS, 210 linkopts = ABSL_DEFAULT_LINKOPTS, 211 visibility = [ 212 "//absl/flags:__pkg__", 213 ], 214 deps = [ 215 ":config", 216 ":flag", 217 ":flag_internal", 218 ":handle", 219 ":path_util", 220 ":program_name", 221 ":registry", 222 "//absl/base:config", 223 "//absl/base:core_headers", 224 "//absl/strings", 225 ], 226) 227 228cc_library( 229 name = "usage", 230 srcs = [ 231 "usage.cc", 232 ], 233 hdrs = [ 234 "usage.h", 235 ], 236 copts = ABSL_DEFAULT_COPTS, 237 linkopts = ABSL_DEFAULT_LINKOPTS, 238 deps = [ 239 ":usage_internal", 240 "//absl/base:config", 241 "//absl/base:core_headers", 242 "//absl/strings", 243 "//absl/synchronization", 244 ], 245) 246 247cc_library( 248 name = "parse", 249 srcs = ["parse.cc"], 250 hdrs = [ 251 "internal/parse.h", 252 "parse.h", 253 ], 254 copts = ABSL_DEFAULT_COPTS, 255 linkopts = ABSL_DEFAULT_LINKOPTS, 256 deps = [ 257 ":config", 258 ":flag", 259 ":flag_internal", 260 ":handle", 261 ":program_name", 262 ":registry", 263 ":usage", 264 ":usage_internal", 265 "//absl/base:config", 266 "//absl/base:core_headers", 267 "//absl/strings", 268 "//absl/synchronization", 269 ], 270) 271 272############################################################################ 273# Unit tests in alphabetical order. 274 275cc_test( 276 name = "commandlineflag_test", 277 size = "small", 278 srcs = [ 279 "internal/commandlineflag_test.cc", 280 ], 281 copts = ABSL_TEST_COPTS, 282 linkopts = ABSL_DEFAULT_LINKOPTS, 283 deps = [ 284 ":config", 285 ":flag", 286 ":handle", 287 ":registry", 288 "//absl/memory", 289 "//absl/strings", 290 "@com_google_googletest//:gtest_main", 291 ], 292) 293 294cc_test( 295 name = "config_test", 296 size = "small", 297 srcs = [ 298 "config_test.cc", 299 ], 300 copts = ABSL_TEST_COPTS, 301 linkopts = ABSL_DEFAULT_LINKOPTS, 302 deps = [ 303 ":config", 304 "@com_google_googletest//:gtest_main", 305 ], 306) 307 308cc_test( 309 name = "flag_test", 310 size = "small", 311 srcs = [ 312 "flag_test.cc", 313 "flag_test_defs.cc", 314 ], 315 copts = ABSL_TEST_COPTS, 316 linkopts = ABSL_DEFAULT_LINKOPTS, 317 deps = [ 318 ":config", 319 ":flag", 320 ":flag_internal", 321 ":handle", 322 ":registry", 323 "//absl/base:core_headers", 324 "//absl/strings", 325 "@com_google_googletest//:gtest_main", 326 ], 327) 328 329cc_binary( 330 name = "flag_benchmark", 331 testonly = 1, 332 srcs = [ 333 "flag_benchmark.cc", 334 ], 335 copts = ABSL_TEST_COPTS, 336 tags = ["benchmark"], 337 visibility = ["//visibility:private"], 338 deps = [ 339 ":flag", 340 "//absl/time", 341 "//absl/types:optional", 342 "@com_github_google_benchmark//:benchmark_main", 343 ], 344) 345 346cc_test( 347 name = "marshalling_test", 348 size = "small", 349 srcs = [ 350 "marshalling_test.cc", 351 ], 352 copts = ABSL_TEST_COPTS, 353 linkopts = ABSL_DEFAULT_LINKOPTS, 354 deps = [ 355 ":marshalling", 356 "@com_google_googletest//:gtest_main", 357 ], 358) 359 360cc_test( 361 name = "path_util_test", 362 size = "small", 363 srcs = [ 364 "internal/path_util_test.cc", 365 ], 366 copts = ABSL_TEST_COPTS, 367 linkopts = ABSL_DEFAULT_LINKOPTS, 368 deps = [ 369 ":path_util", 370 "@com_google_googletest//:gtest_main", 371 ], 372) 373 374cc_test( 375 name = "parse_test", 376 size = "small", 377 srcs = [ 378 "parse_test.cc", 379 ], 380 copts = ABSL_TEST_COPTS, 381 linkopts = ABSL_DEFAULT_LINKOPTS, 382 deps = [ 383 ":flag", 384 ":parse", 385 ":registry", 386 "//absl/base:raw_logging_internal", 387 "//absl/base:scoped_set_env", 388 "//absl/strings", 389 "//absl/types:span", 390 "@com_google_googletest//:gtest_main", 391 ], 392) 393 394cc_test( 395 name = "program_name_test", 396 size = "small", 397 srcs = [ 398 "internal/program_name_test.cc", 399 ], 400 copts = ABSL_TEST_COPTS, 401 linkopts = ABSL_DEFAULT_LINKOPTS, 402 deps = [ 403 ":program_name", 404 "//absl/strings", 405 "@com_google_googletest//:gtest_main", 406 ], 407) 408 409cc_test( 410 name = "type_erased_test", 411 size = "small", 412 srcs = [ 413 "internal/type_erased_test.cc", 414 ], 415 copts = ABSL_TEST_COPTS, 416 linkopts = ABSL_DEFAULT_LINKOPTS, 417 deps = [ 418 ":flag", 419 ":handle", 420 ":marshalling", 421 ":registry", 422 "//absl/memory", 423 "@com_google_googletest//:gtest_main", 424 ], 425) 426 427cc_test( 428 name = "usage_config_test", 429 size = "small", 430 srcs = [ 431 "usage_config_test.cc", 432 ], 433 copts = ABSL_TEST_COPTS, 434 linkopts = ABSL_DEFAULT_LINKOPTS, 435 deps = [ 436 ":config", 437 ":path_util", 438 ":program_name", 439 "//absl/strings", 440 "@com_google_googletest//:gtest_main", 441 ], 442) 443 444cc_test( 445 name = "usage_test", 446 size = "small", 447 srcs = [ 448 "internal/usage_test.cc", 449 ], 450 copts = ABSL_TEST_COPTS, 451 linkopts = ABSL_DEFAULT_LINKOPTS, 452 deps = [ 453 ":config", 454 ":flag", 455 ":parse", 456 ":path_util", 457 ":program_name", 458 ":registry", 459 ":usage", 460 ":usage_internal", 461 "//absl/memory", 462 "//absl/strings", 463 "@com_google_googletest//:gtest", 464 ], 465) 466