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

Fix artifact/symlink mismatch detection #15700

Closed
wants to merge 2 commits into from

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Jun 18, 2022

The check in ActionMetadataHandler that an output declared to be a
symlink is indeed created as a symlink by the action was ineffective as
it would only run if a stat of the output showed that is already was a
symlink. The test only passed by accident since it runs sandboxed and
the sandbox setup would call Path.readSymbolicLink on what it expects to
be a symlink. As this does not happen on Windows, the test correctly
fails there.

This is fixed by calling Path.readSymbolicLink on the output path of
an expected symlink and handling errors appropriately rather
than
assuming the type returned by stat matches the artifact type (file vs symlink).

With this issue fixed, bazel_symlink_test can be enabled on Windows with
the following test-only changes:

  • Pass --windows_enable_symlinks as a startup option.
  • Use relative instead of absolute symlink targets as these have
    consistent shape under Unix and Windows.
  • Use python to create symlinks rather than ln -s, which doesn't seem
    to be able to create unresolved symlinks on Windows.

Work towards #10298

@fmeum fmeum force-pushed the unresolved-symlinks-windows branch 2 times, most recently from 73ff93a to 8f5d597 Compare June 19, 2022 16:00
@fmeum fmeum force-pushed the unresolved-symlinks-windows branch 2 times, most recently from bf0e72e to fcef379 Compare June 29, 2022 16:11
@fmeum fmeum changed the title TEMP: Unresolved symlinks windows Fix artifact/symlink mismatch detection Jun 29, 2022
@fmeum fmeum marked this pull request as ready for review June 29, 2022 16:33
@fmeum
Copy link
Collaborator Author

fmeum commented Jun 29, 2022

@lberki Could you take a look? This should handle the Windows part of #10298 and fixes an actual bug along the way.

@sgowroji sgowroji added team-Core Skyframe, bazel query, BEP, options parsing, bazelrc awaiting-review PR is awaiting review from an assigned reviewer labels Jun 30, 2022
@fmeum
Copy link
Collaborator Author

fmeum commented Jun 30, 2022

@coeuvre Could you take over the review while @lberki is OOO?

@fmeum
Copy link
Collaborator Author

fmeum commented Jul 12, 2022

@coeuvre Friendly ping

@haxorz haxorz requested a review from alexjski July 25, 2022 14:23
@fmeum fmeum force-pushed the unresolved-symlinks-windows branch from fcef379 to 31618be Compare July 28, 2022 09:57
@fmeum fmeum force-pushed the unresolved-symlinks-windows branch from 13caa68 to 9700359 Compare July 28, 2022 13:46
The check in ActionMetadataHandler that an output declared to be a
symlink is indeed created as a symlink by the action was ineffective as
it would only run if a stat of the output showed that is already was a
symlink. The test only passed by accident since it runs sandboxed and
the sandbox setup would call Path.readSymbolicLink on what it expects to
be a symlink. As this does not happen on Windows, the test correctly
fails there.

This is fixed by calling Path.readSymbolicLink on the output path of an
expected symlink before rather than after stat-ing it and trusting the
file type contained in the stat info.

With this issue fixed, bazel_symlink_test can be enabled on Windows with
the following test-only changes:
* Pass --windows_enable_symlinks as a startup option.
* Use relative instead of absolute symlink targets as these have
  consistent shape under Unix and Windows.
* Use python to create symlinks rather than `ln -s`, which doesn't seem
  to be able to create unresolved symlinks on Windows.
@fmeum fmeum force-pushed the unresolved-symlinks-windows branch from 9700359 to 0e43c7c Compare July 28, 2022 13:47
@fmeum fmeum force-pushed the unresolved-symlinks-windows branch 2 times, most recently from d6e4aaf to bf04a68 Compare July 28, 2022 22:02
@fmeum fmeum force-pushed the unresolved-symlinks-windows branch from bf04a68 to 8cbf26a Compare July 28, 2022 22:07
# We use python rather than a simple ln since the latter doesn't handle dangling symlinks on
# Windows.
mkdir -p symlink_helper
cat > symlink_helper/BUILD <<EOF
Copy link
Contributor

@alexjski alexjski Jul 29, 2022

Choose a reason for hiding this comment

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

nit: 'EOF' is generally preferred unless you need variable substitution. If you are OK with this, I am happy to change that as part of the import process.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Could you take care of it? I'm on mobile atm. Thanks!

@alexjski
Copy link
Contributor

Another minor edit could be useful in the commit message:

This is fixed by calling Path.readSymbolicLink on the output path of an
expected symlink before rather than after stat-ing it and trusting the
file type contained in the stat info.

I think we established that trusting stat output is actually OK, it's just that we didn't look whether it matches the expectation, not that it cannot be used.

@@ -370,25 +357,35 @@ def _a_impl(ctx):
)
return DefaultInfo(files = depset([output]))

a = rule(implementation = _a_impl, attrs = {"link_target": attr.string()})
a = rule(
implementation = _a_impl,
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI: I will remove the trailing space from this line as part of importing this change. You can delete that yourself if you prefer.

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!

@fmeum
Copy link
Collaborator Author

fmeum commented Jul 29, 2022

Another minor edit could be useful in the commit message:

This is fixed by calling Path.readSymbolicLink on the output path of an
expected symlink before rather than after stat-ing it and trusting the
file type contained in the stat info.

I think we established that trusting stat output is actually OK, it's just that we didn't look whether it matches the expectation, not that it cannot be used.

I updated the PR description and am fine with you taking care of the nits.

Thanks for the review!

@alexjski
Copy link
Contributor

Another minor edit could be useful in the commit message:

This is fixed by calling Path.readSymbolicLink on the output path of an
expected symlink before rather than after stat-ing it and trusting the
file type contained in the stat info.

I think we established that trusting stat output is actually OK, it's just that we didn't look whether it matches the expectation, not that it cannot be used.

I updated the PR description and am fine with you taking care of the nits.

Thanks for the review!

more nitting in the new sentence I would replace "trusting" with something like "assuming the type matches the artifact type (file vs symlink)."

@fmeum
Copy link
Collaborator Author

fmeum commented Jul 29, 2022

Changed. Not sure I wrapped the lines correctly though, so maybe reflow the text during the import.

@alexjski
Copy link
Contributor

Changed. Not sure I wrapped the lines correctly though, so maybe reflow the text during the import.

Thank you! FYI, I am in the process of merging that internally now. All tests passed, so looking good. Will update the PR once it is merged. Thank you so much for creating this change (and enduring my nitpicking)! It was a pleasure to work with you on that!

@copybara-service copybara-service bot closed this in 666fce5 Aug 1, 2022
@alexjski
Copy link
Contributor

alexjski commented Aug 1, 2022

The change was merged in 666fce5. Thank you for the contribution!

@ShreeM01 ShreeM01 removed the awaiting-review PR is awaiting review from an assigned reviewer label Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Core Skyframe, bazel query, BEP, options parsing, bazelrc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants