blob: 3ecb892b4b821f582e0f2fff1f414c5e287b6248 [file] [log] [blame]
# Copyright (C) 2013 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Compiles a Java library with additional compile-time dependencies
# that do not show up as transitive dependencies to java_library()
# or java_binary() rule that depends on this library.
#
# Example: servlet library needs to be compiled against servlet API
# but this dependency must not become a transitive dependency.
#
# java_library2(
# name = 'gitiles-servlet',
# srcs = SRCS,
# resources = RSRC,
# deps = DEPS,
# compile_deps = ['//lib:servlet-api'],
# visibility = ['PUBLIC'],
# )
# @See: https://github.com/facebook/buck/issues/63
#
def java_library2(
name,
srcs = [],
resources = [],
deps = [],
compile_deps = [],
visibility = []):
c = name + '__compile'
t = name + '__link'
j = 'lib__%s__output/%s.jar' % (c, c)
o = 'lib__%s__output/%s.jar' % (name, name)
java_library(
name = c,
srcs = srcs,
resources = resources,
deps = deps + compile_deps,
visibility = visibility,
)
# Break the dependency chain by passing the newly built
# JAR to consumers through a prebuilt_jar().
genrule(
name = t,
cmd = 'mkdir -p $(dirname $OUT);ln -s $SRCS $OUT',
srcs = [genfile(j)],
deps = [':' + c],
out = o,
)
prebuilt_jar(
name = name,
binary_jar = genfile(o),
deps = deps + [':' + t],
visibility = visibility,
)