0

I am zipping the .xctest file from Plugins folder inside the .app target generated by building my app. I have a build phase script that runs last in my test target to copy this file over. I use the following script to do the zipping:

XCTEST_FILE=${TARGET_BUILD_DIR}/${TARGET_NAME}.xctest
XCTEST_ZIP=${TARGET_BUILD_DIR}/../../${TARGET_NAME}.xctest.zip
zip -jr ${XCTEST_ZIP} ${XCTEST_FILE}

This gives me TestTarget.xctest.zip file. But it unzips differently based on these 2 methods,

unzip TestTarget.xctest.zip

-TestTarget
-CodeResources
-Info.plist

Double clicking TestTarget.xctest.zip in finder

-TestTarget.xctest
--TestTarget
--CodeResources
--Info.plist

Why is unzip going to the innermost node and extracting all the files? I want the unzip command to give me the .xctest directory. I tried renaming the zip file to TestTarget.zip and it still behaves similarly.

I was initially zipping using zip -r ${XCTEST_ZIP} ${XCTEST_FILE}, but the problem with this was it would retain the entire folder structure from root (\) when I double clicked to unzip the file. A post recommend using the -j flag instead of -r. But just -j led to no zip file being generated. Another comment recommend -jr which created a zip that generated output I expected when double clicking it. But I guess the unzip command does stuff differently.

Similar Question: MacOs zip file - different result when double click and running unzip command

The cause for error here was very different,

The problem was when the file was created. It was not related to MacOs issue but with certain path length known issue in windows

Parth
  • 2,682
  • 1
  • 20
  • 39

1 Answers1

0

Based on How to zip folder without full path, I had to update my script to first cd into the TARGET_BUILD_DIR before generating the zip. I also had to remove the -j flag so the local folder structure was retained on running unzip.

cd ${TARGET_BUILD_DIR}
XCTEST_FILE=./${TARGET_NAME}.xctest
XCTEST_ZIP=../../${TARGET_NAME}.xctest.zip
zip -r ${XCTEST_ZIP} ${XCTEST_FILE}
Parth
  • 2,682
  • 1
  • 20
  • 39