diff options
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/ideinfo/intellij_info.bzl')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/ideinfo/intellij_info.bzl | 71 |
1 files changed, 56 insertions, 15 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/ideinfo/intellij_info.bzl b/src/test/java/com/google/devtools/build/lib/ideinfo/intellij_info.bzl index 251a0a2155..feb37fef59 100644 --- a/src/test/java/com/google/devtools/build/lib/ideinfo/intellij_info.bzl +++ b/src/test/java/com/google/devtools/build/lib/ideinfo/intellij_info.bzl @@ -28,23 +28,72 @@ _kind_to_kind_id = { _unrecognized_rule = -1; +DEPENDENCY_ATTRIBUTES = [ + "deps", + "exports", + "_robolectric", # From android_robolectric_test + "_junit", # From android_robolectric_test + "binary_under_test", # From android_test + "java_lib",# From proto_library + "_proto1_java_lib", # From proto_library +] + def get_kind(target, ctx): return _kind_to_kind_id.get(ctx.rule.kind, _unrecognized_rule) +def is_java_rule(target, ctx): + return ctx.rule.kind != "android_sdk"; + +def artifact_location(file): + return struct( + root_path = file.root.path, # todo(dslomov): this gives path relative to execution root + relative_path = file.short_path, + is_source = file.is_source, + ) + +def java_rule_ide_info(target, ctx): + if hasattr(ctx.rule.attr, "srcs"): + sources = [artifact_location(file) + for src in ctx.rule.attr.srcs + for file in src.files] + else: + sources = [] + return struct(sources = sources) # todo(dslomov): more fields + + def _aspect_impl(target, ctx): - ide_info_text = set() kind = get_kind(target, ctx) + rule_attrs = ctx.rule.attr + + ide_info_text = set() + all_deps = [] + + for attr_name in DEPENDENCY_ATTRIBUTES: + if hasattr(rule_attrs, attr_name): + deps = getattr(rule_attrs, attr_name) + for dep in deps: + ide_info_text += dep.android_studio_info_files + all_deps += [str(dep.label) for dep in deps] + if kind != _unrecognized_rule: + if is_java_rule(target, ctx): + info = struct( + label = str(target.label), + kind = kind, + dependencies = all_deps, + # build_file = ??? + java_rule_ide_info = java_rule_ide_info(target, ctx) + ) + else: info = struct( label = str(target.label), kind = kind, + dependencies = all_deps, # build_file = ??? ) - output = ctx.new_file(target.label.name + ".aswb-build.txt") - ctx.file_action(output, info.to_proto()) - ide_info_text += set([output]) - for dep in ctx.rule.attr.deps: - ide_info_text += dep.android_studio_info_files + output = ctx.new_file(target.label.name + ".aswb-build.txt") + ctx.file_action(output, info.to_proto()) + ide_info_text += set([output]) return struct( output_groups = { @@ -54,13 +103,5 @@ def _aspect_impl(target, ctx): ) intellij_info_aspect = aspect(implementation = _aspect_impl, - attr_aspects = [ - "deps", - "exports", - "_robolectric", # From android_robolectric_test - "_junit", # From android_robolectric_test - "binary_under_test", # From android_test - "java_lib",# From proto_library - "_proto1_java_lib", # From proto_library - ] + attr_aspects = DEPENDENCY_ATTRIBUTES )
\ No newline at end of file |