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

import("//tools/grit/grit_rule.gni")

libaddressinput_util_files = [
  "src/cpp/src/address_data.cc",
  "src/cpp/src/address_field.cc",
  "src/cpp/src/address_field_util.cc",
  "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/language.cc",
  "src/cpp/src/localization.cc",
  "src/cpp/src/lookup_key.cc",
  "src/cpp/src/region_data_constants.cc",
  "src/cpp/src/rule.cc",
  "src/cpp/src/util/cctype_tolower_equal.cc",
  "src/cpp/src/util/json.cc",
  "src/cpp/src/util/string_split.cc",
  "src/cpp/src/util/string_util.cc",
]

# GYP version: third_party/libaddressinput/libaddressinput.gyp:libaddressinput_strings
grit("strings") {
  source = "//chrome/app/address_input_strings.grd"
  outputs = [
    "messages.h",
    "en_messages.cc",
    "address_input_strings_am.pak",
    "address_input_strings_ar.pak",
    "address_input_strings_bg.pak",
    "address_input_strings_bn.pak",
    "address_input_strings_ca.pak",
    "address_input_strings_cs.pak",
    "address_input_strings_da.pak",
    "address_input_strings_de.pak",
    "address_input_strings_el.pak",
    "address_input_strings_en-GB.pak",
    "address_input_strings_en-US.pak",
    "address_input_strings_es.pak",
    "address_input_strings_es-419.pak",
    "address_input_strings_et.pak",
    "address_input_strings_fa.pak",
    "address_input_strings_fake-bidi.pak",
    "address_input_strings_fi.pak",
    "address_input_strings_fil.pak",
    "address_input_strings_fr.pak",
    "address_input_strings_gu.pak",
    "address_input_strings_he.pak",
    "address_input_strings_hi.pak",
    "address_input_strings_hr.pak",
    "address_input_strings_hu.pak",
    "address_input_strings_id.pak",
    "address_input_strings_it.pak",
    "address_input_strings_ja.pak",
    "address_input_strings_kn.pak",
    "address_input_strings_ko.pak",
    "address_input_strings_lt.pak",
    "address_input_strings_lv.pak",
    "address_input_strings_ml.pak",
    "address_input_strings_mr.pak",
    "address_input_strings_ms.pak",
    "address_input_strings_nl.pak",
    "address_input_strings_nb.pak",
    "address_input_strings_pl.pak",
    "address_input_strings_pt-BR.pak",
    "address_input_strings_pt-PT.pak",
    "address_input_strings_ro.pak",
    "address_input_strings_ru.pak",
    "address_input_strings_sk.pak",
    "address_input_strings_sl.pak",
    "address_input_strings_sr.pak",
    "address_input_strings_sv.pak",
    "address_input_strings_sw.pak",
    "address_input_strings_ta.pak",
    "address_input_strings_te.pak",
    "address_input_strings_th.pak",
    "address_input_strings_tr.pak",
    "address_input_strings_uk.pak",
    "address_input_strings_vi.pak",
    "address_input_strings_zh-CN.pak",
    "address_input_strings_zh-TW.pak",
  ]
}

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

# This target provides basic functionality which is cooked into the build.
# GYP version: third_party/libaddressinput/libaddressinput.gyp:libaddressinput_util
static_library("util") {
  sources = libaddressinput_util_files
  sources += [
    "chromium/addressinput_util.cc",
    "chromium/json.cc",
  ]
  sources -= [
    "src/cpp/src/util/json.cc",
  ]

  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [ "//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",
  ]
}

if (!is_android) {

# The list of files in libaddressinput.gypi.
gypi_values = exec_script(
    "//build/gypi_to_gn.py",
    [ rebase_path("src/cpp/libaddressinput.gypi") ],
    "scope",
    [ "src/cpp/libaddressinput.gypi" ])


# This target provides more complicated functionality like pinging servers
# for validation rules.
# GYP version: third_party/libaddressinput/libaddressinput.gyp:libaddressinput
static_library("libaddressinput") {
  sources = rebase_path(gypi_values.libaddressinput_files, ".", "src/cpp")
  sources += [
    "chromium/chrome_address_validator.cc",
    "chromium/chrome_metadata_source.cc",
    "chromium/chrome_storage_impl.cc",
    "chromium/fallback_data_store.cc",
    "chromium/input_suggester.cc",
    "chromium/string_compare.cc",
    "chromium/trie.cc",
  ]
  sources -= libaddressinput_util_files
  sources -= [
    "src/cpp/src/util/string_compare.cc",
  ]

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

  public_configs = [ ":libaddressinput_config" ]

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

test("libaddressinput_unittests") {
  sources = rebase_path(gypi_values.libaddressinput_test_files, ".", "src/cpp")
  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/string_compare_unittest.cc",
    "chromium/trie_unittest.cc",
  ]

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

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

  include_dirs = [
    "src/cpp/src",
  ]

  deps = [
    ":libaddressinput",
    ":strings",
    "//base:prefs",
    "//base/test:run_all_unittests",
    "//net:test_support",
    "//testing/gtest",
  ]
}

}  # !is_android