Skip to content

Commit

Permalink
Fixup android local resolvers.
Browse files Browse the repository at this point in the history
Previously the android local SDK resolvers used <ibiblio/> with local
file:// roots.  This led to issues resolving any <dependency/> with a
custom artifact file:// url itself.

Simplify ResolveJarsTestMixin which no longer needs a custom
ivysettings.xml as a result of this fix.

Testing Done:
This ran green locally (I have an android setup):
```
$ ./pants clean-all test \
  tests/python/pants_test/android/:: \
  tests/python/pants_test/backend/project_info/::
```

CI went green here:
  https://travis-ci.org/pantsbuild/pants/builds/83968079

Bugs closed: 2324

Reviewed at https://rbcommons.com/s/twitter/r/2934/
  • Loading branch information
jsirois committed Oct 7, 2015
1 parent 8671207 commit 29c0e81
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
45 changes: 33 additions & 12 deletions build-support/ivy/ivysettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,33 @@ Licensed under the Apache License, Version 2.0 (see LICENSE).
-->

<ivysettings>

<settings defaultResolver="pants-chain-repos"/>

<properties environment="env" />
<property name="m2.repo.relpath" value="[organisation]/[module]/[revision]"/>
<property name="m2.repo.pom" value="${m2.repo.relpath}/[module]-[revision].pom"/>
<property name="m2.repo.artifact"
value="${m2.repo.relpath}/[artifact](-[classifier])-[revision].[ext]"/>
<property name="m2.repo.dir" value="${user.home}/.m2/repository" override="false"/>

<property name="env.ANDROID_HOME" value="/please-export-your-ANDROID_HOME" override="false"/>
<property name="android.repo.dir" value="${env.ANDROID_HOME}/extras/android/m2repository"/>
<property name="google.repo.dir" value="${env.ANDROID_HOME}/extras/google/m2repository"/>
<!-- This dance to set ANDROID_HOME seems more complex than it need be, but an absolute path is
needed whether or not the ANDROID_HOME env var is set and just using the following does
not work to default the value when unset in the environment:
<properties environment="env"/>
<property name="env.ANDROID_HOME" value="/please-export-your-ANDROID_HOME" override="false"/>
-->
<properties environment="env"/>
<property name="ANDROID_HOME"
value="/please-export-your-ANDROID_HOME"
unlessset="env.ANDROID_HOME"/>
<property name="ANDROID_HOME"
value="${env.ANDROID_HOME}"
ifset="env.ANDROID_HOME"/>

<property name="android.repo.dir" value="${ANDROID_HOME}/extras/android/m2repository"/>
<property name="google.repo.dir" value="${ANDROID_HOME}/extras/google/m2repository"/>

<resolvers>

<chain name="pants-chain-repos" returnFirst="true">
Expand All @@ -27,21 +41,28 @@ Licensed under the Apache License, Version 2.0 (see LICENSE).
We setup the maven central resolver to require successful pom downloads here. -->
<ibiblio name="maven-central" m2compatible="true" descriptor="required"/>

<!-- NB: Although url resolvers (like <ibiblio/>) can be pointed at local file:// system
URLs, this leads to issues resolving any <dependency/> with a custom artifact that
defines a file:// url itself. We stick to <filesystem/> resolvers here for the
two android SDK resolvers as a result. -->

<!-- Android SDK Support Library, found in reference to the ANDROID_HOME variable. -->
<ibiblio name="local.android"
m2compatible="true"
root="file://${android.repo.dir}/"/>
<filesystem name="local.android" m2compatible="true" local="true">
<ivy pattern="${android.repo.dir}/${m2.repo.pom}"/>
<artifact pattern="${android.repo.dir}/${m2.repo.artifact}"/>
</filesystem>

<!-- Google Libraries for the Android SDK, found in reference to ANDROID_HOME. -->
<ibiblio name="local.google"
m2compatible="true"
root="file://${google.repo.dir}/"/>
<filesystem name="local.google" m2compatible="true" local="true">
<ivy pattern="${google.repo.dir}/${m2.repo.pom}"/>
<artifact pattern="${google.repo.dir}/${m2.repo.artifact}"/>
</filesystem>

<!-- The mvn standard local filesystem repo/cache -->
<filesystem name="local.m2" m2compatible="true" local="true" checkmodified="true">
<ivy pattern="${m2.repo.dir}/${m2.repo.pom}"/>
<artifact pattern="${m2.repo.dir}/${m2.repo.artifact}"/>
</filesystem>

</chain>
</resolvers>
</ivysettings>
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,6 @@ def _test_jar_lib_with_url(self, load_all):
with temporary_dir(root_dir=self.workdir_root()) as source_dir:
with temporary_dir(root_dir=self.workdir_root()) as dist_dir:
os.makedirs(os.path.join(source_dir, 'src'))
ivy_settings = os.path.join(source_dir, 'build-support', 'ivy', 'ivysettings.xml')
os.makedirs(os.path.dirname(ivy_settings))
with open(ivy_settings, 'w+') as f:
# NB(gmalmquist): It is necessary to use ivysettings different from the default to allow
# resolution of jars from the local filesystem. (This took quite some time to determine,
# because the ivy cache made it seem like resolves were working when they shouldn't,
# hence the step to delete the cached artifact generated by this test a couple dozen
# lines down).
f.write(dedent('''
<?xml version="1.0"?>
<ivysettings>
<settings defaultResolver="default"/>
<include url="${ivy.default.settings.dir}/ivysettings.xml"/>
</ivysettings>
''').strip())
with open(os.path.join(source_dir, 'BUILD'), 'w+') as f:
f.write(dedent('''
source_root('src')
Expand Down Expand Up @@ -100,10 +85,7 @@ def _test_jar_lib_with_url(self, load_all):
targets = ['{0}:{1}'.format(os.path.join(source_dir, 'src'), name) for name in spec_names]

with temporary_dir() as ivy_temp_dir:
extra_args = [
'--ivy-ivy-settings={}'.format(ivy_settings),
'--ivy-cache-dir={}'.format(ivy_temp_dir),
]
extra_args = ['--ivy-cache-dir={}'.format(ivy_temp_dir)]
self.evaluate_subtask(targets, workdir, load_all, extra_args=extra_args,
expected_jars=['org.pantsbuild:synthetic-test-jar:1.2.3'])

Expand Down

0 comments on commit 29c0e81

Please sign in to comment.