28

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"

5 Answers 5

26

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I ran into this issue while trying to build for Docker. Thanks for your fix.
chmod +x foo.sh to allow execution
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

2 Comments

Unfortunately, I'm not know anything about bash scripting. I added the words of the author of this script.
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.
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.

Comments

2

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

1 Comment

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 stackoverflow.com/questions/10067266/…
1

This is now years later, but the answer is found in the bash man page in the EXIT STATUS section:

If a command is not found, the child process created to execute it returns a status of 127. If a command is found but is not executable, the return status is 126.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.