
"""Logic to translate Xcode options to Bazel options."""


class BazelOptions(object):
  """Converts Xcode features into Bazel command line flags."""

  def __init__(self, xcode_env):
    """Creates a new BazelOptions object.

    Args:
      xcode_env: A dictionary of Xcode environment variables.

    Returns:
      A BazelOptions instance.
    """
    self.xcode_env = xcode_env

  def bazel_feature_flags(self):
    """Returns a list of bazel flags for the current Xcode env configuration."""
    flags = []
    if self.xcode_env.get('ENABLE_ADDRESS_SANITIZER') == 'YES':
      flags.extend([
          '--features=asan',
      ])

    return flags


"""Logic to translate Xcode options to Bazel options."""


class BazelOptions(object):
  """Converts Xcode features into Bazel command line flags."""

  def __init__(self, xcode_env):
    """Creates a new BazelOptions object.

    Args:
      xcode_env: A dictionary of Xcode environment variables.

    Returns:
      A BazelOptions instance.
    """
    self.xcode_env = xcode_env

  def bazel_feature_flags(self):
    """Returns a list of bazel flags for the current Xcode env configuration."""
    flags = []
    if self.xcode_env.get('ENABLE_ADDRESS_SANITIZER') == 'YES':
      flags.append('--features=asan')
    if self.xcode_env.get('ENABLE_THREAD_SANITIZER') == 'YES':
      flags.append('--features=tsan')
    if self.xcode_env.get('ENABLE_UNDEFINED_BEHAVIOR_SANITIZER') == 'YES':
      flags.append('--features=ubsan')

    return flags

Support enabling tsan and ubsan from Xcode UI
Support enabling tsan and ubsan from Xcode UI

Xcode won't let you enable ubsan from the UI as it requires a
'Compile Sources' phase with (Objective-)C(++) sources, but if you
manually edit the scheme and enable it or equivalently add the phase
with a dummy file, enable it from the UI, and then remove the phase,
ubsan will work.

PiperOrigin-RevId: 196831918

  
  """Logic to translate Xcode options to Bazel options."""
  
  
  class BazelOptions(object):
    """Converts Xcode features into Bazel command line flags."""
  
    def __init__(self, xcode_env):
      """Creates a new BazelOptions object.
  
      Args:
        xcode_env: A dictionary of Xcode environment variables.
  
      Returns:
        A BazelOptions instance.
      """
      self.xcode_env = xcode_env
  
    def bazel_feature_flags(self):
      """Returns a list of bazel flags for the current Xcode env configuration."""
      flags = []
      if self.xcode_env.get('ENABLE_ADDRESS_SANITIZER') == 'YES':
-       flags.extend([
-           '--features=asan',
-       ])
+       flags.append('--features=asan')
+     if self.xcode_env.get('ENABLE_THREAD_SANITIZER') == 'YES':
+       flags.append('--features=tsan')
+     if self.xcode_env.get('ENABLE_UNDEFINED_BEHAVIOR_SANITIZER') == 'YES':
+       flags.append('--features=ubsan')
  
      return flags
  
Support enabling tsan and ubsan from Xcode UI
## Code Before:

"""Logic to translate Xcode options to Bazel options."""


class BazelOptions(object):
  """Converts Xcode features into Bazel command line flags."""

  def __init__(self, xcode_env):
    """Creates a new BazelOptions object.

    Args:
      xcode_env: A dictionary of Xcode environment variables.

    Returns:
      A BazelOptions instance.
    """
    self.xcode_env = xcode_env

  def bazel_feature_flags(self):
    """Returns a list of bazel flags for the current Xcode env configuration."""
    flags = []
    if self.xcode_env.get('ENABLE_ADDRESS_SANITIZER') == 'YES':
      flags.extend([
          '--features=asan',
      ])

    return flags

## Instruction:
Support enabling tsan and ubsan from Xcode UI
## Code After:

"""Logic to translate Xcode options to Bazel options."""


class BazelOptions(object):
  """Converts Xcode features into Bazel command line flags."""

  def __init__(self, xcode_env):
    """Creates a new BazelOptions object.

    Args:
      xcode_env: A dictionary of Xcode environment variables.

    Returns:
      A BazelOptions instance.
    """
    self.xcode_env = xcode_env

  def bazel_feature_flags(self):
    """Returns a list of bazel flags for the current Xcode env configuration."""
    flags = []
    if self.xcode_env.get('ENABLE_ADDRESS_SANITIZER') == 'YES':
      flags.append('--features=asan')
    if self.xcode_env.get('ENABLE_THREAD_SANITIZER') == 'YES':
      flags.append('--features=tsan')
    if self.xcode_env.get('ENABLE_UNDEFINED_BEHAVIOR_SANITIZER') == 'YES':
      flags.append('--features=ubsan')

    return flags
