uber / okbuck

OkBuck is a gradle plugin that lets developers utilize the Buck build system on a gradle project.
Other
1.54k stars 168 forks source link

Databinding Support #614

Open kageiit opened 6 years ago

kageiit commented 6 years ago

Databinding has a CLI compiler that is in aosp (no artifact on maven.google.com yet). It is only two classes, but it allows ingesting layout xml files and outputting the metadata required by the databinding annotation processor to work correctly.

By using a genrule to pre-process the resources of a module, databinding support can be added in buck/okbuck

sangeetsuresh commented 6 years ago

@kageiit I am looking forward to implement data binding support. Could you please guide me in implementing that.

kageiit commented 6 years ago

@sangeetsuresh see https://github.com/uber/okbuck/commit/ebcea6f0950d37536e18e0bfe7ae6eb39ebf4064#diff-5d4ed6b6392a62dd46960742f4402601 for an example of how the transform cli was added to okbuck.

The process essentially consists of a few steps

erawhctim commented 5 years ago

@sangeetsuresh Just curious - are you actively working on this? I'm trying to figure out if I should rip out the minimal use of DataBinding in order to be able to use Buck/OkBuck

sangeetsuresh commented 5 years ago

@erawhctim I am not actively working on it. I am just figuring out how to implement that in buck.

carlonzo commented 5 years ago

I am currently actively working on it. I have successfully built a demo project using a modified version of the generated BUCK file from okbuck.

basically I have:

it was actually pretty easy. I'm now working on understanding what is the best way to integrate it to okbuck/buck

sangeetsuresh commented 5 years ago

@carlonzo Can you put that code in some repo so that I could also go through that. It will be helpful for me as I am also looking for implementing data binding for buck

carlonzo commented 5 years ago

Sure. I have it on a private repo until I cleanup the experiments, the I will publish

carlonzo commented 5 years ago

@carlonzo Can you put that code in some repo so that I could also go through that. It will be helpful for me as I am also looking for implementing data binding for buck

You can check https://github.com/carlonzo/BuckDatabindingDemo

the most important part is the file databinder.sh to run before, then start the compilation with buck build bin_devDebug . do not use okbuck as it will override the BUCK files. I'm currently trying to write few genrule rules to remove the databinder.sh file.

@kageiit I have few issues when I try to hookup the output of a genrule (which produces a folder with jave files) to the srcs of the android_library rule. are you aware if that is supposed to work? (do you have any example I can look at?) the only way I can make it work (partially. still get few compilation errors) is to generate a .src.zip file and append it to the srcs.

carlonzo commented 5 years ago

@sangeetsuresh Actually I've finally debugged and fixed the issue with android_library (I need to pass the generated java files as a zip to the srcs list) this is the BUCK file with the rules: https://github.com/carlonzo/BuckDatabindingDemo/blob/buck-rules/app/BUCK

I will try now to cleanup (sorry @kageiit to bother, but as I'm a newbie can you have a look at the BUCK file above to see if you can spot any issue? I have still many absolute paths to convert. for example I have no idea how to pull the location of the output folder of the genrules in extra_arguments in src_devDebug rule. do you have any tip? )

kageiit commented 5 years ago

.src.zip is the way to go. Ill take a look at the buck files this week

carlonzo commented 5 years ago

@kageiit did you have some time to have a look? mostly to check if there is any mistake (this my first time I use BUCK), and if you have any tips how I can avoid absolute paths in in extra_arguments in src_devDebug rule and in the genrules. Any suggestion is welcome :)

kageiit commented 5 years ago

cc @raviagarwal7 ^ can help take a look as i will be on vacation for a bit

carlonzo commented 5 years ago

hi @raviagarwal7 can you let me know if you can take a look about the above? I want to start writing a PR to implement the data binding but I am stuck with few doubts. many thanks! cc @kageiit

carlonzo commented 5 years ago

hi @kageiit @raviagarwal7 I would like to continue the development as I believe we are not far from having a solution on okbuck to have databinding working.

As mentioned above the only issue that I believe needs to be solved are the absolute paths in the okbuck_android_module rule which point to the generated files from the genrules. do you have any tip to fix that? is there any way I can add/create expandable variables pointing to the generated output folders? once I solved that I believe I have enough to try the development of a solution. as a reference, here is a working buck file I would need to generate from okbuck https://github.com/carlonzo/BuckDatabindingDemo/blob/buck-rules/app/BUCK thanks!

raviagarwal7 commented 5 years ago
    cmd = 'java -jar /Users/carlo/Projects/BuckApp/bins/android-data-binding-exec-3.4.0.jar PROCESS ' +

You can instead do

    cmd = 'java -jar (location {}) PROCESS '.format(<android-data-binding-target) +

more info on location macro - https://buck.build/function/string_parameter_macros.html#content

carlonzo commented 5 years ago

Hi @raviagarwal7 , thanks for that. I can read that those macros only apply to genrule, apk_genrule, cxx_genrule

but my problem is mostly with the arguments in the extra_arguments in the okbuck_android_module (which I believe is an alias for the android_library rule). anything that help me there?

tyvsmith commented 5 years ago

extra_kotlinc_arguments seems to reference by relative path, that may be a pattern to follow if location won't work.

Example:

extra_kotlinc_arguments = [
        "-Xplugin=buck-out/gen/.okbuck/workspace/kotlin_home/kotlin_home/libexec/lib/kotlin-android-extensions.jar",
    ],
carlonzo commented 5 years ago

Thanks for the tip man. I'll have a look how it works!

mochadwi commented 4 years ago

Keep up the good works @carlonzo

proytx commented 4 years ago

I am new to buck - trying to understand how this databinding implementation is working, apologies if this is a basic question. How exactly are the PROCESS and GEN_BASE_CLASSES handled by android-data-binding-exec-3.4.0.jar - are those string args? When I look at the code here CLI I don't see where those are. I see these args package minSdk library resInput resOutput layoutInfoOutput zipLayoutInfo

carlonzo commented 4 years ago

sorry @proytx I may have missed your message. you were looking at an old branch of databinding. I would suggest to look at here about your question, the arguments are listed in the 2 options files here