Skip to content

Commit

Permalink
apacheGH-540: Fix copy-www-build-step without shelljs
Browse files Browse the repository at this point in the history
There didn't seem to be a compelling reason to keep this as JavaScript
since it was primarily just shelling out to run various commands. By
keeping it in bash, we can significantly simplify the invocation in the
xcodeproj file and we can run it without a dependency on shelljs.

I also moved it into a Scripts folder inside the project so that our
xcodeproj file isn't reliant on the cordova/lib folder existing, and
this particular script isn't actually a "lib" in the standard sense.
  • Loading branch information
dpogue committed Apr 16, 2019
1 parent 44899e2 commit 83c2408
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 77 deletions.
6 changes: 0 additions & 6 deletions bin/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,6 @@ function update_cordova_subproject (argv) {
}
}

// Patching pbxproj to replace copy www shell script with nodejs
// Don't forget to duplicate this in templates/__CLI__.xcodeproj/project.pbxproj and templates/__NON-CLI__.xcodeproj/project.pbxproj on later changes
var copyWwwSh = 'cordova\/lib\/copy-www-build-step\.sh'; /* eslint no-useless-escape : 0 */
var copyWwwJs = 'NODEJS_PATH=\/usr\/local\/bin; NVM_NODE_PATH=~\/\.nvm\/versions\/node\/`nvm version 2>\/dev\/null`\/bin; N_NODE_PATH=`find \/usr\/local\/n\/versions\/node\/\* -maxdepth 0 -type d 2>\/dev\/null \| tail -1`\/bin; XCODE_NODE_PATH=`xcode-select --print-path`\/usr\/share\/xcs\/Node\/bin; PATH=\$NODEJS_PATH:\$NVM_NODE_PATH:\$N_NODE_PATH:\$XCODE_NODE_PATH:\$PATH && node cordova\/lib\/copy-www-build-step\.js'; /* eslint no-useless-escape : 0 */
shell.sed('-i', copyWwwSh, copyWwwJs, path.join(projectPath, 'project.pbxproj'));

if (!found) {
throw new Error('Entry not found in project file for sub-project: ' + subprojectPath);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/sh
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
#
# This script copies the www directory into the Xcode project.
#
# This script should not be called directly.
# It is called as a build step from Xcode.

SRC_DIR="www"
DST_DIR="$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME"
DST_DIR_WWW="$DST_DIR/www"
COPY_HIDDEN=
ORIG_IFS=$IFS
IFS=$(echo -en "\n\b")

if [[ -z "$BUILT_PRODUCTS_DIR" ]]; then
echo "The script is meant to be run as an Xcode build step and relies on env variables set by Xcode."
exit 1
fi

if [[ ! -e "$SRC_DIR" ]]; then
echo "error: Path does not exist: $SRC_DIR"
exit 2
fi

rm -rf "$DST_DIR_WWW"

# Copy www dir recursively
CODE=
if [[ -n $COPY_HIDDEN ]]; then
rsync -Lra "$SRC_DIR" "$DST_DIR"
CODE=$?
else
rsync -Lra --exclude="- .*" "$SRC_DIR" "$DST_DIR"
CODE=$?
fi

if [ $CODE -ne 0 ]; then
echo "error: Error occurred on copying www. Code $CODE"
exit 3
fi

# Copy the config.xml file.
cp -f "${PROJECT_FILE_PATH%.xcodeproj}/config.xml" "$DST_DIR"

IFS=$ORIG_IFS
2 changes: 1 addition & 1 deletion bin/templates/project/__TEMP__.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "NODEJS_PATH=/usr/local/bin; NVM_NODE_PATH=~/.nvm/versions/node/`nvm version 2>/dev/null`/bin; N_NODE_PATH=`find /usr/local/n/versions/node/* -maxdepth 0 -type d 2>/dev/null | tail -1`/bin; XCODE_NODE_PATH=`xcode-select --print-path`/usr/share/xcs/Node/bin; PATH=$NODEJS_PATH:$NVM_NODE_PATH:$N_NODE_PATH:$XCODE_NODE_PATH:$PATH && node cordova/lib/copy-www-build-step.js";
shellScript = "\"$SRCROOT/__PROJECT_NAME__/Scripts/copy-www-build-step.sh\"";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
Expand Down
68 changes: 0 additions & 68 deletions bin/templates/scripts/cordova/lib/copy-www-build-step.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "NODEJS_PATH=/usr/local/bin; NVM_NODE_PATH=~/.nvm/versions/node/`nvm version 2>/dev/null`/bin; N_NODE_PATH=`find /usr/local/n/versions/node/* -maxdepth 0 -type d 2>/dev/null | tail -1`/bin; XCODE_NODE_PATH=`xcode-select --print-path`/usr/share/xcs/Node/bin; PATH=$NODEJS_PATH:$NVM_NODE_PATH:$N_NODE_PATH:$XCODE_NODE_PATH:$PATH && node cordova/lib/copy-www-build-step.js";
shellScript = "\"$SRCROOT/ChildApp/Scripts/copy-www-build-step.sh\"";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "NODEJS_PATH=/usr/local/bin; NVM_NODE_PATH=~/.nvm/versions/node/`nvm version 2>/dev/null`/bin; N_NODE_PATH=`find /usr/local/n/versions/node/* -maxdepth 0 -type d 2>/dev/null | tail -1`/bin; XCODE_NODE_PATH=`xcode-select --print-path`/usr/share/xcs/Node/bin; PATH=$NODEJS_PATH:$NVM_NODE_PATH:$N_NODE_PATH:$XCODE_NODE_PATH:$PATH && node cordova/lib/copy-www-build-step.js";
shellScript = "\"$SRCROOT/SampleApp/Scripts/copy-www-build-step.sh\"";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/sh
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
#
# This script copies the www directory into the Xcode project.
#
# This script should not be called directly.
# It is called as a build step from Xcode.

SRC_DIR="www"
DST_DIR="$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME"
DST_DIR_WWW="$DST_DIR/www"
COPY_HIDDEN=
ORIG_IFS=$IFS
IFS=$(echo -en "\n\b")

if [[ -z "$BUILT_PRODUCTS_DIR" ]]; then
echo "The script is meant to be run as an Xcode build step and relies on env variables set by Xcode."
exit 1
fi

if [[ ! -e "$SRC_DIR" ]]; then
echo "error: Path does not exist: $SRC_DIR"
exit 2
fi

rm -rf "$DST_DIR_WWW"

# Copy www dir recursively
CODE=
if [[ -n $COPY_HIDDEN ]]; then
rsync -Lra "$SRC_DIR" "$DST_DIR"
CODE=$?
else
rsync -Lra --exclude="- .*" "$SRC_DIR" "$DST_DIR"
CODE=$?
fi

if [ $CODE -ne 0 ]; then
echo "error: Error occurred on copying www. Code $CODE"
exit 3
fi

# Copy the config.xml file.
cp -f "${PROJECT_FILE_PATH%.xcodeproj}/config.xml" "$DST_DIR"

IFS=$ORIG_IFS

0 comments on commit 83c2408

Please sign in to comment.