XCTOTD: But I don't WANT you to process those files
(XCTOTD == Xcode Tip of the Day, BTW).
Recently I found that the quickest way to get something working in a project was to borrow some HTML. I could have done it all in Cocoa, but someone had already created an HTML form for what I needed to do. Pressed for time, I decided to take this HTML, drop it into a web view, and be done with it. The purpose of this part of the app was to collect information to send to a web server anyway, so why not let an HTML form do what HTML forms do best?
Maybe because the HTML was not designed with this use in mind, and would look like crap? But that's not hard to fix, given that I have Dashcode just sitting there trying to look useful. It was quick work to set up a Dashcode project, drop the HTML form into it, make it all look nice, and then export it into something I could use in my application.
Dashcode, of course, exports a bunch of stuff, not just HTML but also miscellaneous Javascript files and images, all in a folder. Not a problem. I added the folder to my project in Xcode, as an application resource. Then I added a copy files build stage to make sure the new files stayed in their own folder in the compiled app. Compile the app, and... OK, now we have a problem.
Five new compile warnings. That's pretty impressive given that I hadn't actually edited any of the source code in any way. I didn't think I had added any, but Xcode believed otherwise:
warning: no rule to process file
'$(PROJECT_DIR)/signup-1/iphone-carriers.js' of type
sourcecode.javascript for architecture i386
warning: no rule to process file
'$(PROJECT_DIR)/signup-1/main.js' of type
sourcecode.javascript for architecture i386
warning: no rule to process file
'$(PROJECT_DIR)/signup-1/Parts/setup.js' of type
sourcecode.javascript for architecture i386
warning: no rule to process file
'$(PROJECT_DIR)/signup-1/Parts/Text.js' of type
sourcecode.javascript for architecture i386
warning: no rule to process file
'$(PROJECT_DIR)/signup-1/Parts/utilities.js' of type
sourcecode.javascript for architecture i386
Um, what? On the one hand I'm not all that surprised that Xcode doesn't have a build rule for Javascript files. On the other hand, I don't want it to process them, I just want it to copy them to the right place and move on. As far as I'm concerned, it's good that there's no rule to process these files, but why is it even trying?
Google, usually quite helpful in these situations, wasn't giving me much to go on. I was especially puzzled by the fact that these warnings showed up in Xcode's "checking dependencies" step. Why would there be any dependencies on these files?
I conducted what I thought was an extensive search through project settings and found nothing useful. I briefly considered creating a do-nothing build rule for Javascript files just to shut Xcode up, but held back for the moment on the grounds that it seemed like the stupid solution.
Finally I closed Xcode and looked at the project file in a text editor. Xcode projects are really file bundles, and the hidden file named project.pbxproj is where all the project info goes. Now things got interesting. In the file list, each of the Javascript files appeared twice-- once in "CopyFiles" and once in "Sources". Xcode had added the Javascript files as source code, but then found it didn't actually know what to do with them at compile time. Seeking a quick fix I edited the file (don't try this at home kiddies, this man is a trained professional driving on a closed track) to delete all reference to Javascript files as source code. I reopened the project in Xcode, compiled, and the errors were gone.
That got me going again, but it bugged me. Was that really necessary? It turns out not. Repeating the steps on a test project, I found that I could have fixed it all in Xcode. When I added the files to the project, Xcode had helpfully added the Javascript files to the "compile sources" stage of the build process. Except, as it soon complained, it couldn't handle this addition at compile time. Deleting the Javascript from this build stage fixed the warning message.
Anyway, I'm off to file a bug. Xcode shouldn't add files as source code unless it knows how to process them. Either don't put them in that stage or put them in but know what to do with them (even if it's "do nothing").
Submitted by Tom Harrington on Tue, 07/08/2008 - 11:03.





