Xcode - build phase or script for copying only modified files to App Bundle - xcode

Mac OS X 10.5 compatibility required. Xcode 3.2.5.
My app looks in the bundle's Resources folder, for a "data" folder.
"data" contains a hierarchy of subfolders and data. The contents are constantly being modified.
I don't need to navigate or modify this data within Xcode.
Q. When building, how can I copy "data" (say, from the Xcode project's folder) to the Resources folder, but only copying those files within "data" that have been modified since the last build?
(Simply copying all files every time I build is not feasible; the file sizes are too large, slowing build times.)
Thanks for any help.

Shouldn't be a problem to use rsync in a shell script build phase. Something like this:
rsync -a "${SRCROOT}/data" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}"
That does a bit more than date comparison but it should still be quite a bit faster than what you're doing now.
The above doesn't delete any files you removed from the source directory; to do so, you can add --delete but I'd only suggest doing that after you're sure it's working properly.

Related

Xcode: add files to project in a build phase

In my Xcode project I have a custom build phase which runs a script and downloads some images for use by the app. What I want to do is to automatically add those image to the project during the build. Right now, I have to build once (which downloads the files), and then manually add those files to the project. It works as long as the file names don't change. Instead, I'd like to add all the files in a specific directory to the project.
I've tried setting the Output Files value, as suggested here, like this:
$(PROJECT_DIR)/$(PROJECT_NAME)/External Assets/*
but it doesn't work. Any idea if this can be done?
Create a directory with the .bundle extension. Add this bundle to your app's resources. When the project builds, it will automatically copy every file in the bundle, even if they are changed or added after you first add the bundle to the project.

Minify JSON (or XML) in XCode build phase

I'm building an iOS app that frequently loads JSON configuration files at runtime.
However, the files are very generous with comments and indenting.
How can I tell XCode to copy minified versions of the files to the bundle during build?
You just need to add a build phase to your target. Here is an example, my build script that converts a multimarkdown file to an HTML file.
# Create the HTML file from the Markdown File
/usr/local/bin/multimarkdown --process-html --output="${SCRIPT_OUTPUT_FILE_0}" --to=html "${SCRIPT_INPUT_FILE_0}"
# Publish the Help Text and Image to Dropbox
if [ -d ~/Dropbox/Public/DCWS-Help-Text ]; then
rsync -t "${SRCROOT}/DC Wire Sizer/en.lproj/"* ~/Dropbox/Public/DCWS-Help-Text/
fi
I create the file in the source directory but added it to my git ignore file. It is a build product and not in source control, but you need to make sure it is in your project and part of the target, so it gets copied into the bundle. Also make sure your build script runs before your copy bundle phase.

Create archive without Xcode

I am building an Xcode project from console over ssh (I can use only xcodebuild command), but there are no schemes in the project (user forgot to make schemes shared). xcodebuild allows to pass "archive" parameter only if building scheme (-scheme), but that is not an option for me.
So the question is: is it possible to create archive using only target?
I investigated .xcarchive directory, it contains Info.plist file (which contains information about application), dSYMs directory (containing myapp.dSYM) and Products/Applications (containing myapp.app) directory. I also noted that the file size of binary in .xcarchive's .app is 2 times smaller than in .app that is in Release directory. I guess it is because of code signage.
Can I simply copy files from Release directory (.app and .dSYM) to .xcarchive and create Info.plist there to create archive? Or are there any other steps that I must take?
yes, archives are only folders you can make yourself.
look at ANY archive and try to replicate the folder structure. (changing the appname as required)

xcode4: reliably detect the DerivedData directory of a project/workspace

Xcode 4 builds everything into $HOME/Library/Developer/Xcode/DerivedData/$PROJECT-$UUID, where $UUID is a seemingly random string (it's not really random, it just looks random).
How can I reliably detect the $PROJECT-$UUID part of the above? I've seen a script (https://gist.github.com/949831) that guesses by assuming it is the last modified directory in DerivedData -- but that's not true if my CI machine is building a few projects in parallel.
Nobody answered, so I kept looking for ideas until I found the one below, which satisfies my needs. It can be further modified to be even safer.
In Xcode, add a run-script build phase to the target (the main target, if building a few for the same project).
In the script, put this line:
ln -sf "$BUILD_DIR" BuildDir
Now, when the target is built a symlink to the project's DerivedData directory will be created in the project directory.
If desirable, you can also/instead create BuildDir as a file who's content is the $BUILD_DIR:
echo "$BUILD_DIR" > BuildDir
Then in a script use $(cat BuildDir) to retrieve it.

How to bundle an openframeworks application in xcode (relative resource linking?)

An trying to get openframeworks to build me my application so that i can open it from anywhere and it will load the needed images from within the apps Resources folder.
I believe this is relative linking?
I have done it before, on an older xcode and oF 61.
To do this i dragged the needed images into the project file on the left and added it to the executable target, with in a 'build phase' -> 'copy files'.
Been trying all sorts of methods, ofSetDataPathRoot() which solved the problem last time isnt working for me this time.
Any ideas/help would be appreciated!
Thanks
First you need to tell xCode to copy your /bin/data directory into your application bundle by adding a build phase:
1. Click on your project in the Project Navigator
2. Select "Build Phases"
3. Toggle open the "Run Script" section and paste in the following:
cp -r bin/data "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Resources";
Then tell your app where to find the data folder relative to itself within the bundle.
Inside the setup method of your oF app:
ofSetDataPathRoot("../Resources/data/");
ofSetDataPathRoot() should solve this problem. Perhaps you are setting the replacement root path incorrectly?
Try calling ofToDataPath() yourself on a string path and print out the result, then use Terminal and cd inside the .app bundle to check if the path sounds correct. Paths are expressed relative to the location of the actual executable inside the .app bundle, so if the executable is at myApp.app/Contents/MacOS/myApp and the data files are at myApp.app/Contents/Resources then ofToDataPath( "texture.png" ) should return something like ../Resources/texture.png.
You can double-check the current working directory (myApp.app/Contents/MacOS in my example) by calling getcwd(), open up a terminal and type man getcwd for more info on that.
oF now sets data path root and does internal calls to ofToDataPath() by default. What version are you using?
Have you looked inside the product's package contents to make sure your resources are getting copies in the proper build phase?

Resources