21

I want integrate CPD (Copy-Paste-Detection) to my iOS project. I read about it here and here.

To automatically determine CopyPaste in the code I'm using bash script:

echo "Checking files in ${SOURCE_ROOT}"
JARS_DIR=${PROJECT_DIR}/CPD
FULL_PATH_TO_CPD_XML_OUTPUT=${PROJECT_DIR}/cpd-output.xml

# Running CPD
java -classpath "${JARS_DIR}/ObjCLanguage-0.0.5-SNAPSHOT.jar:${JARS_DIR}/pmd.jar" net.sourceforge.pmd.cpd.CPD --minimum-tokens 100 --files "${SOURCE_ROOT}" -v --language ObjectiveC --encoding UTF-8 --format net.sourceforge.pmd.cpd.XMLRenderer > "${FULL_PATH_TO_CPD_XML_OUTPUT}"

# Running self :)
${BUILT_PRODUCTS_DIR} -cpd-xml "${FULL_PATH_TO_CPD_XML_OUTPUT}"

That code create cpd-output.xml file. But take me an error at compile time "Command /bin/sh failed with exit code 126". Here is log copy http://pastebin.com/359k1Wni I took the code from this example project Error is going then I comment this string:

${BUILT_PRODUCTS_DIR} -cpd-xml "${FULL_PATH_TO_CPD_XML_OUTPUT}"

I tried to find what ever information about this error, but found only a few of these problems without answers. I'm not know anything about bash scripting. I will be happy with any advice. Thank you for your attention.

P.S. Author of following the script written:

In order to integrate XCode and the CPD, we will add to the Build Phases target with the project, Run Script phase, conventionally consisting of several parts: Actually calling cpd Parsing cpd-output.xml Output in the "right format"

alexmorhun
  • 1,903
  • 2
  • 18
  • 23

4 Answers4

18

The error may also be caused due to inadequate "Permissions" to run the Shell. I got:- bash: /home/XXX.sh: Permission denied exit-status: 126
On fixing the permissions on shell script, the issue got fixed.

Vibha
  • 939
  • 9
  • 17
17

126 for “command not executable"

# Running self :)
${BUILT_PRODUCTS_DIR} -cpd-xml "${FULL_PATH_TO_CPD_XML_OUTPUT}"

It looks like $BUILT_PRODUCTS_DIR} is not executable Can you update with the value of this var please

Chris
  • 4,425
  • 5
  • 34
  • 49
  • Unfortunately, I'm not know anything about bash scripting. I added the words of the author of this script. – alexmorhun Apr 02 '12 at 15:40
  • Essentially your application does not have permission from the bash shell to run $BUILT_PRODUCTS_DIR}. How to do that will depend on the code you copied from the project. I will try to take a look at it, but I don't know Objective C (assuming thats what its in). I will update if i figure it out. – Chris Apr 02 '12 at 16:17
4

Like the error message in the pastebin says, the value of ${BUILT_PRODUCTS_DIR} is a directory (line 314). It doesn't make any sense to attempt to execute a directory, so it appears that the build script is broken or corrupted.

By the by, are the setenv commands part of the script as well? This is typically a csh command, not a sh or bash command. Executing a directory doesn't make sense under tcsh either, though, as far as I am aware.

tripleee
  • 175,061
  • 34
  • 275
  • 318
1

The problem was in the wrong script. I give a revised script, which logs have been added:

echo "Checking files in ${SOURCE_ROOT}"
CPD_DIR=${PROJECT_DIR}/CPD
JARS_DIR=${PROJECT_DIR}/CPD
FULL_PATH_TO_CPD_XML_OUTPUT=${PROJECT_DIR}/cpd-output.xml
OBJC_JAR_LIBRARY=${JARS_DIR}/ObjCLanguage-0.0.5-SNAPSHOT.jar

echo [DEBUG] CPD_DIR = ${CPD_DIR}
echo [DEBUG] JARS_DIR = ${JARS_DIR}
echo [DEBUG] FULL_PATH_TO_CPD_XML_OUTPUT = ${FULL_PATH_TO_CPD_XML_OUTPUT}
echo [DEBUG] OBJC_JAR_LIBRARY = ${OBJC_JAR_LIBRARY}
echo [DEBUG] SOURCE_ROOT = ${SOURCE_ROOT}

# Running CPD
java -classpath "${OBJC_JAR_LIBRARY}:${JARS_DIR}/pmd.jar" net.sourceforge.pmd.cpd.CPD --minimum-tokens 200 --files "${SOURCE_ROOT}" -v --language ObjectiveC --encoding UTF-8 --format net.sourceforge.pmd.cpd.XMLRenderer > "${FULL_PATH_TO_CPD_XML_OUTPUT}"

CPD_EXECUTABLE="${CPD_DIR}/CPDObjective-C"
if [ ! -f "${CPD_EXECUTABLE}" ];
then
echo "CPD executable file is not found: " ${CPD_EXECUTABLE}
fi
echo "Running ${CPD_EXECUTABLE} -cpd-xml ${FULL_PATH_TO_CPD_XML_OUTPUT}"
"${CPD_EXECUTABLE}" -cpd-xml "${FULL_PATH_TO_CPD_XML_OUTPUT}"

Here is source code of sample Copy-Paste-Detect

alexmorhun
  • 1,903
  • 2
  • 18
  • 23
  • 1
    If you have any files named `D` or `E` or `B` or `U` or `G`, the unquoted `[DEBUG]` will be interpreted as a wildcard and expanded into a list of those files (also depending on some shell options), The obvious fix is to quote your strings. See also https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable/27701642 – tripleee Oct 23 '19 at 05:17