Use multiple locations for elements dir.
Using ELEMENTS_DIR env variable, you can specify multiple dirs containint your elements. It must be a ":" separated elements list. When an element is seen in one of those lists, it will be chosen and will continue with the next element. Change-Id: I18eca27d943139cd6ca1ebd232b419e502d7b048
This commit is contained in:
parent
7d1a4adc17
commit
308eee2827
@ -256,6 +256,11 @@ The scripts can generally just be run. Options can be set on the command line
|
|||||||
or by exporting variables to override those present in lib/img-defaults. -h to
|
or by exporting variables to override those present in lib/img-defaults. -h to
|
||||||
get help.
|
get help.
|
||||||
|
|
||||||
|
|
||||||
|
Using the variable ELEMENTS_PATH will allow to specify multiple elements locations.
|
||||||
|
It's a colon (:) separated path list, and it will work in a first path/element found,
|
||||||
|
first served approach.
|
||||||
|
|
||||||
Copyright
|
Copyright
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
@ -35,6 +35,8 @@ function show_options () {
|
|||||||
echo " -c -- clear environment before starting work"
|
echo " -c -- clear environment before starting work"
|
||||||
echo " -n skip the default inclusion of the 'base' element"
|
echo " -n skip the default inclusion of the 'base' element"
|
||||||
echo " -p package[,package,package] -- list of packages to install in the image"
|
echo " -p package[,package,package] -- list of packages to install in the image"
|
||||||
|
echo
|
||||||
|
echo "ELEMENTS_PATH will allow you to specify multiple locations for the elements."
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,9 +20,9 @@ import sys
|
|||||||
|
|
||||||
|
|
||||||
def get_elements_dir():
|
def get_elements_dir():
|
||||||
if not os.environ.get('ELEMENTS_DIR'):
|
if not os.environ.get('ELEMENTS_PATH'):
|
||||||
raise Exception("$ELEMENTS_DIR must be set.")
|
raise Exception("$ELEMENTS_PATH must be set.")
|
||||||
return os.environ['ELEMENTS_DIR']
|
return os.environ['ELEMENTS_PATH']
|
||||||
|
|
||||||
|
|
||||||
def dependencies(element, elements_dir=None):
|
def dependencies(element, elements_dir=None):
|
||||||
@ -37,15 +37,21 @@ def dependencies(element, elements_dir=None):
|
|||||||
if elements_dir is None:
|
if elements_dir is None:
|
||||||
elements_dir = get_elements_dir()
|
elements_dir = get_elements_dir()
|
||||||
|
|
||||||
element_deps_path = os.path.join(elements_dir, element, 'element-deps')
|
for path in elements_dir.split(':'):
|
||||||
try:
|
element_deps_path = (os.path.join(path, element, 'element-deps'))
|
||||||
with open(element_deps_path) as element_deps:
|
try:
|
||||||
return set([line.strip() for line in element_deps])
|
with open(element_deps_path) as element_deps:
|
||||||
except IOError as e:
|
return set([line.strip() for line in element_deps])
|
||||||
if e.errno == 2:
|
except IOError as e:
|
||||||
return set()
|
if os.path.exists(os.path.join(path, element)) and e.errno == 2:
|
||||||
else:
|
return set()
|
||||||
raise
|
if e.errno == 2:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
|
sys.stderr.write("ERROR: Element %s doesn't exists\n" % (element, ))
|
||||||
|
exit(-1)
|
||||||
|
|
||||||
|
|
||||||
def expand_dependencies(user_elements, elements_dir=None):
|
def expand_dependencies(user_elements, elements_dir=None):
|
||||||
|
@ -77,9 +77,9 @@ class TestElementDeps(TestCase):
|
|||||||
|
|
||||||
class TestElements(TestCase):
|
class TestElements(TestCase):
|
||||||
def test_depends_on_env(self):
|
def test_depends_on_env(self):
|
||||||
self.useFixture(EnvironmentVariable('ELEMENTS_DIR', '/foo/bar'))
|
self.useFixture(EnvironmentVariable('ELEMENTS_PATH', '/foo/bar'))
|
||||||
self.assertEquals('/foo/bar', get_elements_dir())
|
self.assertEquals('/foo/bar', get_elements_dir())
|
||||||
|
|
||||||
def test_env_not_set(self):
|
def test_env_not_set(self):
|
||||||
self.useFixture(EnvironmentVariable('ELEMENTS_DIR', ''))
|
self.useFixture(EnvironmentVariable('ELEMENTS_PATH', ''))
|
||||||
self.assertRaises(Exception, get_elements_dir, ())
|
self.assertRaises(Exception, get_elements_dir, ())
|
||||||
|
@ -39,8 +39,11 @@ function save_image () {
|
|||||||
function generate_hooks () {
|
function generate_hooks () {
|
||||||
mkdir -p $TMP_HOOKS_PATH
|
mkdir -p $TMP_HOOKS_PATH
|
||||||
for _ELEMENT in $IMAGE_ELEMENT ; do
|
for _ELEMENT in $IMAGE_ELEMENT ; do
|
||||||
[ -d $ELEMENTS_DIR/$_ELEMENT ] || die "Element $_ELEMENT does not exist." ;
|
for dir in $(echo $ELEMENTS_PATH | tr ":" " ") ; do
|
||||||
cp -t $TMP_HOOKS_PATH -a $ELEMENTS_DIR/$_ELEMENT/* ;
|
[ -d $dir/$_ELEMENT ] || continue
|
||||||
|
cp -t $TMP_HOOKS_PATH -a $dir/$_ELEMENT/* ;
|
||||||
|
break
|
||||||
|
done
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,4 +22,4 @@ IMAGE_NAME=${IMAGE_NAME:-image}
|
|||||||
export IMAGE_SIZE=${IMAGE_SIZE:-2} # N.B. This size is in GB
|
export IMAGE_SIZE=${IMAGE_SIZE:-2} # N.B. This size is in GB
|
||||||
# Set via the CLI normally.
|
# Set via the CLI normally.
|
||||||
# IMAGE_ELEMENT=
|
# IMAGE_ELEMENT=
|
||||||
export ELEMENTS_DIR=$(dirname $0)/../elements
|
export ELEMENTS_PATH=${ELEMENTS_PATH:-(dirname $0)/../elements}
|
||||||
|
@ -21,4 +21,4 @@ MODULE_ROOT=${MODULE_ROOT:-""}
|
|||||||
LIB_UDEV_ROOT=${LIB_UDEV_ROOT:-""}
|
LIB_UDEV_ROOT=${LIB_UDEV_ROOT:-""}
|
||||||
BUSYBOX=${BUSYBOX:-$(which busybox)}
|
BUSYBOX=${BUSYBOX:-$(which busybox)}
|
||||||
IMAGE_NAME=${IMAGE_NAME:-"ramdisk"}
|
IMAGE_NAME=${IMAGE_NAME:-"ramdisk"}
|
||||||
export ELEMENTS_DIR=$(dirname $0)/../elements
|
export ELEMENTS_PATH=${ELEMENTS_PATH:-(dirname $0)/../elements}
|
||||||
|
@ -31,12 +31,16 @@ function cleanup () {
|
|||||||
function ensure_binaries() {
|
function ensure_binaries() {
|
||||||
BINARY_DEPS="${BUSYBOX}"
|
BINARY_DEPS="${BUSYBOX}"
|
||||||
for _FLVR in ${RAMDISK_ELEMENT} ; do
|
for _FLVR in ${RAMDISK_ELEMENT} ; do
|
||||||
_FILE="${ELEMENTS_DIR}/${_FLVR}/binary-deps"
|
for dir in $(echo $ELEMENTS_PATH | tr ":" " ") ; do
|
||||||
if [ -a $_FILE ]; then
|
[ -d $dir/$_FLVR ] || continue
|
||||||
for _LINE in $(cat $_FILE) ; do
|
_FILE="${dir}/${_FLVR}/binary-deps"
|
||||||
BINARY_DEPS="${BINARY_DEPS} $_LINE"
|
if [ -a $_FILE ]; then
|
||||||
done
|
for _LINE in $(cat $_FILE) ; do
|
||||||
fi
|
BINARY_DEPS="${BINARY_DEPS} $_LINE"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
break
|
||||||
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
for _BIN in $BINARY_DEPS ; do
|
for _BIN in $BINARY_DEPS ; do
|
||||||
@ -171,14 +175,17 @@ function populate_init () {
|
|||||||
|
|
||||||
# Append /init with any element fragments that are present
|
# Append /init with any element fragments that are present
|
||||||
for _FLVR in ${RAMDISK_ELEMENT} ; do
|
for _FLVR in ${RAMDISK_ELEMENT} ; do
|
||||||
_FILE="${ELEMENTS_DIR}/${_FLVR}/init"
|
for dir in $(echo $ELEMENTS_PATH | tr ":" " ") ; do
|
||||||
if [ -a $_FILE ]; then
|
[ -d $dir/$_FLVR ] || continue
|
||||||
cat >>$TMP_MOUNT_PATH/init <<EOF
|
_FILE="${dir}/${_FLVR}/init"
|
||||||
|
if [ -a $_FILE ]; then
|
||||||
|
cat >>$TMP_MOUNT_PATH/init <<EOF
|
||||||
# init fragment from ${_FLVR}
|
# init fragment from ${_FLVR}
|
||||||
EOF
|
EOF
|
||||||
cat <$_FILE >>$TMP_MOUNT_PATH/init
|
cat <$_FILE >>$TMP_MOUNT_PATH/init
|
||||||
fi
|
fi
|
||||||
|
break
|
||||||
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
# Add our final steps to /init
|
# Add our final steps to /init
|
||||||
@ -194,10 +201,14 @@ function populate_udev () {
|
|||||||
echo "Installing udev rules"
|
echo "Installing udev rules"
|
||||||
|
|
||||||
for _FLVR in ${RAMDISK_ELEMENT} ; do
|
for _FLVR in ${RAMDISK_ELEMENT} ; do
|
||||||
_DIR="${ELEMENTS_DIR}/${_FLVR}/udev"
|
for dir in $(echo $ELEMENTS_PATH | tr ":" " ") ; do
|
||||||
if [ -d $_DIR ]; then
|
[ -d $dir/$_FLVR ] || continue
|
||||||
find $_DIR -type f -exec cp -v {} $TMP_MOUNT_PATH/lib/udev/rules.d/ \;
|
_DIR="${dir}/${_FLVR}/udev"
|
||||||
fi
|
if [ -d $_DIR ]; then
|
||||||
|
find $_DIR -type f -exec cp -v {} $TMP_MOUNT_PATH/lib/udev/rules.d/ \;
|
||||||
|
fi
|
||||||
|
break
|
||||||
|
done
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user