1*da0073e9SAndroid Build Coastguard Workerdef _impl(repository_ctx): 2*da0073e9SAndroid Build Coastguard Worker archive = repository_ctx.attr.name + ".tar" 3*da0073e9SAndroid Build Coastguard Worker reference = Label("@%s_unpatched//:README" % repository_ctx.attr.name) 4*da0073e9SAndroid Build Coastguard Worker dirname = repository_ctx.path(reference).dirname 5*da0073e9SAndroid Build Coastguard Worker repository_ctx.execute(["tar", "hcf", archive, "-C", dirname, "."]) 6*da0073e9SAndroid Build Coastguard Worker repository_ctx.extract(archive) 7*da0073e9SAndroid Build Coastguard Worker for patch in repository_ctx.attr.patches: 8*da0073e9SAndroid Build Coastguard Worker repository_ctx.patch(repository_ctx.path(patch), repository_ctx.attr.patch_strip) 9*da0073e9SAndroid Build Coastguard Worker build_file = repository_ctx.path(repository_ctx.attr.build_file) 10*da0073e9SAndroid Build Coastguard Worker repository_ctx.execute(["cp", build_file, "BUILD.bazel"]) 11*da0073e9SAndroid Build Coastguard Worker 12*da0073e9SAndroid Build Coastguard Worker_patched_rule = repository_rule( 13*da0073e9SAndroid Build Coastguard Worker implementation = _impl, 14*da0073e9SAndroid Build Coastguard Worker attrs = { 15*da0073e9SAndroid Build Coastguard Worker "build_file": attr.label(), 16*da0073e9SAndroid Build Coastguard Worker "patch_strip": attr.int(), 17*da0073e9SAndroid Build Coastguard Worker "patches": attr.label_list(), 18*da0073e9SAndroid Build Coastguard Worker }, 19*da0073e9SAndroid Build Coastguard Worker) 20*da0073e9SAndroid Build Coastguard Worker 21*da0073e9SAndroid Build Coastguard Workerdef new_patched_local_repository(name, path, **kwargs): 22*da0073e9SAndroid Build Coastguard Worker native.new_local_repository( 23*da0073e9SAndroid Build Coastguard Worker name = name + "_unpatched", 24*da0073e9SAndroid Build Coastguard Worker build_file_content = """ 25*da0073e9SAndroid Build Coastguard Workerpkg_tar(name = "content", srcs = glob(["**"])) 26*da0073e9SAndroid Build Coastguard Worker""", 27*da0073e9SAndroid Build Coastguard Worker path = path, 28*da0073e9SAndroid Build Coastguard Worker ) 29*da0073e9SAndroid Build Coastguard Worker _patched_rule(name = name, **kwargs) 30*da0073e9SAndroid Build Coastguard Worker 31*da0073e9SAndroid Build Coastguard Workerdef _new_empty_repository_impl(repo_ctx): 32*da0073e9SAndroid Build Coastguard Worker build_file = repo_ctx.attr.build_file 33*da0073e9SAndroid Build Coastguard Worker build_file_content = repo_ctx.attr.build_file_content 34*da0073e9SAndroid Build Coastguard Worker if not (bool(build_file) != bool(build_file_content)): 35*da0073e9SAndroid Build Coastguard Worker fail("Exactly one of 'build_file' or 'build_file_content' is required") 36*da0073e9SAndroid Build Coastguard Worker 37*da0073e9SAndroid Build Coastguard Worker if build_file_content: 38*da0073e9SAndroid Build Coastguard Worker repo_ctx.file("BUILD", build_file_content) 39*da0073e9SAndroid Build Coastguard Worker elif build_file: 40*da0073e9SAndroid Build Coastguard Worker repo_ctx.template("BUILD", repo_ctx.attr.build_file, {}) 41*da0073e9SAndroid Build Coastguard Worker 42*da0073e9SAndroid Build Coastguard Workernew_empty_repository = repository_rule( 43*da0073e9SAndroid Build Coastguard Worker attrs = { 44*da0073e9SAndroid Build Coastguard Worker "build_file": attr.label(allow_files = True), 45*da0073e9SAndroid Build Coastguard Worker "build_file_content": attr.string(), 46*da0073e9SAndroid Build Coastguard Worker }, 47*da0073e9SAndroid Build Coastguard Worker implementation = _new_empty_repository_impl, 48*da0073e9SAndroid Build Coastguard Worker) 49*da0073e9SAndroid Build Coastguard Worker 50*da0073e9SAndroid Build Coastguard Worker"""Create an empty repository with the supplied BUILD file. 51*da0073e9SAndroid Build Coastguard Worker 52*da0073e9SAndroid Build Coastguard WorkerThis is mostly useful to create wrappers for specific target that we want 53*da0073e9SAndroid Build Coastguard Workerto be used with the '@' syntax. 54*da0073e9SAndroid Build Coastguard Worker""" 55