<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def symlink_bundles(self, app, bundle_dir):
 """For each bundle in the given app, symlinks relevant matched paths. Validates that at least one path was matched by a bundle. """

    for bundle_counter, bundle in enumerate(app.bundles):
      count = 0
      for path, relpath in bundle.filemap.items():
        bundle_path = os.path.join(bundle_dir, relpath)
        count += 1
        if os.path.exists(bundle_path):
          continue

        if os.path.isfile(path):
          safe_mkdir(os.path.dirname(bundle_path))
          os.symlink(path, bundle_path)
        elif os.path.isdir(path):
          safe_mkdir(bundle_path)

      if count == 0:
        raise TargetDefinitionException(app.target,
                                        'Bundle index {} of "bundles" field '
                                        'does not match any files.'.format(bundle_counter))