WWDC2004 Session 309
Transcript
Kind: captions Language: en please welcome Xcode lead engineer on ders Bertil rude hi I'm and Ursula dice code lead engineer as you heard on previous session we saw a couple of ways of increasing the productivity of Xcode clicker works yet we saw how to increase productivity one when navigating your project in particular with the detail is finding the right files the files by name and by content that kind of thing we saw editing how to get productive with that sauce some source code management how to use documentation workflows I kind of thing so this session would i'd like to do is to dive down a little bit on the build system and we can take a look at some of the ways specifically have increasing productivity when building your projects in xcode so let's take the hood off so we're going to cover is we're going to start with talking about the xcode project model just brief summary we've talked about a lot of concepts in all these sessions like targets and files and build phases by kind of stuff but sometimes it can be a little bit tricky to keep it all straight so i just want to give real basic and talk about some of the concepts real quickly and then we're going to talk about optimizing to build performance some of the things you can do to speed up the things that your projects already doing so the kinds of builds that you already doing on your projects then we're going to talk a little bit about how to automate some of the common tasks then maybe things you are doing using finder or the command line that we can actually set up to be done automatically maybe even at night using an automatic script to run so you don't even have to worry about it so we'll talk about this we'll start with the project model so Xcode works on projects right so a project what is a project well project is basically a container it contains references and files so these are files and folders on your disk and it doesn't actually contain the files themselves right the files just live in two is you can access them using the terminal or finder we just have references to the file the project also has targets and these are the blueprints for the conceptual products that you want to build so your application your library your plug-in that kind of thing there are associations between these file reference can belong to a target and as just as there can be multiple targets a file can be part of one or more targets in particular we see here this single file reference is actually part of more than one target so this could be the case if you had some shared common code let's say you're doing a client server maybe there's a header file that they both use to get access to things like default port numbers stuff like that you also notice that we can have file references that are not actually part of any target at all and well what are these useful for well you know maybe you want to have a to-do list or you have read me or something like that some people actually use xcode to manage the recipe collection and admittedly most of you actually have projects that build products so for use this would probably be a to-do list or something like that so another thing that we have in a project is dependencies between targets and this is fairly logical right if you have a library in an application you want to make sure the library is up to date before you try to build the app fairly simple we also have build styles and we'll get to those little bit more later but they're actually a separate entities in a project that's get applied to a target dynamically when you build we'll talk about that in more detail there's another case which related to a question that we had just recently from the previous session you can actually have one project refers to another so in this case we still have the first project as file references targets as usual files belong to the targets nothing special there the second one is files targets files belong to target and there's the dependencies between the targets within a project but there's something more we can do we can actually add a project reference to the first project in which case we have a link to the other project so now the first project that one of the lot actually knows about the project on the right and therefore we can set up dependencies between the targets between the different projects so this can be very useful we still of course have the build styles and they can actually apply to builds of the targets in the secondary project will go into that a little bit more so we talked about targets well what are these targets that we talked about application and library and those kinds of things those are really product types the types of things you want to build the party types more refer to build systems so we we have this dependency layer that goes between the targets those are the red dashed arrows you saw on the previous diagram so you can have your application your library etc but each target can have its own build system and so we'll see how this can be useful the first kind are native Dart right this is what Xcode really shines with this is where the dependency graph is maintained continuously up to date internally so we can show nice up-to-date information about it native targets currently support applications frameworks libraries plugins and there is project level support for multiple OS SDK so you can be on Panther and you can build for tiger for example they provide the best integration of the user interface but sometimes that's not feasible so sometimes you have other kinds of targets you want to use so one of the kind are what we call external targets and the icon here is a shell command or a command-line tool icon because it actually lets you invoke any command line tool at all and you can typically invoke things like new make or aunt or those are those kinds of things typically they're used if you have maybe an open source project or a project that sets this cross platform but you can actually invoke any script or command as we'll see a little bit later on a demo Xcode also supports project builder Jam style targets so that for those of you who have projects and projects builder there was a separate command line tool called Jam stands for just another make and that's what there was an external tool the pipeline for the information between IDE and the build tool wasn't that great so that's we have native targets but the jam targets still support everything that they did in project folder we did this specifically so that you'll be able to transition your projects from project builder tax code very easily it's a good idea to convert to native targets there's a menu item for that the only thing not supported as native targets in xcode 1.5 our java targets or working on that and the architecture of xcode is actually fairly flexible so in the future we plan to allow you to plug in customized support for other kinds of build systems if you want to we don't have that yet we're hard at work on that when we're not doing presentations for WBC so that's a little bit about target types so these things are these things determine what gets built but how do we determine how to build it but these are the build settings right so they control the inner workings of the build they're like the properties that you make variables analogous to that so their individual properties one settings value can actually refer to another one this is someone powerful you can define a setting that has the path of a common directory and then base everything off of that for example the install pass can actually refer to dollar home turns out that home is one of the build settings that gets inherited from the environment so that can be kind of nice build settings are passes environment variables I mentioned external targets we passed that in the environments if you have an external shell script or a new make target or whatever they will actually have access to that of course for native targets it doesn't really matter there is no external command to be called build settings can be set at various levels will see that shortly they're usually set on a particular target because that's the most natural place to set a preference or a build default is on the product that gets built and there's an ordering it's the build settings so that your customized values override the defaults and build styles override to target values etc the higher levels override the lower levels so what are the levels well here's the president at the bottom we have the inherited environment variables these are the just the basic things like like the homes variable that come from a terminal if you're purely an ID user you probably don't care so much about this after that comes a built-in default settings there's a lot of these right these are all the set all the default settings for all the compilers or linkers or whatever you have installed so whether or not optimizations on or off by default that kind of thing above that are the target setting the build style settings come above that we'll talk a little bit bit more detail about that and above that or the command line setting for what's this well for the IDE itself this is always empty this is always a moot point but it turns out you can actually build a project from the command line and that's where this gets useful you can override any setting at all from the command line when you invoke what's called Xcode build to build your project from the command line the environment variables we talked about these get inherited the built-in default so the linker settings that kind of thing that the default values target settings are real interesting so we're going to drill it down and talk more about those you set the target settings in the build tab of the target inspector as a target info window so we see the little red red circle there how you get to that and that opens up this panel and here we see the settings it's just list you saw this in the previous session shows the inherited default values as well as anything you've customized anything YouTube customized is showing bold and the inherited ones are are not involved also I mentioned the build settings there's anything set in the build setting Trump's the values of lower levels so we show in strikethrough we show the ones that are set and build settings in in in built out so this indicates that the dead code stripping setting is actually overridden in the deploy in the current build style something else here is we have a pop-up menu that lets you focus on category of build settings I think this was shown in the introduction Xcode but it's worth pointing out again that you can actually click on that that table heading there and and narrow down your your focus and of course we have the search field which lets you find any setting that you want quickly and this match is not only certain not only the name of the setting but also we searched in the help string for that setting so if you type in if you're not sure if you can't find a setting you're looking for try typing a phrase related to that into the field here okay so much for target settings that's pretty simple so build style settings we'll talk about that these guys have said in a similar manner they left some variations on targets so the bug versus release app the pro version of the app versus a demo version let's say they as I mentioned the build sells override anything at the lower level some examples of how to use build styles you can for example build with without debugging symbols this is fairly obvious you can build with zero link enabled or disabled their link is feature that we use a development time but we really don't want to use while we ship with product different optimization levels pretty easy alternative rhythms suppose you're trying out some new hashtable algorithm you want to build one variation of your apps with the old algorithm one variation with the new one and just in performance test let's say you can enable/disable features if you do a demo version of the app you want to disable save and with a good stripping the codes going to get removed as well that's a feature that's new to 11.5 you may want to set different build output paths so that you have your debug builds object files going to one place and your deployment bills going to the other place so why don't you tell multiple targets right i mean we haven't already have separate targets well you could but let's consider an example right so what if i have an application and let's say that i have a demo version of that application right so all we do there is we set a special bound to find that turns off saving okay let's say there's a support library that they all rely on but actually so I've been doing development for a months and so let's see okay well what I've actually been developing is my is my debug version of the thing right so now it comes time to deploy well I want to optimize better want to maybe turn off some debug logging that kind of stuff so I really have another version of each of these targets and then suppose I want to have yet a third style where I say well let me try that new hash algorithm I still want to have optimization on so I can really do the performance testing so now i have really yet a third set of each of the target so all told I have nine targets and really what I have though if you look at them is the combination of three targets times three variations on each week or less fees and to build styles we get rid of these so what we really have is is and the plus n as opposed to end times then so build styles of multiple targets right you can use multiple targets and just ignore build selves that's fine but they're there and especially helpful for large projects so let's talk about how to set those the settings there we go to actually the project if you notice what selected here is the project icon up at the top build styles are attached to the project not to each target so we inspect the project and that's where we see a list of the build style so this is in the Styles tab if you notice at the top the four tabs I've selected the Styles tab and there I see in the pop-up I see all the styles that are available and the window looks very very familiar right it's the same thing that we see in the target inspector just now we're editing a different level of the president's one in important thing or one important way to use the build Styles is to only define the things that are unique about that style so if you have some setting that really is common to all the styles as the same value for all the styles odds are that it's not really part of the variation so that that's one thing to keep in mind one interesting thing is that you can actually refer to the overridden value you don't actually have to obliterate whatever is defined below you can just append to it so if you have a bunch of preprocessor macros you can say dollar parenthesis value and for capture the overridden value and then just add to it that was a little bit about build set build style settings there's more and that you in the documentation can reach from the distinct help button there again we talked about the command line settings these are for use by could build I'll talk about that a little bit later another thing that native targets have is build rules and these are just like the rules that you would define and make or any any language like that right they control how source files a process and every will consists of a condition and an action and the condition matches on the kind of file that you want to process so the first matching rule is used and what you do what xcode does is that it matches on either file types so this is the abstract file types such as all see like language files which would include C C++ we could see that kind of stuff or you can match on specific patterns the filing pattern matching is particularly useful if you have something like you custom extension for custom file format let's say you have a unique image file format that he use you're developing a game you can set up a rule that will take files with type suffix and pipe them through some translation tool that compiled the image or whatever so they can load faster into your game that's just an example you can use them to select the compiler inversion for example GCT 35 there's a preview of that in your onto DVD that you got and you can use build rules to select between GCT 33 and 35 the default is 33 but you can you can easily just change the pop-up to select 35 another example is Java C vs jokes and as I mentioned you can also use them to generate translate files or even generate custom source code the outputs of a build rule or pipes back into the Builder old machinery so you can generate some cascading rule applications in sweat you headed to build rules using again the target inspector you go to the rules tab this time pretty pretty obvious if you hear that you can define you can use a custom script if you want and there are some macros that you can access input path output path for the name of the file being processed again the the pink question mark icon there is your friend when it comes to help about what what's going on here as we see here the system rules are defined down below and the custom rules are above if you remember I said the first matching rule is used so custom rules at the target level overwrite anything at the system okay we have a fairly extensive set of built-in types that extra recognizes and you can notice at the bottom those wells pretty low but the ridge the last item says source files matching that's where you can type and let's say start out to so that's the condition the action shows all the compilers and translators that Xcode knows about and you can also type in a custom script in any scripting language you like that's a little bit about build rules as i show you can define actually what the output pass is going to be the ties into Xcode dependency analysis so your script is only run if the inputs are newer than the outputs okay so let me show a little demo just and show her some of these things are grab the demo machine please Thanks ok so I have here a diversion of sketch and what I wanted to show was a couple of things in so many of these demos you know just kind of opened something and build it and shows that it builds I figured I'd do something a little bit different and actually show you just where the items are some of the more commonly asked questions so one of the big ones is if you select the target the project icon up here and then say and so that's how you get access to the style but not underneath the targets the target has its own setting so we can expect that to write and actually I inspected the target smart group which has nothing but I can select each target and show that but again the project is what has styled if you notice here there are a couple of items that are in bold these are overridden I've actually here I've overridden the the output location for both the intermediates and for the products and so what's going to happen here is that when I build with the development build style it's going to put everything into a subdirectory called debug if you build with the deployment it's going to put them just into the default location so that's really useful this is also where you can define new styles up here in the the project inspector and name your own build style that kind of thing you can obviously edit build styles and delete them in that kind of stuff so one other thing that I wanted to show is that when we have stringless settings you can actually you can actually edit the value using a sheet now and if I can find one let's say a preprocessordefinitions can narrow it down there preprocessor defines i can say edit setting and i actually get the sheet to edit individual list items in here so i can do do that if i choose one other thing I wanted to show is the build rules again here's the rules editor now this is notice again that this is at the target level so each target can define its own rules here are the inherited ones and I can also of course add my own rule and I can choose whatever I like here okay one thing that you may find useful is you notice I can only select the target up here we actually have another pop-up menu they can add you toolbar if you end up using build Styles a lot like I do for example you can actually just add another pop-up for the build style and so the way to read this is ok I'm going to build a sketch target I'm going to build it with either for either deployment or development and that can be fairly fairly handy thing to do so just a little overview of this could we go back to the slide please okay so we talked about the project model a little bit that was or a quick introduction or a quick refresher looks like really about optimizing bill performance before you were here increasing productivity with Xcode so speeding up the bills well what occurs during a build expert has a fast powerful build system and it keeps a lot of information internally so some features are automatic we talked about the dependency analysis that's always kind of being updated in the background so that when you hit the build hammer we already know what's up to date or not we talked about parallel builds if you have a dual cpu machine xcode automatically takes advantage of both cpus zero-length these are all things you've heard about predicting compilation you may not have heard so much about we'll talk a little bit more about that the basic idea is that we can start compiling while you're still editing your file so that by the time you save your file and you actually hit the hammer we're done compiling it and that works really nicely when you especially when you have single file turn around so those are some automatic things there are some things you can do to optimize your project one of the biggest things is to add a precompiled header Xcode comes well Mac os10 comes with a lot of SDK is a lot of headers and there's just a lot of declarations that the compiler has to see every time it compiles a source file so we can we can speed up some of that work by doing it only one another big thing is distributed builds I'm sure you've heard of this too maybe you don't know quite how to enable it I can figure is that kind of stuff we'll talk a little bit about that sixty continue is another thing that you saw in the introduction sessions how many people are actually used then Wow okay try it out it works most of the time there are some caveats that other sessions have gone into to change the size of a structure that kind of thing basically patches your code while it's running so you don't even have to quit and restart the app and it can be really good at really a time saver but let's talk a little bit more about the compile at a compiled debug cycle so let's say we're editing a file that's it takes some time right and then we have let's say we edit for files we end up this is the slow case we end up compiling each of the four files and then we link and then we start the program so one of the things we can do as I mentioned here's the timeline that this all takes one of things we can do is set up a pc h a pre-compiled header this cuts each compilation down to a fraction what it was so we shorten the overall time okay that's pretty straightforward another thing we can do is to use your link to enable that during during development it is enabled by default for development builds so that cuts out the link during development so now we've shortened it a little bit more still we have the CPU marching through each processor like that I'm just compiling it and then finally we start the program so let's do it in parallel we have a dual cpu we can have each GPU actually going through compiling and we're done in a shorter amount of time but we can do even better and suppose instead of just using two cpus we used one of ours or two of ours to take the data preprocessing somehow send it out across the wire to other machine but those compile the files and send the results back and then we just harvest the results so that shortens the time and that is great for large bills especially when you have lots of files suppose we just take the single file case just go back to that so we're still back to the one file even if we have dual CPUs if we only touch one file there's no point in having two CPUs we can't really Carol lies we can just do that one so one key observation is that editing is not very processor intensive so we commit we can actually make a shorter box to indicate that and then what we see is it can actually slide the compile step in underneath the editing meaning especially in a dual cpu if you have to read you can be editing with one and compiling with the other one so what Xcode actually does to send down the first part of the file and then wait until you hit save and it sends the rest of it so that shortens the compile time and then the last thing is as I mentioned six and continues we can get rid of restarting your app entirely in most cases so you can just keep on patching the code in your wrap until you find its unique change of structure or do anything more significant like that so it's a fairly short compile time compared to we started out with soap recompile headers so that yeah that's that's nice graphic but how do we actually do this well what you do is we use the observation that most of the most of the code is in the headers the compiler sees the same code over and over again analyst for using precompiled headers one example I just found a small one a little C++ file under developer examples and this is the this is the you carbon event TPP it's actually 54 lines long and this is actually the whole text of that file so it's a very tiny table scroll spoilery but wouldn't be interesting things here and expensive ones is we see that it says import carbon / carbon H so what does that end up doing well it actually ends up working the code that you typed because this ends up being 9944 lines that the compiler has to see so this is actually not even to scale the grade line there would have disappeared it's actually point zero six percent of the code that came from your project and ninety-nine point ninety-four percent came from the system headers so the obvious thing to do is to create a precompiled header for for a carbon that H so you too d 33 and 35 support precompiled headers and they're pretty easy to set up an Xcode what you do is you create a prefix header that gets implicitly included in front of every source file in your target it's a tapper target level and then you just check the checkbox that's a pretty compile this thing exco to automatically figures out which different versions of it it needs to do for example if you pass different preprocessor macros and different headers it actually builds builds it correctly for you keep in mind though that prefix that are gets included for every source file to target so it has to be compatible with every source file if you have people's plus an objective c plus plus then you need to use pound of steps appropriately there's a really nice help page on that index code documentation you search for PCH the other thing to keep in mind is even if you have a correct prefix header it can get precompiled too many times if you put changing headers in it so they did the trick here is to put all the stable code typically the system code which hardly ever changes except when you update the software you put that in the precompiled header and then you leave all your user code to be compiled every time and the other thing I mentioned is Xcode does pre-compiled the prefix header on demand which means if you change the input conditions so the pre comp is no longer valid Xcode will rebuild it for you so that's a little bit about precompiled headers just shortly about distributed build there's some some questions we we get about that Xcode automatically uses all CPUs right the why why limit yourself to your own machine there's lots of CPUs we only ship dual CPUs but you could have a 14 CPM machine if you use all the other machines and their offices next to you the way to do this way to enable this is to go to the Xcode preferences and there are two things you can set or you can set whether your machine should use other machines to precompiler to to distribute to and you can set up at the bottom there whether your own machine should be a distributed build server something is to keep in mind it's only available in the 33 and 35 that's a big of an issue for most of you who are on 33 obviously the faster your network in the faster your machines are the more benefit you're going to have and it really does require 100 bass-t network to be effective because with the machines even the powerbooks being so fast anything slower than that it's also faster just to compile locally than to send it out and get it back the ideal number of machines we found is between four and ten that that's a very fuzzy number it just really depends any project but it's probably not the case that adding 200 extras is going to make it 200 times faster than not having distributed builds so there is definitely a fall off at some point keep in mind the security resource code this is concern for some of you in that and not at all for others there are two modes one is rendezvous this means go out and find any server who's willing to compile my code and let it compile my code but that means that you're sending your source code to that machine so you make sure that that's something that you want to do the other option is to specify a list of servers you could do that in the panel that I showed you in the previous slide you can actually just specify a list and if you enable rendezvous it will actually show you the list of the servers that are within range and you can check off which ones you want and limit the list that way to let's say a set of secure machines and a lab somewhere so we talked about precompiled headers and distribute a build 0 link this is fairly automatic there isn't much to talk about here except to observe the length time is significant part of the turnaround time and typically you're editing only a couple of source files so the interesting is saying here and where you need to be aware is that it runs the code directly from the object files it does only work for applications and command-line tools right now for technical reasons the big thing to be aware of is keep in mind it runs from development from the object code so therefore you don't want to do this when you deploy your app the deployment build style is set up to not use zero length by default that you actually get a real app that gets linked don't trip interlink builds because it's going to try to access the data files back on your build machine if you get this I know if you can see this but basically it says zero line could not load o file then it gives a path of the data file that indicates that you took the the binary stub that was built for zero link and took it to another machine and the binary sub is about 10k big and it's all the old files are still back in your old machine so that's that's a symptom of that and the fix of course turn off your link for the plant those particular just want to mention a little bit this is off by default so here's something that you can do to increase your productivity normally even the PCH doesn't get used nothing happens until you have build so here's the idea again that we can get a head start by using those idle cycles while you're editing and start compiling we send the first couple of town includes which typically include include heavyweights like carbon H or coconut H and get the compiler really chewing on that stuff first and then while you're still typing your code the compiler is just sitting idle and then when you say we send the rest of the data and then when you have build oftentimes the compilation is already done and the data file is just sitting there ready to be used so it effectively essentially eliminates the compile step for single editing even if you're editing multiple files before hitting run again if you edit them in sequence it actually can eliminate the compulsive entirely the ways to turn this on there's a checkbox and the press panel so that's all you have to do for that it's automatic after that you're going to show a little bit of that okay what I wanted to show first here is we inspect the target again see that I have let me see here if I can find the prefix setter there we go so I've said here s Keith SKT prefix this is a project roller path actually to a file in my project so let's take a look at that which type prefix can use the Handy detail view to get to it all this one does is include coco de h if you had people plus in here this would still work because of the guard macro that's what i was talking about before the precompile had reached exciter checkboxes it is obviously the one that caused it to be to be precompiled you could have a prefix that or even if you didn't want to pre compile it that's typically not not very interesting zero link is really does show up in the target inspector because after all it inspect all of the settings so if I choose 0 here at cic 20 link actually is overridden at the target level and the reason for that is the difference between the deployment of development build so I go to the project and it's back here if I go to the styles let me narrow down again r0 link I'll excuse it in the development style 0 link is checked and in the deployments violates unchecked so that that's really how you want to do things another thing I wanted to show here is the distributive builds again we see normally under building there's some some options for the local machine distributed builds is the prep pandas dedicated to to distribute the build I don't have set up for distributed bills because of the the demo machines here but pretty obvious what the settings do but I wanted to show that this is the panel actually where you get access to that because sometimes forget questions well I you know how do i set this up or do whatever you can look under building there are some interesting options one thing that Xcode supports which is actually kind of nice is to build through shared location this is particularly nice if you have multiple projects even they're unrelated you can get all the products to go into a particular location it's also good if you're working with source code off the network and you want to make sure that your binary is really on the local disk it's a really good idea for performance the predictive compilation is off by default but and disabled by battery power by battery power but it's really good thing to be to be turning on we'll be turning that on is the default and another useful one is if you want explicit control over how many processes to to run on your machine we're limited to three because we've really seen that it can hurt the performance or the responsiveness of your machine is you if we launch too many compiles of once on the same portable power book so it's a little bit about that one other thing i want to show actually is i showed how you can set settings at a target level you can actually set settings at a particular source file level two you can either navigate down into groups here you can expand the sources phase which are all the source code files for that target or you can just see them here keeps fact if you select sources you see them all listed they all have check marks because I built the project yet this means that it needs to build one of the things you can do is you can actually select here and you can add additional compiler flags and if you if you add compiler flags to a particular source file Xcode will take care of generating another version of the precompiled header for that if it needs to so you don't have to worry about that okay so just a little bit about those kinds of things creative slides back please thanks so we talked about optimizing build performance a little bit i just want to show you where to go to set some of these settings because of the questions to get on the mailing list indicate sometimes people don't don't know that i'll talk about it really interesting topic those automating some of the common tasks we talked about how to make the things you already do as do those things in xcode faster but automating common tasks gets into territory where you may be doing something totally by hand that you could actually automate so what if some of the ways we can do this well you can automate the build that's one of the most obvious things and there are a couple ways to do this one is to use the command line tool the I'm command line tool called Xcode build I'll describe in detail you can use applescript Xcode is scriptable so for those of you know one love Apple script we can use that and actually there is a automator stage in an action that you can use to build a project another way you can automate your workflow in xcode the build workflow is the set up custom build rules I mentioned that I'll talk about some more examples some custom build phases have really interesting uses that that I haven't thought of all of them and I'm sure you can think of many many good ways to use them they were the external targets these are really kind of opening a porthole into the machinery so that you can actually hook and anything that you like into the build phase and into the build sequence custom executables is another topic I want to talk about this is sometimes underused but can be extremely powerful especially if you're working on libraries and plugins we start with building on the from the command line the tool is called Xcode build and it's in your default path so if you're running from terminal you type Xcode build it provides access to the exact same build system as the IDE uses so there's no sort of compatibility mode or any of that stuff it's actually the same shared library that's opening your project and building it you can evoke from the command line from the shell scripts for example or directly from the command line good for nightly builds that kind of stuff the basic implementation the basic location to Xcode build and that would just bring your projects at the date whatever project you have to change the working directory into but it has several options one of those is you can say what action you want I mean that's pretty obvious you can remove your binary so you can bring bring your project up to date you can actually specify which target you want to build and this is obviously useful if you have many targets I showed the target pop up where you can choose which target to build this is this option the dash target option is actually the same thing is that problem sets for too controlling same with the build style you choose a build style development or deployment typically if you're building from the command line even building for deployments and you'll want to put the results and installer package something like that this is the same or controls the same setting as the pop up for the build style into Xcode ID and under the hood it actually controls literally the same setting so there's a high degree of fidelity there you can also over at build settings if you remember the gray box at the very top of the president's with command line options that's what these are so if you pass any of the command line options II just once that you've defined or that are built in you can just override that on the command line this is kind of a new make style use of the Xcode ide but it's it's nice to have a command line tool like those for the automated stuff so if you don't want to use the command line you can also use Apple script excursion scriptable if you go to the script editor and you say open dictionary Xcode shows up in there and you can see all the classes and commands p.m. not all facilities are available from Apple scripts at this time but we're working on completing that rounding it out project operations are you can set build settings you can add files that kind of stuff here for example it's just a little line of Apple scripts that just builds a particular target specific current set of build settings so this is another way that you could automate your build process for actually going from source code to file disk image that you ship to customers so either or custom build rules are a way of automating inside of the projects as I mentioned inside of each target I'm repeating some of the same information here but I want to sort of try to give a couple of opportunities to and to help you remember it they could the essence is that a rule controls how the target produces and processes the source file so in action it's any script you can run from terminal you can even use Apple scripts you can use pearl Ruby that kind of stuff obviously a normal shell Python as I mentioned earlier the build rules can declare the path that gets produced the find output files so this gets related to the input files by Xcode and so your rule only gets run if the input is newer than the output or if the output doesn't exist and the produce files are set right back into the dependent into the rules system so if you produce see files then they get set back in and the rule for C files gets applied and it could see compiler is involved so that's fairly handy for example custom scripts to generate see files from whatever data files you have in fact the tool that you used to generate those see files could actually be built by another target in your project we've seen that in some of the internal projects at Apple actually other example uses pre-processing generating code code you can invoke compilers that are not directly supported in Xcode we have a list of some of the compilers that are supported GCC is the the only c compiler with built-in support there are other c compilers and Fortran compilers and you can use a rule for those custom build phases are a little bit different from rules the rules are conditioned action kind of saying build phases are just steps from the sequence to build your product and so you can add them to any point in your native target and the primary uses are things like copying arbitrary files for exam and running upper tree scripts you may have UNIX man pages you may have custom files that going custom places in your applique you can specify inputs and outputs and again these phases get run only if needed and the paths have fed directly into the Xcode dependency graph so some examples copying files and folders that's a popular one a lot of people have somewhat complicated applications and they want to embed frameworks from that kind of stuff you can set special permissions on files we have a have a little kernel expansion that kind of thing that it needs some special flags you can also install files in arbitrary filesystem locations so that's what I mentioned the UNIX fan page this is maybe for more of the sort of typical darwin development it has specific places in the file system were files need to go typical Mac applications should be able to be run from anywhere external targets I mentioned this early on this is a way to call any kind of external build system you have so you can specify the actions in vogue for build for clean all these things are passed in the environment so you can actually set your own options at the target level and they get passed down through the environment and if you have a perl script let's say or shell scripts you can pick up those settings and modify the behavior of its based on that so there's lots of opportunities for weaving your own custom scripts into the xcode build process here to really get to it to a source to disk image kind of workflow you can customize the command line as i mentioned you can pass any are any options you want if you have your own script that you're invoking to drive a part of the build system that's maybe not so interesting because you've you just change the script but suppose you using aunt or or make you could do that there are actually a project templates to invoke the ant build systems are installed as part of the the Xcode install for java development so you take a look at some of those four examples of this sexual ok so other examples I think I talked about these some of them already make and yeah talked about this package maker is actually another interesting useful this we intend to think of external targets to to invoke external build systems but any tool can be involved so if you want to use it to create a package disk image there are command line tools for that excellent does not yet have to have gulping target types for building disk images and other kinds of deployment targets that's definitely something on our list but meanwhile you can actually wired up yourself but not not that much work web server deployment tools is another interesting one you could ftp as a result of your your build over to some server etc custom executables are an interim I think under use but a very useful tool anytime you create an executable target such as an application or command line tool Xcode automatically creates an executable for you and what's an executable well just an execution context so that names something to be run the directory from which it should be run any kind of arguments to be passed to it if it has any on the command line you can set these up for anything you like so if you're developing a photoshop plugin you can actually set up an executable to launch photoshop and have it load your plug-in launch parameters can be configured and as I mentioned you can create as many of these as you want custom ones plug-in development is one libraries to if you're working on a framework or library maybe you're you're most of you probably shipping an app or working on something like that but if you are working on just the framework what you probably have is you probably have a dozen test apps or more and so you could set up an executable for each of your test applications each one configured to run with your build version of the library and that's a great way to test your library as you make a change to your framework code you just hit build and run it will run some other app but load in your framework and you can test your changes that way and it's useful for quickly switching between them just as there is a development like a build style and a target pop up there is an active executable pop up which controls what gets run when you hit the Run button so that's another thing you can add your toolbar so I want to show a couple of these things in action the time actually going to show not just show where things are but actually build a couple of things so can we have the down-low machine please thanks so what I'm going to do here is to first let me just go ahead and build let's say we have the development build style here is the the active one I can actually add i'm just going to control click on here and you have the active executable show you that sketch not surprisingly executables shown under here and you can edit any kind of settings there what i want to do now though was too let's say create an external target let me go ahead and I'm going to do is to go under the project menu select sketch here you go and say new target and what I'm going to do is create a shell script target and let's say I want to create a disk image so that's what I'm going to going to choose and I want to add it to the sketch project that's pretty simple okay so now we have dance fo here by default this target it doesn't build any kind of product at all it has is a single phase they create that runs a shell script so I'm going to inspect the shell script build phase shell script goes here right so i could type in the whole shell scripts here if I wanted to but what I'm actually going to do I have a ready-made one that I'll just add to the project i'm just going to drag that n drop it here under under the groups and files i want to copy this into the project actually it lives on my desktop right now so i'll just copy it in i'm not going to add it to any target because i don't actually want to install the script as part of any build if i added it to the sketch target it would get added as a resource in the resources bucket but i don't want to do that so i'll just go ahead and click Add so now i have my shell script here I can let's see you take a look at that and in this case it's a fairly it's not too complicated uses applescript actually the most of the complications use apple script to configure a disk image what it does is just created disk image used apple script to set position of files and icons and color and stuff like that compresses the disk image and then it sells the finer to show it to us so let's go ahead and take a look at that now I've added the file to my project but what I also want to do is of course to to edit the shell script old page itself so I'm just going to tuck in a shell command here to to this case just invoke the shell script that's in my project the shell script here gets started up from the project folders so that's that's fairly fairly succinct way of doing that she noticed at the bottom there is the input files may output files this is how i mentioned that xcode weeds and the shell script into its dependency graph so that it knows when to run it so what I'm going to do here is I'm gonna actually going to add I'm going to use some of the build settings that are defined by default I'm going to say that in my built product directory there's going to be a application called sketched out app could drag this into these build settings header know about build products sir well we have a menu item for bringing up the HTML page for this we have a bunch of built-in build build settings normally if you're just building an app in xcode if you're not doing anything particularly like automating the workflow here you don't really need to know about these but they're very useful if you do want to do anything more a little more complicated like this another thing I'm going to do is I'm going to make the shell script here depend on the shell script file that I am actually including and what this is going to do is it's going to mean that my shell script gets run if the product is out of date and also get and get run if I modified the script that built the disk image so that's kind of nice and what does it produce we need to know what to compare against so what the script produces is it put and target builder that's another one of the standard defined settings it's going to create a sketch disk image so now we have this all set up and let's see what happens when we build one of the things that I do is to make sure I picked the deployment target so don't try to ship the the zero link binaries and I'm just going to select the create disk image target there's one more thing I forgot to do is anybody know yeah so right now we have two independent targets you can actually have two separate totally separate dependency trees or two or more if you want an Xcode but to relate these two targets to each other what I want to do is I want to bring up the inspector again and I want to add a dependency from the create disk image targets to the sketch targets so this means that schedule get updated before I even try to build a disk image me and get rid of a couple of the the inspectors here and now let's just go ahead and build this so it's going to go ahead and build sketches it normally does and actually I'm going to do is it's linking it's not very linking so that's a good sign so it's running the custom script so it's actually creating the disk image and mounting in setting the background color and all that good stuff so now we actually end up with a compressed disk image that can change my built version sketch and I can ship this to my to my customers and moreover thank you moreover if I go in to Xcode again and I have build see it just says build succeeded we can look at that in more detail for you bring up the show detailed results I'm just going to hide the editor here because I don't really need ever know nothing happened here well that's because Xcode knows that I haven't updated sketch I have not updated the script and so I don't need to do anything if I go in here and I update the script one of the things I can do that date the script is to say okay here's some of the input settings so my script takes well let me go ahead and copy one of these and I'm going to not define it in the script itself I'm going to save this what I'm actually going to do is I'm going to set this Andy create this kimmage target so I go here and i have my own setting and i'm just going to make this be let's say zero so now when i build and it knows that i need to build because i modified one of the inputs so now when i build it runs the custom shell scripts and it's going out to the finder again and now we get a different color so and there again if I build once more nothing happens this is a nice way to make sure that we only actually do work when we need to so that's where the shell script inputs and outputs come in all right so that's kind of interesting but we can actually do something even a little bit more interesting with shell script build phases me actually add in the shell script build phase to the same target you can either create a new target and have it depend on other things you typically do that if you have your own build system like Andrew make if you just want to have a little steps to happen at the end of updating a target you would just add another shell script build phase I'm going to go ahead and do that I can do that in several ways I can go to the project menu here saying your build phase i'm just going to control click here on target actually and i can say add new build phase yeah at a shell script build phase just another one I get another inspector looks exactly the same because it's just another shell script the sequence of these matters so they accept rise to run your shell scripts in sequence it will however respect input and output dependencies as a higher order presidents and respecting the the order in other words if you say is that the the first shell script depends on the output of the second shell script it will actually run the second one first so will respect the dependencies what I'm going to do in this case is I'm actually going to use Apple script now I'm going to use a tool called with a script and what I want to do is I have another little script here that I'm going to drag into my my project i'm going to copy it in not going to add it because i don't want to copy it into my product this is just a helper script while I'm building my product and so here's a little apple script and what I want to do is actually you know in and see if I can't get get a little notification here when I when that build completes so what I want to do is I want to I want to get an SMS when when the put my build finishes so I'm just going to go ahead and have a little script to use his Apple script to do that let me go ahead and just type in the name of it notify completion that xept I don't actually need any inputs and outputs in this case I just wanted to run at the very end it just always run if I need to build something if anything needs to be updated I just want this always run so we're just going to go ahead and build again and we're already up to date with the disk image so we shouldn't really need to do much what we did though was we ran we ran an applescript to send me lil SMS and ok so the build finished and actually it says your build succeeded but you can't do that so that's that's an innovative use I guess for for build phases so go forth and experiments with that alright so i can we have the slides back to okay so just to summarize okay slides right of water just to summarize one of the things we mention Xcode has a lot of built-in features a lot of you don't have to know about sometimes you just have to enable like predicting compilation your length all this kind of stuff just just works out of the box semi-transparent right there a link pretty good compilation icon stuff others do require some setup because there are inputs that X cannot know such as with your prefix setter what's the nature of your project what kind of what kind of headers is it that you use that are not changing their something's Xcode can do to analyze this we're thinking about how to make this even more automatic in the future but for now set up a prefix setter make sure it's precompiled this will save a lot of times during build and we'll get some some good build performance distributed builds is another way if I'm sitting in a coffee shop with my powerbook this isn't going to help you much but if I'm in the office and I have a build form that's just a couple of meters away this can really speed up especially a batch build if you have a large application you nightly build this could be a real time-saver custom build phases and build rules a little bit different right they're not helping you speed up the things that you're already doing such as building your app but they help you automate some of the things that that you might be adding to do by hand and even if you have existing script to do something like build a disk image we've seen how you can actually weave that into Xcode and two to get Xcode to invoke it at the right time so explore the possibilities and use the mailing list the Xcode helps and and learn about these features and use the great documentation that talks about these features so for some of the more information there's actually sample code and some example project here at connect apple com I think you've seen this address and in many other sessions some sessions there's there's the samples that we show the demos you can actually download those play with that yourself obviously the expo build system in the reference library especially for the bill to build settings they're all documented there there there in the HTML pages there's a normal Xcode help of course on the release notes I'd like to his Matthew Formica here now okay we have virtual Matthew I'm going to ask virtual matches we come up on stage again it's wei-li and and at this point I'd like to also ask the arrest of the Xcode team to come up for Q&A