Skip to content

Commit

Permalink
Restore historical behavior for --output-dir (#480)
Browse files Browse the repository at this point in the history
* Fix install instructions in README

* Make JUJU_REPOSITORY only a fallback for layers

Only look for layers / interfaces in JUJU_REPOSITORY if other, more
explicit env vars are not set.

* Restore historical behavior for --output-dir

Previous to #478, the behavior of `--output-dir` matched that of
`$JUJU_REPOSITORY` in that it specified a directory which would have a
`builds` or `{series}` directory created under it, which would then have
the final charm output dir created under that.  This got changed and
broke the charm builds for OpenStack, so this restores the previous
behavior of `--output-dir` while retaining the new semantics for
`--build-dir`.

* Fix build / cache dir checks when parents are missing
  • Loading branch information
johnsca committed Feb 5, 2019
1 parent fd999e3 commit 5807aa1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Installation

To run the latest stable release, use::

sudo snap install charm
sudo snap install charm --classic

You'll also almost certainly want to install Juju as well::

Expand Down
22 changes: 15 additions & 7 deletions charmtools/build/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,14 +656,15 @@ def inspect(self):
def normalize_build_dir(self):
charm_build_dir = os.environ.get('CHARM_BUILD_DIR')
juju_repo_dir = os.environ.get('JUJU_REPOSITORY')
series = self.series or 'builds'
if not self.build_dir:
if self.output_dir:
self.build_dir = self.output_dir / series
if charm_build_dir:
self.build_dir = path(charm_build_dir)
elif juju_repo_dir:
series = self.series or 'builds'
self.build_dir = path(juju_repo_dir) / series
else:
series = self.series or 'builds'
log.warn('Build dir not specified via command-line or '
'environment; defaulting to /tmp/charm-builds')
self.build_dir = path('/tmp/charm-builds')
Expand All @@ -690,19 +691,26 @@ def normalize_cache_dir(self):
'specify a different build directory with '
'--cache-dir or $CHARM_CACHE_DIR')

def _check_path(self, path_to_check, need_write=False):
def _check_path(self, path_to_check, need_write=False, can_create=False):
if not path_to_check:
return
if not os.path.exists(path_to_check):
path_to_check = os.path.dirname(path_to_check)
if not can_create:
raise BuildError('Missing required path: '
'{}'.format(path_to_check))
try:
path_to_check.makedirs_p()
except Exception:
raise BuildError('Unable to create required path: '
'{}'.format(path_to_check))
if not os.access(path_to_check, os.R_OK):
raise BuildError('Unable to read from: {}'.format(path_to_check))
if need_write and not os.access(path_to_check, os.W_OK):
raise BuildError('Unable to write to: {}'.format(path_to_check))

def check_paths(self):
self._check_path(self.build_dir, need_write=True)
self._check_path(self.cache_dir, need_write=True)
self._check_path(self.build_dir, need_write=True, can_create=True)
self._check_path(self.cache_dir, need_write=True, can_create=True)
self._check_path(self.wheelhouse_overrides)

def clean_removed(self, signatures):
Expand Down Expand Up @@ -851,7 +859,7 @@ def main(args=None):
formatter_class=argparse.RawDescriptionHelpFormatter,)
parser.add_argument('-l', '--log-level', default=logging.INFO)
parser.add_argument('-f', '--force', action="store_true")
parser.add_argument('-o', '--output-dir', type=path, dest='build_dir',
parser.add_argument('-o', '--output-dir', type=path,
help='Alias for --build-dir')
parser.add_argument('-d', '--build-dir', type=path,
help='Directory under which to place built charms; '
Expand Down
4 changes: 3 additions & 1 deletion charmtools/build/fetchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ def can_fetch(cls, url):

if not cls.NO_LOCAL_LAYERS:
prefixed_name = '{}-{}'.format(cls.NAMESPACE, name)
search_path = [os.environ.get("JUJU_REPOSITORY", ".")]
search_path = []
if cls.ENVIRON in os.environ:
search_path.append(os.environ[cls.ENVIRON])
elif cls.OLD_ENVIRON in os.environ:
search_path.append(os.environ[cls.OLD_ENVIRON])
else:
search_path.append(os.environ.get("JUJU_REPOSITORY", "."))
for part in search_path:
basepath = path(part)
for dirname in (name, prefixed_name):
Expand Down

0 comments on commit 5807aa1

Please sign in to comment.