Fetch values from remote during tuist generate

Question or problem

As far as I understand, the environment during tuist generate is sandboxed and has no internet access, so I cannot do a url connection to fetch some configuration values from my server.

Expectation

Have a proper way to do a url request to a remote server to fetch a json.

Context

  • Tuist version: 4.68.0

I have a project that contains multiple apps based on a white labeled app. Each app has some configuration values which I am injecting in its plist file.
Right now I am manually entering these values in the .xcconfig file of its app.
I would like to automate this by injecting them during the tuist generate process. To do that I need to fetch them from a remote server whose json response will contain them.
But unfortunately it seems that the environment of tuist generate is sandboxed and I cannot fetch them (I get hostname not found on my url requests).
What is a proper way of doing this with Tuist?

Reproduction (mandatory for problems)

Include a reproducible project and steps to reproduce the issue. If you have logs, include them too.

Hey :waving_hand:

While you can disable the sandbox, it’s not what we’d recommend doing. Reaching out to network can make the compilation of the manifests slow. Additionally, we cache the manifests based on the contents of the file – and the caching of the manifests will not produce deterministic results if you depend on accessing the network.

If you want to load some JSON files from the internet, I’d recommend running a script pre-generation that will load these JSON files into .swift files that you can then put into the ProjectDescriptionHelpers (and thus let Tuist load these as any other file, without disabling sandbox).

If you use mise, you can use the concept of tasks to wrap tuist generate and run your script before. But you can also use a basic shell script.

Hope this helps :crossed_fingers:

1 Like