using the output of a ctx.action

927 views
Skip to first unread message

ittai zeidman

unread,
Mar 1, 2017, 3:17:50 PM3/1/17
to bazel-discuss
Hi,
I need to get a list of all entries in an archive which match a pattern to later on manipulate them a bit and concat them to a single string with a comma separated list.
It seems ctx.action is the way I want to go but I'm not sure how to use the output.
Been thinking of something like:
def _discover_classes(ctx, suffix, archive):
    classes = ctx.new_file(ctx.label.name + "_classes")
    ctx.action(
      inputs=[archive],
      outputs=[classes],
      progress_message="Discovering classes with suffix of %s" % suffix,
#still need to trim the path of the entries
      command="unzip -l {archive} | grep {suffix}.class".format(archive=archive, suffix=suffix))
    return classes

I don't know what I can do with classes since I think it's the file where what I want is its contents.

Thanks in advance

ittai zeidman

unread,
Mar 6, 2017, 10:17:02 AM3/6/17
to bazel-discuss
Ok,
So I was able to understand that I'm not supposed to be able to read the file in skylark (I think it's to facilitate determinism on the one hand and fast analysis on the other hand).
I think but really really not sure that I need to get this file added to the runfiles but I'm not sure how...

What I currently do is:
1. create a file which contains the content I'm interested in (ctx.new_file and ctx.action). This isn't declared in the outputs since it's a temp file for the file AFAIC.
2. create a test launcher, an executable file which starts jvm (using ctx.file_action)
3. use a common method to the scala rules which builds an executable.

The problem I face is that the file created at #1 is missing. I first thought it was because it's on the classpath generated in #2 so I added it there but I can't find it anywhere on the filesystem so I think that I might have an additional two problems:
1. The file isn't created
2. The file isn't exposed to the test (runfiles?)
The problem can be #1, #2 or both.

This is the code:

Damien Martin-guillerez

unread,
Mar 6, 2017, 10:20:24 AM3/6/17
to ittai zeidman, bazel-discuss
Hi ittai,

You need to add the generated_classes file to the runfiles provider. See https://bazel.build/versions/master/docs/skylark/rules.html#runfiles


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/03b1902d-224b-43e5-bacf-c266557527f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mizux Seiha

unread,
Apr 6, 2022, 10:04:59 AM4/6/22
to bazel-discuss
dead link...

Maybe replaced by https://bazel.build/rules/rules?hl=en ?

Mizux Seiha

unread,
Apr 6, 2022, 10:16:06 AM4/6/22
to bazel-discuss
Reply all
Reply to author
Forward
0 new messages