1*5ca8c28cSEnji Cooper"""Provides a fake @fuchsia_sdk implementation that's used when the real one isn't available. 2*5ca8c28cSEnji Cooper 3*5ca8c28cSEnji CooperThis is needed since bazel queries on targets that depend on //:gtest (eg: 4*5ca8c28cSEnji Cooper`bazel query "deps(set(//googletest/test:gtest_all_test))"`) will fail if @fuchsia_sdk is not 5*5ca8c28cSEnji Cooperdefined when bazel is evaluating the transitive closure of the query target. 6*5ca8c28cSEnji Cooper 7*5ca8c28cSEnji CooperSee https://github.com/google/googletest/issues/4472. 8*5ca8c28cSEnji Cooper""" 9*5ca8c28cSEnji Cooper 10*5ca8c28cSEnji Cooperdef _fake_fuchsia_sdk_impl(repo_ctx): 11*5ca8c28cSEnji Cooper for stub_target in repo_ctx.attr._stub_build_targets: 12*5ca8c28cSEnji Cooper stub_package = stub_target 13*5ca8c28cSEnji Cooper stub_target_name = stub_target.split("/")[-1] 14*5ca8c28cSEnji Cooper repo_ctx.file("%s/BUILD.bazel" % stub_package, """ 15*5ca8c28cSEnji Cooperfilegroup( 16*5ca8c28cSEnji Cooper name = "%s", 17*5ca8c28cSEnji Cooper) 18*5ca8c28cSEnji Cooper""" % stub_target_name) 19*5ca8c28cSEnji Cooper 20*5ca8c28cSEnji Cooperfake_fuchsia_sdk = repository_rule( 21*5ca8c28cSEnji Cooper doc = "Used to create a fake @fuchsia_sdk repository with stub build targets.", 22*5ca8c28cSEnji Cooper implementation = _fake_fuchsia_sdk_impl, 23*5ca8c28cSEnji Cooper attrs = { 24*5ca8c28cSEnji Cooper "_stub_build_targets": attr.string_list( 25*5ca8c28cSEnji Cooper doc = "The stub build targets to initialize.", 26*5ca8c28cSEnji Cooper default = [ 27*5ca8c28cSEnji Cooper "pkg/fdio", 28*5ca8c28cSEnji Cooper "pkg/syslog", 29*5ca8c28cSEnji Cooper "pkg/zx", 30*5ca8c28cSEnji Cooper ], 31*5ca8c28cSEnji Cooper ), 32*5ca8c28cSEnji Cooper }, 33*5ca8c28cSEnji Cooper) 34