def determine_package_deps(bazel_package_deps, module_dependency_matchlist, root_package):
    """Given a full list of package dependencies, as determined by the skylark/aspect code in intellij_project.bzl,
    filter down to only the dependencies that should be considered,
    in establishing intellij module dependency relationships,
    using the matchlist.
    Produce a mapping of bazel package to other bazel packages it depends on."""
    def is_module_dependency_match(bazel_package_dep):
        for m in module_dependency_matchlist:
            if m.matches(bazel_package_dep):
                return True
        return False

    matched_package_deps = filter(lambda p: is_module_dependency_match(p), bazel_package_deps)

    package_to_depends_on_packages = {}
    for p in matched_package_deps:
        if p["bazel_package"] not in package_to_depends_on_packages:
            package_to_depends_on_packages[p["bazel_package"]] = []
        if (p["depends_on_bazel_package"] not in package_to_depends_on_packages[p["bazel_package"]]):
            package_to_depends_on_packages[p["bazel_package"]].append(p["depends_on_bazel_package"])

    return package_to_depends_on_packages