GithubHelp home page GithubHelp logo

Comments (3)

bolinfest avatar bolinfest commented on April 25, 2024

I'm not sure what you mean.

If you have Java code that does not depend on anything in the Android SDK (i.e., the ordinary JDK), then use a java_library() rule to build that code.
If you have Java code that uses classes from the Android SDK, then compile it with an android_library() rule.

android_library() rules can depend on java_library() rules.

from buck.

jeromeernestgarcia avatar jeromeernestgarcia commented on April 25, 2024

Any given module could be compiled for Android or for J2SE. Currently we have an Android directory for Android specific source, a common directory for Java code that can run on anything, and a J2SE directory that has J2SE versions of the code that is in the Android directory. Buck encourages all the code to live in one tree, but having different platform builds complicates that. Is there a best-practices way to organize code of this sort in the buck environment?

from buck.

bolinfest avatar bolinfest commented on April 25, 2024

I believe that you could have everything in one tree. You just might have folders in the root like:

java/common/
java/android/
java/j2se/

or something like that. The BUCK files in the java/android/ and java/j2se/ folders would reference the ones in java/common/ as deps, assuming the dependencies are only one-way.

If the deps are two-way, then I would create a macro for each java_library rule in java/common/ that creates two rules: one that depends on the java/android/ versions of your deps and another that depends on the java/j2se/ versions. So you might have something like:

# Define this in a DEFS file that you list under includes in .buckconfig:
# http://facebook.github.io/buck/concept/buckconfig.html
def create_both_versions(name, srcs, deps):
  for type in ['j2se', 'android']:
    rule_name = '%s_%s' % (name, type)
    rule_deps = []
    for dep in deps:
      if dep.startswith('//java/XXX'):
        rule_deps.append(dep.replace('//java/XXX', '//java/XXX' + type))
      else:
        rule_deps.append(dep)
    java_library(
      name = rule_name,
      srcs = srcs,
      deps = rule_deps,
      visibility = [ 'PUBLIC' ],
    )

Then under //java/common/analytics, you might do:

# This creates both //java/common/analytics:analytics_j2se and
# //java/common/analytics:analytics_android
create_both_versions(
  name = 'analytics',
  srcs = glob(['*.java']),
  deps = [
    '//java/XXX/base:base',
  ],
)

So in //java/android/analytics, you can do:

android_library(
  name = 'analytics',
  srcs = glob(['*.java']),
  deps = [
    '//java/common/analytics:analytics_android',
  ],
)

It's not exactly how Buck is meant to be used, but it may be a useful workaround for you. Ultimately, we would like to support the idea of "flavors" of build rules, which would make this less awkward.

from buck.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.