The best way to find any number of files in my xcode project (and do some processing) is to write a little php script. The script can simply copy the files to the bundle. The hard part is integrating with xcode. It took me a while to find a clean path. (You can use a script language that you like using this method).
First use "Add Script Run" instead of "Add Copy File"
Shell parameter:
/bin/sh
Command Parameter:
${SRCROOT}/your_script.php -s ${SRCROOT} -o ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH} exit $?
(screenshot in xcode)
$ {SRCROOT} is your project directory.
$ {CONFIGURATION (...) is the package directory. Exactly what you need :)
That way, your script return code can stop the xcode assembly (use die (0) for success and die (1) for crashes), and the script output will appear in the xcode build log.
Your script will look like this: (don't forget chmod + x on it)
#!/usr/bin/php <?php error_reporting(E_ALL); $options = getopt("s:o:"); $src_dir = $options["s"]."/"; $output_dir = $options["o"]."/";
BONUS : here is my add_file function.
- Pay attention to the special PNG handling (use apple png compression).
- Note the use of file / time to prevent copying copy files every time.
l
define("COPY_PNG", "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/copypng -compress"); function add_file_to_bundle($output_dir, $filepath) { // split path $path_info = pathinfo($filepath); $output_filepath = $output_dir.$path_info['basename']; // get file dates of input and output $input_date = filemtime($filepath); $output_date = @filemtime($output_filepath); if ($input_date === FALSE) { echo "can't get input file modification date"; die(1); } // skip unchanged files if ($output_date === $input_date) { //message("skip ".$path_info['basename']); return 0; } // special copy for png with apple png compression tool if (strcasecmp($path_info['extension'], "png") == 0) { //message($path_info['basename']." is a png"); passthru(COPY_PNG." ".escapeshellarg($filepath)." ".escapeshellarg($output_filepath), $return_var); if ($return_var != 0) die($return_var); } // classic copy else { //message("copy ".$path_info['basename']); passthru("cp ".escapeshellarg($filepath)." ".escapeshellarg($output_filepath), $return_var); if ($return_var != 0) die($return_var); } // important: set output file date with input file date touch($output_filepath, $input_date, $input_date); return 1; }
Vivien
source share