I've written a toy libtooling based tool that does some analysis/source rewriting over ObjectiveC code. How do I run it over an iOS Xcode project?
I've looked at compiling the application through commandline/clang, but I haven't got it to work yet. Is it possible to chain my tool with xcodebuild? Or is there a better way to run the tool over an Xcode project?
I think what you need is JSON-Compilation-Database.
You can use xctool to generate a json compilation databse (xctool has a reporter that generate this thing, see the readme.)
The json compilation database is just a json file which contains all the compiler options (say, the header search path, the frame work search path) that need to pass to the clang and libtooling based tools.
If you want your tool to generate errors and warnings in code it should be a clang plugin and you can just change your project clang flags to load the plugin.
In your case it seems like you are using libtooling that alters the source code, you can simply add your script to your project build process prior to the "Compile Sources" stage.
In Xcode -> Click on Project -> click on your desired Target -> Build Phases -> Click on Editor (Menu Bar) -> Add Build Phase -> Add Run Script
Drag the new Run Script to be before Compile Sources
Edit the run script phase to do what you want
Related
I'm using protobuf to generate swift classes from protofiles (I've written a script for this purpose). Now I need to add all generated files into target in Xcode project.
How can I do this programmatically? Maybe script in Build Phases or some other kind of actions in macOS (Automator?)?
CocoaPods uses this project to modify project files: https://github.com/CocoaPods/Xcodeproj
It is possible to do that with functionality built into Xcode (we have done it with c++, but it should be possible with swift, too):
In your target, add a custom shell script build rule that matches the extension of your protofiles.
Call your script using "${INPUT_FILE_PATH}" and "${SCRIPT_OUTPUT_FILE_0}".
If the output file's extension matches another build rule, that one will be executed. So in you case, set the output file of the build rule to ${DERIVED_FILE_DIR}/${INPUT_FILE_BASE}.swift in order to send it to the swift compiler.
Now go to your target's Compile Sources build phase and add the protofiles.
You can do this via Xcode "Build Rules"
Check this project which leverage "Build Rules" to generate source code files and add them to the project from protobuf
https://github.com/microsoft/plcrashreporter
When I try to compile the repo https://github.com/Bernie-2016/fieldthebern-ios I run into a swift conversion issue. "This workspace has projects that contain source code with an earlier version of swift."
"Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly."
When I try "edit -> convert -> To current swift syntax" Opens up selecting targets to convert, many of which are frameworks. Proceeding with the conversion yields >3,000 errors in the console.
I think the solution is to grab the latest libraries via cocoapods and then complete the conversion with the main project code but am not getting any luck.
Make sure that your podfile references a Swift 3 branch for every Framework.
Then you need to cd into your project folder using Terminal
Run: pod update
once done, open your project in Xcode and you should be prompted to convert into the latest Swift Syntax automatically, if you weren't you have to do it manually in
Edit > Convert > To Current Swift Syntax…
when all changes are prompted, click update
this will again display 999+ errors but no worries.
run the clean command Cmd + Shift + K and then build Cmd + B
you should have no more errors and if you do have errors, they shouldn't be a lot and you would have to go through the errors manually to fix them
its completely normal, it became a routine thing for me when using CocoaPods
I'm new to OSX/iOS development and I'm developing a library project (Cocoa Touch Framework) for iOS. While working on the library I would like to test changes to the code, but because it's a library, I can't run it straight away from XCode and view it's output. What I'm used to do in other platforms, (Windows for example) is to create a another project under the same solution (Visual Studio), add the library to this project and write my test code there. Unfortunately I didn't find a way to do something similar in XCode, my workflow now consists of quitting/opening two different projects, copying frameworks around and re-adding framework dependencies.
Surely there must be a better way to do this...
There are lots of post already in the SO .
But keeping it simple just follow these steps :
1.) Drag and drop Xcode project to your Xcode project 2.) go to build phase and then select your project (which u have imported ) to target. 3.) Search path - > user header search path (select your library) and also enter other linker flag.
Simple !
Is't exactly the same in Xcode :)
If you have a project (without a test build accompanying it) is:
1) See, no test Target :(
2) Click on the target that you want a test environment for (in my case, locates) so it's highlighted.
3) Click on the "edit" menu, then pop down to "Conver to" then "XCTest"
(yet another one of Apple's ambiguous places to hide things!)
Follow the wizard and that'll create you an XCTest build target that can be run on demand and through CI.
Have fun!
I can't handle the Xcode IDE for this particular project anymore!
I have a simple C project I want to build into a static library for iOS, and I don't want to use the Xcode IDE.
I'm familiar with xcodebuild but my understanding is that I'd first need to create an Xcode project to use it - and simply being able to build the project on the command line isn't my goal.
I want a standard make-style build process for this project but can't seem to find any information about doing such a thing. It seems like I can't. Is that true?
You absolutely CAN use a makefile project. It's just a matter of using the correct paths, etc...
Here's something to get you started:
iOS static lib cross-compile script
Xcode seems to allow specifying a custom compiler for source files via the Build Rules tab (copy the system C rule to the target, select "Custom Script". Just for testing the concept, I wrote echo $* as the script.
However it doesn't really run that script (no output is sent to the console); the end result is that no file gets built, so later I get a link error.
Am I using it wrong? What's the correct way of using a custom compiler in Xcode 4.x?
I tried your example. The script would not run unless I added an output file to the Output Files table for the build rule. Then the script ran, but the results appear in the build transcript instead of the console. Open the log navigator by choosing View > Navigators > Show Log Navigator. Select your build from the log navigator to open the build results window. There should be a run custom shell script step in the build results window. On the right side of the step is a small button with several horizontal lines. Click that button to show the build transcript.
If you want to use a custom compiler on some of the files in your project, you may find it easier to add a Run Script build phase to your target and add the files you want to compile to the Run Script build phase.