1"""Implementation of sphinx_docs_library.""" 2 3load(":sphinx_docs_library_info.bzl", "SphinxDocsLibraryInfo") 4 5def _sphinx_docs_library_impl(ctx): 6 strip_prefix = ctx.attr.strip_prefix or (ctx.label.package + "/") 7 direct_entries = [] 8 if ctx.files.srcs: 9 entry = struct( 10 strip_prefix = strip_prefix, 11 prefix = ctx.attr.prefix, 12 files = ctx.files.srcs, 13 ) 14 direct_entries.append(entry) 15 16 return [ 17 SphinxDocsLibraryInfo( 18 strip_prefix = strip_prefix, 19 prefix = ctx.attr.prefix, 20 files = ctx.files.srcs, 21 transitive = depset( 22 direct = direct_entries, 23 transitive = [t[SphinxDocsLibraryInfo].transitive for t in ctx.attr.deps], 24 ), 25 ), 26 DefaultInfo( 27 files = depset(ctx.files.srcs), 28 ), 29 ] 30 31sphinx_docs_library = rule( 32 implementation = _sphinx_docs_library_impl, 33 attrs = { 34 "deps": attr.label_list( 35 doc = """ 36Additional `sphinx_docs_library` targets to include. They do not have the 37`prefix` and `strip_prefix` attributes applied to them.""", 38 providers = [SphinxDocsLibraryInfo], 39 ), 40 "prefix": attr.string( 41 doc = "Prefix to prepend to file paths. Added after `strip_prefix` is removed.", 42 ), 43 "srcs": attr.label_list( 44 allow_files = True, 45 doc = "Files that are part of the library.", 46 ), 47 "strip_prefix": attr.string( 48 doc = "Prefix to remove from file paths. Removed before `prefix` is prepended.", 49 ), 50 }, 51) 52