30 lines
1 KiB
Python
30 lines
1 KiB
Python
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
#
|
|
# This source code is licensed under both the MIT license found in the
|
|
# LICENSE-MIT file in the root directory of this source tree and the Apache
|
|
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
|
|
# of this source tree.
|
|
|
|
load("@prelude//utils:utils.bzl", "value_or")
|
|
|
|
def go_attr_pkg_name(ctx: "context") -> str.type:
|
|
"""
|
|
Return the Go package name for the given context corresponing to a rule.
|
|
"""
|
|
return value_or(ctx.attrs.package_name, ctx.label.package)
|
|
|
|
def merge_pkgs(pkgss: [{str.type: "artifact"}]) -> {str.type: "artifact"}:
|
|
"""
|
|
Merge mappings of packages into a single mapping, throwing an error on
|
|
conflicts.
|
|
"""
|
|
|
|
all_pkgs = {}
|
|
|
|
for pkgs in pkgss:
|
|
for name, path in pkgs.items():
|
|
if name in pkgs and pkgs[name] != path:
|
|
fail("conflict for package {!r}: {} and {}".format(name, path, all_pkgs[name]))
|
|
all_pkgs[name] = path
|
|
|
|
return all_pkgs
|