Xcode: Create a dependency between one file and another

310 Views Asked by At

We are using a custom compiler to compile some resources for our project. These resources are text-based and have a .ink extension. We are using a custom Build Rule for these ink files. (see footnote if you're interested in what they are!)

Our ink compiler takes a root ink file, which can have include statements for other ink files. So, within the Xcode project, we only include the root ink file, so that it doesn't attempt to compile the child ink files independently.

However, we now have the problem that if you change one of the child ink files, Xcode doesn't know to recompile the parent.

Is there some kind of custom build script we could do that would automatically touch the root file if any of the children are modified? Or some kind of dependency we could set up? (Currently we touch the root file every build, but this will become far too slow as the project grows)

We really don't want to have to change the way the ink compiler works in order to do this!

p.s. if you're interested in what the heck these ink files are: They're story files - we develop text based narrative games for iOS.

2

There are 2 best solutions below

0
On

If you select your project in Xcode and go to "Build Phases" you can add shell scripts to the build process of your app. Maybe this could be a good start for checking if your ink files need to recompile.

More infos here: Running a Script While Building a Product

0
On

I ended up creating a custom makefile, and then creating a "Run Script" build phase, which called make in the directory that held the ink files.

I don't know much about makefiles, but here's what I cobbled together based on online tutorials:

ALL_CHILD_INK = subdir/*.ink
FINAL_FILENAME = root_filename

$(FINAL_FILENAME).json: $(FINAL_FILENAME).ink $(ALL_CHILD_INK)
    ink_compiler $< $@

Essentially, it's a simple makefile that ensures that all the child files are dependencies for the main root file.