Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

[buildfile] includes doesn't act like include_defs #199

Closed
saadfarooq opened this issue Sep 21, 2014 · 6 comments
Closed

[buildfile] includes doesn't act like include_defs #199

saadfarooq opened this issue Sep 21, 2014 · 6 comments

Comments

@saadfarooq
Copy link

The documentation says that the includes property in the [buildfile] section of .buckconfig is equivalent to invoking include_defs at the start of each file.

However, when I include the following in a BUCK file it works fine but if I include it (via a file) in .buckconfig, it gives an error on the sha1 line.

include_defs('//bucklets/maven_jar.bucklet')
maven_jar(
  name = 'junit',
  id = 'junit:junit:4.11',
  sha1 = '4e031bb61df09069aeb2bffb4019e7a5034a4ee0'
)

Is this expected behavior ?

@davido
Copy link
Contributor

davido commented Sep 21, 2014

It mostly works. This was already reported and tracked in #182. According to comments there, this bug was already fixed and the fix about to land shortly.

@saadfarooq
Copy link
Author

Cool. Thanks.

@davido
Copy link
Contributor

davido commented Sep 21, 2014

I probably misread your bug report, but this is unusually that you observe failure on sha1 line. I think exact your setting is up and running in gitiles project. Try pull and bulid it with buck build all and see how it's different from your case: [1]. Note, that gitile is using bucklet as submodule.

[1] git clone https://gerrit.googlesource.com/gitiles

@davido
Copy link
Contributor

davido commented Sep 21, 2014

So this works: include this lines in .buckconfig :

[buildfile]
  includes = //bucklets.defs

And put this in bucklet.defs:

$ cat bucklets.defs
import os
import sys

d = os.getcwd()
while not os.path.lexists(os.path.join(d, '.buckversion')):
  d = os.path.dirname(d)

bd = os.path.join(d, 'bucklets')
if not os.path.isdir(bd) or not os.listdir(bd):
  sys.stderr.write(('Bucklets directory is missing or empty: %s\n'
                    'Run `git submodule update --init`') % bd)
  sys.exit(1)

bucklets = [
  'java_doc.bucklet',
  'java_sources.bucklet',
  'maven_jar.bucklet',
  'maven_package.bucklet',
  'war.bucklet',
]

for bucklet in bucklets:
  path = os.path.join(bd, bucklet)
  if not os.path.isfile(path):
    sys.stderr.write('Missing bucklet: %s\n' % path)
    sys.exit(1)
  include_defs('//bucklets/%s' % bucklet)

And now you don't need any more to include bucklets directly in you BUCK file, but should be able to just say:

maven_jar(
  name = 'junit',
  id = 'junit:junit:4.11',
  sha1 = '4e031bb61df09069aeb2bffb4019e7a5034a4ee0'
)

Or better say this to reflect hamcrest deps as well:

maven_jar(
  name = 'junit',
  id = 'junit:junit:4.11',
  sha1 = '4e031bb61df09069aeb2bffb4019e7a5034a4ee0',
  deps = [':hamcrest-core'],
)

maven_jar(
  name = 'hamcrest-core',
  id = 'org.hamcrest:hamcrest-core:1.3',
  sha1 = '42a25dc3219429f0e5d060061f71acb49bf010a0',
  visibility = ['//lib:junit'],
)

@saadfarooq
Copy link
Author

That works. Thanks.
One comment though. The while not keeps looping forever if there is no `.buckversion' file.

@davido
Copy link
Contributor

davido commented Sep 22, 2014

Thanks for reporting. Change under review [1].

[1] https://gerrit-review.googlesource.com/60264

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

No branches or pull requests

2 participants