Using generated resources for an android_resource rule

57 views
Skip to first unread message

Benjamin Kohler-Crowe

unread,
Dec 10, 2015, 6:32:51 PM12/10/15
to Buck
Hi!

I want to create a android_resource rule that includes both checked-in resources and generated resources.  I have a genrule that's creating the files I want, but I can't figure out how to get android_resource to tie them together.  The documentation for android_resource says that I should be able to pass additional resource directories via deps, but both ways I can think of to do so give different errors.

The last step of my generating looks like this, just for reference:

    genrule (
        name = 'compileTzData',
        srcs = glob(['tzdata/**']),
        out = 'res',
        cmd = '$(exe :compileTzData_binary) $SRCDIR $OUT',
        visibility = ['PUBLIC'],
    )

This puts a properly-layed-out "res" directory down under buck-out.

Here was my first approach to pull those in:

    # One-step?
    android_resource(
        name = 'res',
        res = 'library/src/main/res',
        deps =
        [
            ':compileTzData',
        ],
        package = 'net.danlew.android.joda',
        visibility = ['PUBLIC'],
    )

That errors with:
dependency //3rdparty/jodatime_android:compileTzData (genrule) is not of type android_resource or android_library


So, I tried wrapping the genrule with an extra step of android_resource:

    # Two-step?
    android_resource(
        name = 'res_generated',
        res = ':compileTzData',
        package = 'net.danlew.android.joda',
    )

    android_resource(
        name = 'res',
        res = 'library/src/main/res',
        deps =
        [
            ':res_generated',
        ],
        package = 'net.danlew.android.joda',
        visibility = ['PUBLIC'],
    )

But that refuses to recognize the "res" argument as "output of this other rule", and instead interprets it as "literal directory name", like so:
parameter 'res': no such file or directory '3rdparty/jodatime_android/:compileTzData

Is there a way to get this to work?

I'm on a snapshot of Buck from back in March -- 9219f0adc65c6e5c5171d3af7ca98d1454ec3dd1 specifically.  I've tried updating to latest today (9663eb09f844482f88523cc4c325f2fa10132db7), but that broke some existing genrules that are used by just about all our libraries -- more than I want to try to solve today, or even this week.  :)  But if there's a change somewhere between March and now that solves this, I'd be happy to try moving everyone here to that version.

Thanks!
-Ben

Benjamin Kohler-Crowe

unread,
Dec 10, 2015, 6:45:06 PM12/10/15
to Buck
I just tried more-recent-but-not-quite-so-recent, end of August, and got an error message I can't even make sense of.

BUILD FAILED: com.facebook.buck.model.BuildTarget.compareTo(Lcom/facebook/buck/model/BuildTarget;)I

Uri Baghin

unread,
Dec 10, 2015, 8:39:50 PM12/10/15
to Benjamin Kohler-Crowe, Buck
I think it might work if you specify it in the res attribute like:

    android_resource(
        name = 'res',
        res = ':compileTzData',
        package = 'net.danlew.android.joda',
        visibility = ['PUBLIC'],
    )

--
You received this message because you are subscribed to the Google Groups "Buck" group.
To unsubscribe from this group and stop receiving emails from it, send an email to buck-build+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Benjamin Kohler-Crowe

unread,
Dec 10, 2015, 8:51:45 PM12/10/15
to Buck
That's what I'm trying in the first step of my second approach above:


    android_resource(
        name = 'res_generated',
        res = ':compileTzData',
        package = 'net.danlew.android.joda',
    )

That's what gives the error:

parameter 'res': no such file or directory '3rdparty/jodatime_android/:compileTzData

(I *think* that, if I could get that to work, the next step would pull those and the checked-in resources together correctly.)

Benjamin Kohler-Crowe

unread,
Dec 14, 2015, 3:56:47 PM12/14/15
to Buck
For anyone stumbling upon this:

I think I found the commit that fixed this issue,
https://github.com/facebook/buck/commit/e723e64c0423714528d7368c5899ab965a559adc

(But at this point I'm working on updating all our builds to work with all the other intervening changes -- removal of deps from genrule and removal of target from android_binary, mostly.  So, I haven't confirmed whether just moving to that July commit would have been sufficient.)

-Ben

Shawn Wilsher

unread,
Dec 14, 2015, 4:10:43 PM12/14/15
to buck-...@googlegroups.com
I had missed that you were on a really old rev, which now explains why I
was confused about the code not working.

Cheers,

Shawn
Reply all
Reply to author
Forward
0 new messages