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

_gperf_files = [
  {
    source = "data/common_words.gperf"
    namespace = "url_formatter::common_words"
    testonly = false
  },
  {
    source = "data/common_words_test.gperf"
    namespace = "test"
    testonly = true
  },
]

_generated_targets = []
_generated_test_targets = []
foreach(_item, _gperf_files) {
  _source = _item.source
  _source_name = get_path_info(_item.source, "name")
  _target_name = "generate_" + _source_name + "_dafsa"

  action(_target_name) {
    script = "//net/tools/dafsa/make_dafsa.py"
    sources = [ _item.source ]
    testonly = _item.testonly

    outputs = [ "${target_gen_dir}/${_source_name}-inc.cc" ]
    args = [
      "--namespace=${_item.namespace}",
      rebase_path(_item.source, root_build_dir),
      rebase_path("${target_gen_dir}/${_source_name}-inc.cc", root_build_dir),
    ]
  }

  if (_item.testonly) {
    _generated_test_targets += [ ":${_target_name}" ]
  } else {
    _generated_targets += [ ":${_target_name}" ]
  }
}

group("common_words_dafsa") {
  public_deps = _generated_targets
}
group("common_words_test_dafsa") {
  public_deps = _generated_test_targets
  testonly = true
}

source_set("common") {
  sources = [
    "common_words_util.cc",
    "common_words_util.h",
  ]

  public_deps = [ "//base" ]
  deps = [
    ":common_words_dafsa",
    "//net",
  ]
}

source_set("unit_tests") {
  testonly = true
  sources = [ "common_words_util_unittest.cc" ]
  deps = [
    ":common",
    ":common_words_dafsa",
    ":common_words_test_dafsa",
    "//testing/gtest",
  ]
}
