MobileNativeFoundation / rules_xcodeproj

Bazel rules for generating Xcode projects.
MIT License
525 stars 84 forks source link

Feature Request: Support provisioning of code snippets in generated Xcode projects #499

Open cgrindel opened 2 years ago

cgrindel commented 2 years ago

Some companies/projects provide shared code snippets checked in to source control. Right now, we perform a separate step to copy the code snippets to the appropriate location.

  cp -R \
    "${SRC_ROOT}/CodeSnippets/." \
    "${HOME}/Library/Developer/Xcode/UserData/CodeSnippets"

Granted this request is slightly orthogonal to the generation of the project. However, the generation of the project does provide a nice signal to copy the shared code snippets.

Options

  1. Do nothing and suggest clients wrap calls to the project generation in a shell script which does whatever is necessary to provision the development environment.
  2. Do nothing and suggest clients use a multirun rule to execute the project generation and run a target that copies the code snippets.
  3. Add an attribute listing the code snippets that should be copied to the user's Library directory.
  4. Provide attributes that allow a client to specify pre- and post- install hooks. The installer would then run them in the specified order before and after the installation. (NOTE: This is really just incorporating option 2 into rules_xcodeproj.)
cgrindel commented 2 years ago

Having thought about it a bit more, I tend to think that option 2 or 4 might be the best path forward. It reduces the complexity, but allows the entire operation to be handled by a single Bazel run command.

brentleyjones commented 2 years ago

To support multiple Xcode configurations (i.e. Release and Profile in addition to Debug) we will probably need a wrapper script around the bazel run invocation, to be able to capture some arbitrary bazel flags (though this isn't guaranteed yet).

To properly support Focused Projects we will also recommend a wrapper script around the bazel run invocation, as one will need to do some level of meta programming to generate changes to one or more .bzl files.

Since code snippets don't exist in the .xcodeproj bundle, I feel this ties into that wrapper script. I recommend creating a simple wrapper, per option 1, for now. We will need to get further along in the implementation of the previously mentioned features before we will know what our example wrapper script will look like (or if we will have a wrapper script creator, or a canonical one, or ...).

brentleyjones commented 2 years ago

We now have a wrapper script in the form of the "runner". It's not too customizable right now, but we now also support pretty arbitrary config via configs in .bazelrc or .xcodeproj.bazelrc or even command-line arguments.

I think it would be fine to add more customization into what happens in the runner. A design document would be nice, but a well fleshed out PR works as well.