Skip to content

Commit

Permalink
Restore missing bzl file
Browse files Browse the repository at this point in the history
fbshipit-source-id: e348a9709e36fb4c3ded63b7ebdc1c880be85755
  • Loading branch information
passy committed Dec 3, 2018
1 parent db242cc commit 950b6a3
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions tools/build_defs/oss/soloader_defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
def _deps_decorator(**kwargs):
"""
Dependencies starting with '//deps/' should be provided (included in
'provided_deps' rather than 'deps'). This decorator takes care
of moving all such dependencies from 'deps' to 'provided_deps'.
"""
all_deps = kwargs.get("deps", [])
oss_deps = [dep for dep in all_deps if dep.startswith("//deps:")]
kwargs["deps"] = [dep for dep in all_deps if dep not in oss_deps]
kwargs.setdefault("provided_deps", []).extend(oss_deps)
return kwargs

def android_library(**kwargs):
native.android_library(**_deps_decorator(**kwargs))

def android_aar(**kwargs):
native.android_aar(**_deps_decorator(**kwargs))

def fb_java_library(**kwargs):
native.java_library(**_deps_decorator(**kwargs))

def fb_core_android_library(**kwargs):
android_library(**kwargs)

DEPENDENCIES_INDEX = {}

def _add_dependency_to_index(name, **dep):
DEPENDENCIES_INDEX[name] = dep

def maven_library(
name,
group,
artifact,
version,
sha1,
visibility,
packaging = "jar",
scope = "compiled"):
"""
Creates remote_file and prebuilt_jar rules for a maven artifact.
"""
_add_dependency_to_index(
name = name,
artifact = artifact,
group = group,
packaging = packaging,
scope = scope,
sha1 = sha1,
version = version,
)

remote_file_name = "{}-remote".format(name)
native.remote_file(
name = remote_file_name,
out = "{}-{}.{}".format(name, version, packaging),
url = ":".join(["mvn", group, artifact, packaging, version]),
sha1 = sha1,
)

if packaging == "jar":
native.prebuilt_jar(
name = name,
binary_jar = ":{}".format(remote_file_name),
visibility = visibility,
)
else:
native.android_prebuilt_aar(
name = name,
aar = ":{}".format(remote_file_name),
visibility = visibility,
)

def define_list_deps_target():
"""
Generates rule that dumps all maven_libraries defined in given
BUCK file in json format.
"""
json_deps = struct(**DEPENDENCIES_INDEX).to_json()
native.genrule(
name = "list-deps",
out = "dependencies.json",
cmd = """echo '{}' > $OUT""".format(json_deps),
)

0 comments on commit 950b6a3

Please sign in to comment.