def _get_relative_dirname(base, file):
    """Return a dirname in the form of path segments relative to base.
    If the file.short_path is not within base, return empty list.
    Example: if base="foo/bar/baz.txt"
             and file.short_path="bar/baz.txt",
             return ["bar"].
    Args:
      base (string): the base dirname (ctx.label.package)
      file (File): the file to calculate relative dirname.
    Returns:
      (list<string>): path
    """
    path = file.dirname
    if not path.startswith(base):
        return []
    parts = path.split("/")
    if parts[0] == "external":
        # ignore off the first two items since we'll be cd'ing into
        # this dir.
        return parts[2:]
    base_parts = base.split("/")
    return parts[len(base_parts):]