ios - Adding a new build rule to parse all rtf files -


xcode includes flexible build rules system. documentation non-existant however.

a project working on ios 5 , ios 6 includes rtf file. ios 6, can convert rtf file archived nsattributedstring object, load @ runtimeand display directly uitextview. ios 5, can't (without lot of work in core text...) want text without style info.

i wrote command line tool, rtftodata takes rtf file input , generates .txt file , .data file (where .data file contains version of styled text project knows how use.)

here syntax of command line tool:

rtftodata [-o] source_path [destination_path] -o (optional) overwite existing files source_path (required) path source rtf file (must have extension "rtf" or "rtf" destination_directory (optional.) writes output files source file directory if no destination specified destination_directory must exist if specified.

i want set project can add .rtf files sources (with "add target" checkbox not checked.) want xcode run rtftodata command on each file specifying output files should copied directory , added target.

ideally, i'd build process know dependencies between source .rtf files , processed .data , .txt files. if touch .rtf file, i'd build process re-run rtftodata command.

i makefile , unix scripting neophyte. think can use run script build rule this, unclear on how. guess need write script finds files of type ".rtf", pipes list of files invocation of rtftodata.

can outline steps need take in xcode ide make project handle smoothly?

as side-note, there directory can put command line tools available current version of xcode? far i've been installing rtftodata command in /library/usr/bin, i'd build tool included in project, or @ least, not have use sudo set every development machine used build project.

create custom build phase

  1. add .rtf files project , make sure added target.
  2. go target settings , select "build rules" tab:

    enter image description here

  3. click "add build rule" button @ bottom.

    enter image description here

  4. you want configure rule based on this:

    enter image description here

    enter standard wildcard glob files want match (*.rtf).

    inside script section can make use of number of environment variables. assuming glob has matched input file test.rtf have access these vars:

    • input_file_path = /path/to/your/project/source/test.rtf
    • input_file_name = test.rtf
    • input_file_base = test
    • input_file_suffix = .rtf
    • input_file_dir = /path/to/your/project/source/

    you want process file , send ${derived_files_dir} directory whatever new filename or extension need. in case take base filename input , give new extension.

    fill out "output files" section same output file used in script. ensure dependency system works , file copied .app. script run if input has changed or output file missing .app.

    note "output files" should not have double quotes. paths quoted xcode.

    if script generates multiple output files, add entries well.

once set up, .rtf files added target converted whatever output files script generates. original .rtf files not exist in final .app.

where put scripts/programs

as side-note, there directory can put command line tools available current version of xcode?

put tools somewhere below directory contains .xcproject. build phase/rules use ${srcroot} environment variable, directory containing project:

assuming file system layout:

/path/to/project/project.xcodeproj /path/to/project/tools/commandlinetool 

use in build phase/rules:

"${srcroot}/tools/commandlinetool" "${input_file_path}" ... 

remember use double-quotes everywhere can!


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -