Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Databinding Support #614

Open
kageiit opened this issue Apr 5, 2018 · 21 comments
Open

Databinding Support #614

kageiit opened this issue Apr 5, 2018 · 21 comments

Comments

@kageiit
Copy link
Contributor

kageiit commented Apr 5, 2018

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
Copy link

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

@kageiit
Copy link
Contributor Author

kageiit commented Jul 23, 2018

@sangeetsuresh see ebcea6f#diff-5d4ed6b6392a62dd46960742f4402601 for an example of how the transform cli was added to okbuck.

The process essentially consists of a few steps

  • Create a java_binary that has the databinding CLI as the main class
  • Provide android layout files as sources to a genrule that runs the cli on them and outputs the sources required for compliation
  • Hookup the output of the genrule as an input source to the andrid_library rule

@erawhctim
Copy link

erawhctim commented Jan 7, 2019

@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
Copy link

sangeetsuresh commented Jan 7, 2019

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

@carlonzo
Copy link

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:

  • run the CLI tool mentioned above
  • added the generated source code and resources to the source sets of the project
  • enabled the annotation processor
  • build

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

@sangeetsuresh
Copy link

@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
Copy link

carlonzo commented Jun 3, 2019

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

@carlonzo
Copy link

carlonzo commented Jun 6, 2019

@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
Copy link

carlonzo commented Jun 6, 2019

@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
Copy link
Contributor Author

kageiit commented Jun 6, 2019

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

@carlonzo
Copy link

@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
Copy link
Contributor Author

kageiit commented Jun 22, 2019

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

@carlonzo
Copy link

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
Copy link

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
Copy link
Collaborator

    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
Copy link

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
Copy link
Member

tyvsmith commented Nov 11, 2019

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
Copy link

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

@mochadwi
Copy link

mochadwi commented Feb 6, 2020

Keep up the good works @carlonzo

@proytx
Copy link

proytx commented Apr 5, 2020

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
Copy link

carlonzo commented Jul 1, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants