Skip to content

Commit

Permalink
Replace SNAP envvars with the 16.04 ones.
Browse files Browse the repository at this point in the history
LP: #1533552
  • Loading branch information
sergiusens committed Jan 15, 2016
1 parent fe9ca74 commit 04b1a13
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 39 deletions.
2 changes: 1 addition & 1 deletion docs/your-first-snap.md
Expand Up @@ -160,7 +160,7 @@ We'll write a tiny little script that runs the server and `fswebcam` together:
#!/bin/sh
set -e

cd "$SNAP_APP_DATA_PATH"
cd "$SNAP_DATA"

golang-static-http &

Expand Down
10 changes: 5 additions & 5 deletions examples/gopaste/gopaste
Expand Up @@ -2,9 +2,9 @@

set -x

cd $SNAP_APP_DATA_PATH
cp $SNAP_APP_PATH/web.template .
cp -r $SNAP_APP_PATH/static .
export HOME=$SNAP_APP_DATA_PATH
cd $SNAP_DATA
cp $SNAP/web.template .
cp -r $SNAP/static .
export HOME=$SNAP_DATA

exec $SNAP_APP_PATH/bin/gopasted -port 8080 -external-host snappy
exec $SNAP/bin/gopasted -port 8080 -external-host snappy
2 changes: 1 addition & 1 deletion examples/shout/snapcraft.yaml
Expand Up @@ -6,7 +6,7 @@ icon: icon.png

apps:
server:
command: bin/shout --home $SNAP_APP_DATA_PATH
command: bin/shout --home $SNAP_DATA
daemon: simple

parts:
Expand Down
5 changes: 2 additions & 3 deletions examples/tomcat-maven-webapp/wrapper
Expand Up @@ -4,9 +4,9 @@ set -e
set -x

# installation pathes are based of CATALINA_HOME
export CATALINA_HOME="$SNAP_APP_PATH"
export CATALINA_HOME="$SNAP"
# writable pathes are based of CATALINA_BASE
export CATALINA_BASE="$SNAP_APP_DATA_PATH"
export CATALINA_BASE="$SNAP_DATA"

# create runtime data
mkdir -p "$CATALINA_BASE/logs"
Expand All @@ -20,4 +20,3 @@ if ! [ -d $CATALINA_BASE/webapps ]; then
fi

$CATALINA_HOME/bin/catalina.sh run

2 changes: 1 addition & 1 deletion examples/webcam-webui/config.py
Expand Up @@ -11,7 +11,7 @@


def main():
config_file = os.path.join(os.environ['SNAP_APP_DATA_PATH'], _CONFIG)
config_file = os.path.join(os.environ['SNAP_DATA'], _CONFIG)

config_yaml = yaml.load(sys.stdin)
if config_yaml:
Expand Down
2 changes: 1 addition & 1 deletion examples/webcam-webui/webcam-webui
@@ -1,7 +1,7 @@
#!/bin/sh
set -e

cd "$SNAP_APP_DATA_PATH"
cd "$SNAP_DATA"

[ -f configuration ] && interval=$(sed -n 's/.*interval: `\([0-9.]\+\).*/\1/p' configuration)

Expand Down
6 changes: 3 additions & 3 deletions integration_tests/snaps/assemble/binary1.after
@@ -1,5 +1,5 @@
#!/bin/sh
export PATH="$SNAP_APP_PATH/bin:$SNAP_APP_PATH/usr/bin:$PATH"
export LD_LIBRARY_PATH="$SNAP_APP_PATH/lib:$SNAP_APP_PATH/usr/lib:$SNAP_APP_PATH/lib/@MULTIARCH@:$SNAP_APP_PATH/usr/lib/@MULTIARCH@:$LD_LIBRARY_PATH"
export PATH="$SNAP/bin:$SNAP/usr/bin:$PATH"
export LD_LIBRARY_PATH="$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/@MULTIARCH@:$SNAP/usr/lib/@MULTIARCH@:$LD_LIBRARY_PATH"

exec "$SNAP_APP_PATH/binary1" $*
exec "$SNAP/binary1" $*
2 changes: 1 addition & 1 deletion integration_tests/snaps/pypi-config/config.py
Expand Up @@ -11,7 +11,7 @@


def main():
config_file = os.path.join(os.environ['SNAP_APP_DATA_PATH'], _CONFIG)
config_file = os.path.join(os.environ['SNAP_DATA'], _CONFIG)

config_yaml = yaml.load(sys.stdin)
if config_yaml:
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/test_python_plugin.py
Expand Up @@ -45,8 +45,8 @@ def test_snap_with_pypi_config(self):
FileExists())

expected_config = (
'exec "$SNAP_APP_PATH/usr/bin/python3" '
'"$SNAP_APP_PATH/usr/bin/config.py" $*\n')
'exec "$SNAP/usr/bin/python3" '
'"$SNAP/usr/bin/config.py" $*\n')
with open(os.path.join(
project_dir, 'snap', 'meta', 'hooks', 'config')) as config:
config_contents = config.read()
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_snap.py
Expand Up @@ -62,7 +62,7 @@ def test_snap(self):

self.useFixture(
fixtures.EnvironmentVariable(
'SNAP_APP_PATH', os.path.join(os.getcwd(), 'snap')))
'SNAP', os.path.join(os.getcwd(), 'snap')))
binary_scenarios = (
('command-assemble-service.wrapper', 'service-start\n'),
('stop-command-assemble-service.wrapper', 'service-stop\n'),
Expand Down
11 changes: 5 additions & 6 deletions snapcraft/meta.py
Expand Up @@ -157,18 +157,17 @@ def _write_wrap_exe(wrapexec, wrappath, shebang=None, args=None, cwd=None):
cwd = 'cd {}'.format(cwd) if cwd else ''

snap_dir = common.get_snapdir()
assembled_env = common.assemble_env().replace(snap_dir, '$SNAP_APP_PATH')
assembled_env = common.assemble_env().replace(snap_dir, '$SNAP')
replace_path = r'{}/[a-z0-9][a-z0-9+-]*/install'.format(
common.get_partsdir())
assembled_env = re.sub(replace_path, '$SNAP_APP_PATH', assembled_env)
assembled_env = re.sub(replace_path, '$SNAP', assembled_env)
executable = '"{}"'.format(wrapexec)
if shebang is not None:
new_shebang = re.sub(replace_path, '$SNAP_APP_PATH', shebang)
new_shebang = re.sub(replace_path, '$SNAP', shebang)
if new_shebang != shebang:
# If the shebang was pointing to and executable within the
# local 'parts' dir, have the wrapper script execute it
# directly, since we can't use $SNAP_APP_PATH in the shebang
# itself.
# directly, since we can't use $SNAP in the shebang itself.
executable = '"{}" "{}"'.format(new_shebang, wrapexec)
script = ('#!/bin/sh\n' +
'{}\n'.format(assembled_env) +
Expand All @@ -194,7 +193,7 @@ def _wrap_exe(command, basename=None):
if os.path.exists(wrappath):
os.remove(wrappath)

wrapexec = '$SNAP_APP_PATH/{}'.format(execparts[0])
wrapexec = '$SNAP/{}'.format(execparts[0])
if not os.path.exists(exepath) and '/' not in execparts[0]:
# If it doesn't exist it might be in the path
logger.debug('Checking to see if {!r} is in the $PATH'.format(
Expand Down
2 changes: 1 addition & 1 deletion snapcraft/plugins/catkin.py
Expand Up @@ -121,7 +121,7 @@ def env(self, root):

# Various ROS tools (e.g. rospack, roscore) keep a cache or a log,
# and use $ROS_HOME to determine where to put them.
'ROS_HOME=$SNAP_APP_USER_DATA_PATH/ros',
'ROS_HOME=$SNAP_USER_DATA/ros',

# This environment variable points to where the setup.sh and
# _setup_util.py files are located. This is required at both build-
Expand Down
2 changes: 1 addition & 1 deletion snapcraft/plugins/roscore.py
Expand Up @@ -51,7 +51,7 @@ def __init__(self, name, options):
def build(self):
os.makedirs(os.path.join(self.installdir, 'bin'), exist_ok=True)
ros_dir = os.path.join(
'$SNAP_APP_PATH',
'$SNAP',
'opt',
'ros',
self.options.rosdistro)
Expand Down
22 changes: 11 additions & 11 deletions snapcraft/tests/test_meta.py
Expand Up @@ -128,7 +128,7 @@ def test_create_meta_with_config_with_args(self):

expected_wrapper = [
'#!/bin/sh\n', '\n', '\n',
'exec "$SNAP_APP_PATH/config.sh" something $*\n']
'exec "$SNAP/config.sh" something $*\n']
self.assertEqual(config_wrapper, expected_wrapper)

def test_create_meta_with_app_with_security_policy(self):
Expand Down Expand Up @@ -200,9 +200,9 @@ def test_wrap_exe_must_write_wrapper(self, mock_assemble_env):
wrapper_path = os.path.join(snapdir, relative_wrapper_path)

expected = ('#!/bin/sh\n'
'PATH=$SNAP_APP_PATH/usr/bin:$SNAP_APP_PATH/bin\n'
'PATH=$SNAP/usr/bin:$SNAP/bin\n'
'\n\n'
'exec "$SNAP_APP_PATH/test_relexepath" $*\n')
'exec "$SNAP/test_relexepath" $*\n')
with open(wrapper_path) as wrapper_file:
wrapper_contents = wrapper_file.read()

Expand All @@ -227,9 +227,9 @@ def test_wrap_exe_writes_wrapper_with_basename(self, mock_assemble_env):
self.assertEqual(relative_wrapper_path, 'new-name.wrapper')

expected = ('#!/bin/sh\n'
'PATH=$SNAP_APP_PATH/usr/bin:$SNAP_APP_PATH/bin\n'
'PATH=$SNAP/usr/bin:$SNAP/bin\n'
'\n\n'
'exec "$SNAP_APP_PATH/test_relexepath" $*\n')
'exec "$SNAP/test_relexepath" $*\n')
with open(wrapper_path) as wrapper_file:
wrapper_contents = wrapper_file.read()

Expand All @@ -244,8 +244,8 @@ def test_snap_shebangs_extracted(self):
The shebang needs to be an absolute path, and we don't know
in which directory the snap will be installed. Executing
it in the wrapper script allows us to use the $SNAP_APP_PATH
environment variable.
it in the wrapper script allows us to use the $SNAP environment
variable.
"""
snapdir = common.get_snapdir()
partsdir = common.get_partsdir()
Expand All @@ -264,8 +264,8 @@ def test_snap_shebangs_extracted(self):
expected = (
'#!/bin/sh\n'
'\n\n'
'exec "$SNAP_APP_PATH/snap_exe"'
' "$SNAP_APP_PATH/test_relexepath" $*\n')
'exec "$SNAP/snap_exe"'
' "$SNAP/test_relexepath" $*\n')
with open(wrapper_path) as wrapper_file:
wrapper_contents = wrapper_file.read()

Expand Down Expand Up @@ -294,7 +294,7 @@ def test_non_snap_shebangs_ignored(self):

expected = ('#!/bin/sh\n'
'\n\n'
'exec "$SNAP_APP_PATH/test_relexepath" $*\n')
'exec "$SNAP/test_relexepath" $*\n')
with open(wrapper_path) as wrapper_file:
wrapper_contents = wrapper_file.read()

Expand Down Expand Up @@ -323,7 +323,7 @@ def test_non_shebang_binaries_ignored(self):

expected = ('#!/bin/sh\n'
'\n\n'
'exec "$SNAP_APP_PATH/test_relexepath" $*\n')
'exec "$SNAP/test_relexepath" $*\n')
with open(wrapper_path) as wrapper_file:
wrapper_contents = wrapper_file.read()

Expand Down
2 changes: 1 addition & 1 deletion snapcraft/tests/test_plugin_catkin.py
Expand Up @@ -533,7 +533,7 @@ def test_run_environment(self, run_mock):

self.assertTrue('ROS_MASTER_URI=http://localhost:11311' in environment)

self.assertTrue('ROS_HOME=$SNAP_APP_USER_DATA_PATH/ros' in environment)
self.assertTrue('ROS_HOME=$SNAP_USER_DATA/ros' in environment)

self.assertTrue('_CATKIN_SETUP_DIR={}'.format(os.path.join(
'/foo', 'opt', 'ros', self.properties.rosdistro)) in environment)
Expand Down

0 comments on commit 04b1a13

Please sign in to comment.