Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soft dependency support for resources #2920

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

r3ps4J
Copy link

@r3ps4J r3ps4J commented Nov 9, 2024

Goal of this PR

This PR adds support for soft dependencies, indicated by the manifest entries soft_dependency and soft_dependencies. Soft dependencies only get started if they exist, making it possible to add optional dependencies to a resource. This is useful when a resource can work fine without a dependency, but can benefit from having access to that dependency.

See the proposal on the forum for more details: https://forum.cfx.re/t/soft-dependencies-for-resources/5281288/1

How is this PR achieving the goal

This PR implements soft dependencies by loading them the same way as normal dependencies, but if one is missing or fails to start it skips it and continues to the next one. It also still prints the same information as with regular dependencies, and only tries to load the soft dependencies after the hard dependencies have been checked and loaded to prevent starting them when the resource can't start anyway.

This PR specifically adds the const bool soft = false parameter to the loadDeps function. The paramter has a default value of false, to remain backwards compatible. When soft is set to true the following things are different as opposed to loading hard dependencies:

  • Constraints are not checked, as having optional constraints makes little sense.
  • When a soft dependency is not found, the loop continues instead of returning false early to stop the resource from loading.
  • The soft dependency does not get stored in resourceDependants, as stopping the soft dependency should not prevent the resource from running.
  • When a soft dependency fails to start, the loop continues instead of returning false early to stop the resource from loading and storing the dependency in resourceDependencies to start it later.

This PR applies to the following area(s)

This applies to the server and clients. The changes were made in citizen-resources-core.

Successfully tested on

The changes were tested on the server and FiveM client.

Game builds: b3095

Platforms: Windows

Checklist

  • Code compiles and has been tested successfully.
  • Code explains itself well and/or is documented.
  • My commit message explains what the changes do and what they are for.
  • No extra compilation warnings are added by these changes.

Fixes issues

None.

Adds support for soft dependencies, indicated by the manifest entries
`soft_dependency` and `soft_dependencies`. Soft dependencies only get
started if they exist, making it possible to add optional dependencies
to a resource.
@github-actions github-actions bot added the triage Needs a preliminary assessment to determine the urgency and required action label Nov 9, 2024
@r3ps4J r3ps4J marked this pull request as ready for review November 9, 2024 21:36
@github-actions github-actions bot added invalid Requires changes before it's considered valid and can be (re)triaged and removed triage Needs a preliminary assessment to determine the urgency and required action labels Nov 9, 2024
@r3ps4J r3ps4J deleted the branch citizenfx:master November 11, 2024 09:00
@r3ps4J r3ps4J closed this Nov 11, 2024
@r3ps4J r3ps4J deleted the master branch November 11, 2024 09:00
@r3ps4J r3ps4J restored the master branch November 11, 2024 09:01
@r3ps4J
Copy link
Author

r3ps4J commented Nov 11, 2024

Okay I wanted to rename the branch on my repo, but github doesn't seem to like it.

@r3ps4J r3ps4J reopened this Nov 11, 2024
@r3ps4J r3ps4J deleted the branch citizenfx:master November 11, 2024 09:04
@r3ps4J r3ps4J closed this Nov 11, 2024
@r3ps4J r3ps4J deleted the master branch November 11, 2024 09:04
@r3ps4J r3ps4J restored the master branch November 11, 2024 09:05
@r3ps4J r3ps4J reopened this Nov 11, 2024
@github-actions github-actions bot added triage Needs a preliminary assessment to determine the urgency and required action invalid Requires changes before it's considered valid and can be (re)triaged and removed invalid Requires changes before it's considered valid and can be (re)triaged triage Needs a preliminary assessment to determine the urgency and required action labels Nov 11, 2024
@Nobelium-cfx
Copy link
Contributor

Thank you for the contribution!

I understand the motivation behind this PR and the code looks reasonable. But I don't have enough context to make the final call on if it's actually needed. @prikolium-cfx WDYT?

@prikolium-cfx
Copy link
Collaborator

Thank you for the contribution!

I understand the motivation behind this PR and the code looks reasonable. But I don't have enough context to make the final call on if it's actually needed. @prikolium-cfx WDYT?

Should be discussed together with team. Can't say right now pros and cons of such decision

@prikolium-cfx prikolium-cfx added manual-review PRs that need manual review and work before merging. and removed invalid Requires changes before it's considered valid and can be (re)triaged labels Nov 12, 2024
Adds single quotes around resource names in dependency loading traces
to clarify what is part of the resource name.
@r3ps4J
Copy link
Author

r3ps4J commented Nov 12, 2024

Sounds good! I added some quotes around the resource names to clarify what is and what is not part of the resource names. This also makes it match the other traces in the dependency loader.

@github-actions github-actions bot added the invalid Requires changes before it's considered valid and can be (re)triaged label Nov 12, 2024
@r3ps4J
Copy link
Author

r3ps4J commented Nov 28, 2024

@prikolium-cfx any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Requires changes before it's considered valid and can be (re)triaged manual-review PRs that need manual review and work before merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants