chromium/components/os_crypt/sync/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/cast.gni")
import("//build/config/features.gni")
import("//build/config/ui.gni")
import("//components/os_crypt/sync/features.gni")

# Wrapper component to allow dependencies to depend on //components/os_crypt/sync directly.
group("sync") {
  public_deps = [ ":os_crypt" ]
}

component("os_crypt") {
  sources = [
    "os_crypt.h",
    "os_crypt_switches.cc",
    "os_crypt_switches.h",
  ]

  deps = [
    "//base",
    "//build:branding_buildflags",
    "//build:chromecast_buildflags",
    "//build:chromeos_buildflags",
    "//components/prefs",
    "//crypto",
  ]

  configs += [ "//build/config/compiler:wexit_time_destructors" ]
  defines = [ "IS_OS_CRYPT_IMPL" ]

  if (allow_runtime_configurable_key_storage) {
    defines += [ "ALLOW_RUNTIME_CONFIGURABLE_KEY_STORAGE" ]
  }

  if ((is_posix && !is_apple && !(is_linux && !is_castos)) || is_fuchsia) {
    sources += [ "os_crypt_posix.cc" ]
  }

  if (is_apple) {
    sources += [
      "keychain_password_mac.h",
      "keychain_password_mac.mm",
      "os_crypt_mac.mm",
    ]
    deps += [ "//crypto:mock_apple_keychain" ]
  }

  if (is_win) {
    sources += [ "os_crypt_win.cc" ]
    deps += [ "//components/version_info" ]
    libs = [ "crypt32.lib" ]
  }

  if (is_linux && !is_castos) {
    sources += [
      "key_storage_config_linux.cc",
      "key_storage_config_linux.h",
      "key_storage_linux.cc",
      "key_storage_linux.h",
      "key_storage_util_linux.cc",
      "key_storage_util_linux.h",
      "os_crypt_linux.cc",
    ]

    if (use_glib && use_dbus) {
      sources += [
        "key_storage_libsecret.cc",
        "key_storage_libsecret.h",
        "libsecret_util_linux.cc",
        "libsecret_util_linux.h",
      ]
      configs += [ "//build/config/linux:glib" ]
      deps += [ "//third_party/libsecret" ]
      defines += [ "USE_LIBSECRET" ]
    }
    if (use_dbus) {
      sources += [
        "key_storage_kwallet.cc",
        "key_storage_kwallet.h",
        "kwallet_dbus.cc",
        "kwallet_dbus.h",
      ]
      deps += [ "//dbus" ]
      defines += [ "USE_KWALLET" ]
    }
  }
}

static_library("test_support") {
  testonly = true
  sources = [
    "os_crypt_mocker.cc",
    "os_crypt_mocker.h",
  ]
  deps = [
    ":os_crypt",
    "//base",
    "//testing/gtest",
  ]
  if (is_linux && !is_castos) {
    sources += [
      "os_crypt_mocker_linux.cc",
      "os_crypt_mocker_linux.h",
    ]
    defines = []
    if (use_glib) {
      defines += [ "USE_LIBSECRET" ]
    }
    if (use_dbus) {
      defines += [ "USE_KWALLET" ]
    }
  }
}

source_set("unit_tests") {
  testonly = true
  sources = [ "os_crypt_unittest.cc" ]
  deps = [
    ":os_crypt",
    ":test_support",
    "//base",
    "//base/test:test_support",
    "//build:branding_buildflags",
    "//build:chromeos_buildflags",
    "//components/prefs:test_support",
    "//crypto",
    "//testing/gmock",
    "//testing/gtest",
    "//ui/base",
  ]

  if (is_apple) {
    sources += [ "keychain_password_mac_unittest.mm" ]
    deps += [ "//crypto:mock_apple_keychain" ]
  }

  if (is_linux && !is_castos) {
    sources += [
      "key_storage_linux_unittest.cc",
      "key_storage_util_linux_unittest.cc",
      "os_crypt_linux_unittest.cc",
    ]
    defines = []

    if (use_glib) {
      sources += [ "key_storage_libsecret_unittest.cc" ]
      deps += [ "//third_party/libsecret" ]
      defines += [ "USE_LIBSECRET" ]
    }
    if (use_dbus) {
      sources += [
        "key_storage_kwallet_unittest.cc",
        "kwallet_dbus_unittest.cc",
      ]
      deps += [ "//dbus:test_support" ]
      defines += [ "USE_KWALLET" ]
    }
  }
}