chromium/third_party/libaddressinput/BUILD.gn

# Copyright 2014 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/locales.gni")
import("//testing/libfuzzer/fuzzer_test.gni")
import("//testing/test.gni")
import("//tools/grit/grit_rule.gni")

config("internal_config") {
  if (is_clang) {
    cflags = [
      "-Wno-newline-eof",

      # md5.cc uses "register". TODO(thakis): Fix.
      "-Wno-deprecated-register",
    ]
  }

  # libaddressinput just says `#include "messages.h"` for grit-generated
  # headers.
  include_dirs = [ target_gen_dir ]
}

grit("strings") {
  source = "chromium/address_input_strings.grd"

  outputs = [
    "messages.h",
    "en_messages.cc",
  ]
  foreach(locale, all_chrome_locales) {
    outputs += [ "address_input_strings_$locale.pak" ]
  }

  configs = [ ":internal_config" ]
}

config("libaddressinput_config") {
  defines = [ "I18N_ADDRESS_VALIDATION_DATA_URL=\"https://chromium-i18n.appspot.com/ssl-aggregate-address/\"" ]
  include_dirs = [ "src/cpp/include" ]
}

# This target provides basic functionality which is cooked into the build.
static_library("util") {
  sources = [
    "chromium/json.cc",
    "src/cpp/src/address_data.cc",
    "src/cpp/src/address_field.cc",
    "src/cpp/src/address_field_util.cc",
    "src/cpp/src/address_field_util.h",
    "src/cpp/src/address_formatter.cc",
    "src/cpp/src/address_metadata.cc",
    "src/cpp/src/address_ui.cc",
    "src/cpp/src/format_element.cc",
    "src/cpp/src/format_element.h",
    "src/cpp/src/grit.h",
    "src/cpp/src/language.cc",
    "src/cpp/src/language.h",
    "src/cpp/src/localization.cc",
    "src/cpp/src/lookup_key.cc",
    "src/cpp/src/lookup_key.h",
    "src/cpp/src/region_data_constants.cc",
    "src/cpp/src/region_data_constants.h",
    "src/cpp/src/rule.cc",
    "src/cpp/src/rule.h",
    "src/cpp/src/util/cctype_tolower_equal.cc",
    "src/cpp/src/util/cctype_tolower_equal.h",
    "src/cpp/src/util/json.h",
    "src/cpp/src/util/lru_cache_using_std.h",
    "src/cpp/src/util/md5.cc",
    "src/cpp/src/util/md5.h",
    "src/cpp/src/util/re2ptr.h",
    "src/cpp/src/util/size.h",
    "src/cpp/src/util/string_compare.h",
    "src/cpp/src/util/string_split.cc",
    "src/cpp/src/util/string_split.h",
    "src/cpp/src/util/string_util.cc",
    "src/cpp/src/util/string_util.h",
  ]

  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    ":internal_config",
    "//build/config/compiler:no_chromium_code",
  ]

  public_configs = [ ":libaddressinput_config" ]

  include_dirs = [ "$root_gen_dir/third_party/libaddressinput" ]

  deps = [
    ":strings",
    "//base",
    "//base:i18n",
    "//third_party/icu",
    "//third_party/re2",
  ]
}

# This target provides more complicated functionality like pinging servers
# for validation rules.
static_library("libaddressinput") {
  sources = [
    "chromium/addressinput_util.cc",
    "chromium/addressinput_util.h",
    "chromium/chrome_address_validator.cc",
    "chromium/chrome_address_validator.h",
    "chromium/chrome_metadata_source.cc",
    "chromium/chrome_metadata_source.h",
    "chromium/chrome_storage_impl.cc",
    "chromium/chrome_storage_impl.h",
    "chromium/fallback_data_store.cc",
    "chromium/fallback_data_store.h",
    "chromium/storage_test_runner.h",
    "chromium/string_compare.cc",
    "chromium/trie.cc",
    "chromium/trie.h",
    "src/cpp/src/address_input_helper.cc",
    "src/cpp/src/address_normalizer.cc",
    "src/cpp/src/address_problem.cc",
    "src/cpp/src/address_validator.cc",
    "src/cpp/src/null_storage.cc",
    "src/cpp/src/ondemand_supplier.cc",
    "src/cpp/src/ondemand_supply_task.cc",
    "src/cpp/src/ondemand_supply_task.h",
    "src/cpp/src/post_box_matchers.cc",
    "src/cpp/src/post_box_matchers.h",
    "src/cpp/src/preload_supplier.cc",
    "src/cpp/src/region_data.cc",
    "src/cpp/src/region_data_builder.cc",
    "src/cpp/src/retriever.cc",
    "src/cpp/src/retriever.h",
    "src/cpp/src/rule_retriever.cc",
    "src/cpp/src/rule_retriever.h",
    "src/cpp/src/validating_storage.cc",
    "src/cpp/src/validating_storage.h",
    "src/cpp/src/validating_util.cc",
    "src/cpp/src/validating_util.h",
    "src/cpp/src/validation_task.cc",
    "src/cpp/src/validation_task.h",
    "src/cpp/test/fake_storage.h",
    "src/cpp/test/mock_source.h",
    "src/cpp/test/testdata_source.h",
  ]

  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    ":internal_config",
    "//build/config/compiler:no_chromium_code",
  ]

  public_configs = [ ":libaddressinput_config" ]

  deps = [
    ":strings",
    ":util",
    "//base",
    "//base:i18n",
    "//components/prefs",
    "//net",
    "//services/network/public/cpp",
    "//third_party/icu",
    "//third_party/re2",
  ]
}

if (is_ios) {
  bundle_data("countryinfo_test_bundle_data") {
    testonly = true
    sources = [ "//third_party/libaddressinput/src/testdata/countryinfo.txt" ]
    outputs = [ "{{bundle_resources_dir}}/" +
                "{{source_root_relative_dir}}/{{source_file_part}}" ]
  }
}

# This target provides utilities for tests of libaddressinput.
source_set("test_support") {
  testonly = true
  sources = [
    "src/cpp/test/fake_storage.cc",
    "src/cpp/test/mock_source.cc",
    "src/cpp/test/testdata_source.cc",
  ]

  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    ":internal_config",
    "//build/config/compiler:no_chromium_code",
  ]

  defines = [ "TEST_DATA_DIR=\"src/third_party/libaddressinput/src/testdata\"" ]

  data = [ "//third_party/libaddressinput/src/testdata/" ]

  include_dirs = [ "src/cpp/src" ]

  deps = [ ":libaddressinput" ]
  if (is_ios) {
    deps += [ ":countryinfo_test_bundle_data" ]
  }
}

test("libaddressinput_unittests") {
  sources = [
    "chromium/addressinput_util_unittest.cc",
    "chromium/chrome_address_validator_unittest.cc",
    "chromium/chrome_metadata_source_unittest.cc",
    "chromium/chrome_storage_impl_unittest.cc",
    "chromium/fallback_data_store_unittest.cc",
    "chromium/storage_test_runner.cc",
    "chromium/storage_test_runner.h",
    "chromium/string_compare_unittest.cc",
    "chromium/trie_unittest.cc",
    "src/cpp/test/address_data_test.cc",
    "src/cpp/test/address_field_test.cc",
    "src/cpp/test/address_field_util_test.cc",
    "src/cpp/test/address_formatter_test.cc",
    "src/cpp/test/address_input_helper_test.cc",
    "src/cpp/test/address_metadata_test.cc",
    "src/cpp/test/address_normalizer_test.cc",
    "src/cpp/test/address_problem_test.cc",
    "src/cpp/test/address_ui_test.cc",
    "src/cpp/test/address_validator_test.cc",
    "src/cpp/test/fake_storage_test.cc",
    "src/cpp/test/format_element_test.cc",
    "src/cpp/test/language_test.cc",
    "src/cpp/test/localization_test.cc",
    "src/cpp/test/lookup_key_test.cc",
    "src/cpp/test/null_storage_test.cc",
    "src/cpp/test/ondemand_supply_task_test.cc",
    "src/cpp/test/post_box_matchers_test.cc",
    "src/cpp/test/preload_supplier_test.cc",
    "src/cpp/test/region_data_builder_test.cc",
    "src/cpp/test/region_data_constants_test.cc",
    "src/cpp/test/region_data_test.cc",
    "src/cpp/test/retriever_test.cc",
    "src/cpp/test/rule_retriever_test.cc",
    "src/cpp/test/rule_test.cc",
    "src/cpp/test/supplier_test.cc",
    "src/cpp/test/testdata_source_test.cc",
    "src/cpp/test/util/json_test.cc",
    "src/cpp/test/util/md5_unittest.cc",
    "src/cpp/test/util/string_compare_test.cc",
    "src/cpp/test/util/string_split_unittest.cc",
    "src/cpp/test/util/string_util_test.cc",
    "src/cpp/test/validating_storage_test.cc",
    "src/cpp/test/validating_util_test.cc",
    "src/cpp/test/validation_task_test.cc",
  ]

  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    ":internal_config",
    "//build/config/compiler:no_chromium_code",
  ]

  include_dirs = [ "src/cpp/src" ]

  # TODO(crbug.com/936653): Remove this after fixing deprecated API usage.
  if (is_clang) {
    cflags = [ "-Wno-deprecated-declarations" ]
  }

  deps = [
    ":libaddressinput",
    ":strings",
    ":test_support",
    ":util",
    "//base/test:run_all_unittests",
    "//base/test:test_support",
    "//components/prefs",
    "//mojo/core/embedder",
    "//net:test_support",
    "//services/network:test_support",
    "//testing/gtest",
  ]
}

fuzzer_test("libaddressinput_parse_address_fields_fuzzer") {
  sources = [ "fuzz/parse_address_fields_fuzzer.cc" ]
  deps = [
    ":libaddressinput",
    ":util",
  ]
  dict = "//third_party/libaddressinput/fuzz/data/require.dict"
}

fuzzer_test("libaddressinput_parse_format_rule_fuzzer") {
  sources = [ "fuzz/parse_format_rule_fuzzer.cc" ]
  deps = [
    ":libaddressinput",
    ":util",
  ]
  dict = "//third_party/libaddressinput/fuzz/data/fmt.dict"
}

fuzzer_test("libaddressinput_address_formatter_fuzzer") {
  sources = [ "fuzz/address_formatter_fuzzer.cc" ]
  deps = [
    ":libaddressinput",
    ":util",
  ]
}