Skip to content

Conversation

@K-Tone
Copy link
Collaborator

@K-Tone K-Tone commented Apr 1, 2025

Description

Apparently, if a user project happens to already have a script with the same name as was also chosen in the Input Actions importer as the target C# file, we would silently overwrite it with auto-generated stuff and so the user might loose data.

In the comments to the case it was suggested to check if the file exists, and if it does - then only overwrite when we're sure that it's whatever we generated before. Otherwise, output an error. So that's precisely what I did here.

Testing status & QA

Local testing, added the area QA.

Overall Product Risks

  • Complexity: Low
  • Halo Effect: Low

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
    • Jira port for the next release set as "Resolved".
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

After merge:

  • Create forward/backward port if needed. If you are blocked from creating a forward port now please add a task to ISX-1444.

@K-Tone K-Tone requested review from Pauliusd01 and ritamerkl April 1, 2025 10:26
@K-Tone K-Tone changed the title Anthony/ixsb 1257 input actions overwrite FIX: Fixed Input Actions code generation overwriting user files when the names happened to match. Apr 1, 2025
@K-Tone K-Tone marked this pull request as ready for review April 1, 2025 10:30
Copy link
Collaborator

@ritamerkl ritamerkl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small nitpick, otherwise looks good! Nice to have this!

if (File.Exists(wrapperFilePath))
{
var text = File.ReadAllText(wrapperFilePath);
var autoGeneratedMarker = "This code was auto-generated by com.unity.inputsystem";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if we can utilise the string the auto generator uses as well, to avoid that this breaks in the case the string would change. I am not sure how much overhead this would entail, I am comfortable with this solution too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fast review!

This is a good point so I've checked code around just a little bit. Appears, the code generator template is declared as a constant inside a static function. It's used in just two spots, both of which specialise it with some extra data. Regardless of the specialization, it's going to include this particular string that we have right now on the PR. It feels immanent to the code logics that we would include the package name as part of it always.

Looking at it, it feels unlikely it's going to be broken any time soon. We would need to add another code generator. I guess, it's indeed more risk in the form of extra code churn if we were to use (portions) of the actual template used by generator.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking, that is fine for me!

Copy link
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix makes sense and seems to match the description.

@ekcoh
Copy link
Collaborator

ekcoh commented Apr 2, 2025

Restarted CI run since I believe the failure was just noise, CHANGELOG conflict needs to be fixed though.

@K-Tone K-Tone added the bug Issues where existsing functionality misbehaves label Apr 2, 2025
Copy link
Collaborator

@Pauliusd01 Pauliusd01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, here's what I checked:

  • User repro, when moving the input actions asset to a new folder and renaming
  • Whether error still shows up when regenerating the class (uncheck recheck the option)
  • Input actions asset itself is preserved correctly when failing to generate the code
  • Whether code generation works when it finds auto generated files with the same name like the error message describes. (I copied over info from a different asset with different names and it did overwrite it)
  • Does generated code update correctly when updating the Input Actions asset

@K-Tone K-Tone merged commit 3f65a3c into develop Apr 2, 2025
110 checks passed
@K-Tone K-Tone deleted the anthony/ixsb-1257-input-actions-overwrite branch April 2, 2025 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issues where existsing functionality misbehaves

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants