Skip to content

TSCBasic: repair the Windows build after #277 #282

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

Merged
merged 2 commits into from
Jan 14, 2022
Merged

Conversation

compnerd
Copy link
Member

This fixes multiple issues with the file locking implementation on
Windows. AbsolutePath.root is meaningless on Windows - there is
no concept of a singular root on Windows, instead you have have 26
individual roots - A-Z. Stripping the count of characters for the
root path leaves us with an invalid path string as the root drives
have been stripped. The next character is an invalid character on
most file systems, and so we must replace :. Instead of using a
MAX_NAME to compute a length of the ARC, enforce a limit for the
complete path (though an ARC would be limited to 255 codepoints on
NTFS). This incidentally also corrects the emitted path, previous
path computation left us with the file in PWD.

@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd
Copy link
Member Author

@abertelrud I think that this is mostly similar to #281 but missing the changes you found on the test suite, but it has the additional file name generation fix. I think that we need part of your change still, a part of this change, and a part of another change to get this fully correct.

@abertelrud
Copy link
Contributor

@abertelrud I think that this is mostly similar to #281 but missing the changes you found on the test suite, but it has the additional file name generation fix. I think that we need part of your change still, a part of this change, and a part of another change to get this fully correct.

Thanks for this! Right, at least the unit test's use of NAME_MAX needs to be conditioned out (I updated that PR while you were putting up this one).

@compnerd
Copy link
Member Author

I should be more explicit: I don't know how to do this M&A exercise - any thoughts on how to accomplish this the most effective way?

@abertelrud
Copy link
Contributor

I am not sure about the origins of the original AbsolutePath.root but it was there already. So I guess there's a silver lining here in that there are some non-Windows-compatible runtime issues being addressed.

@abertelrud
Copy link
Contributor

I should be more explicit: I don't know how to do this M&A exercise - any thoughts on how to accomplish this the most effective way?

I think we should proceed with this PR but just put in the conditional from #281 to skip that part of the unit test.

@compnerd
Copy link
Member Author

Once the dust from these changes settles, I believe that #278 also needs to be updated.

@abertelrud
Copy link
Contributor

abertelrud commented Jan 13, 2022

Once the dust from these changes settles, I believe that #278 also needs to be updated.

Yes, absolutely.

.components.joined(separator: "_")
.replacingOccurrences(of: ":", with: "_") + ".lock"
#if os(Windows)
var lockFileUTF8 = lockFilesDirectory.appending(component: lockFileName).pathString.utf8.suffix(Int(MAX_PATH))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is supposed to be just the filename, so lockFilesDirectory gets prepended again below.

Copy link
Contributor

Choose a reason for hiding this comment

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

This means you'll end up with lockFilesDirectory twice.

Looking at this more, I think the part about AbsolutePath.root was try avoid pasting something that starts with / as a subpath. I kept that part unmodified but it seems odd, since the file name should never have that in the first place.

My view is that we should just compute a SHA1 of the whole path, whatever it is, and then use that as the filename. But it's true that it would be less readable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see: With non-Windows file paths, the components returns a / as the first path component. So this is just stripping that out.

Taking a step back, I think what would make sense here would be to take just the components leading from the root of the path (whether that's / or C:\ or whatever) and just using those as the basis for the filename. All this is trying to do is to come up with a unique file name.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an API to return just the path and not the root?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would be better, however, I think that this new version should address the path issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there an API to return just the path and not the root?

I don't believe that there is such an API in the TSC Path API today.

This fixes multiple issues with the file locking implementation on
Windows.  `AbsolutePath.root` is meaningless on Windows - there is
no concept of a singular root on Windows, instead you have have 26
individual roots - A-Z.  Stripping the count of characters for the
root path leaves us with an invalid path string as the root drives
have been stripped.  The next character is an invalid character on
most file systems, and so we must replace `:`.  Instead of using a
`MAX_NAME` to compute a length of the ARC, enforce a limit for the
complete path (though an ARC would be limited to 255 codepoints on
NTFS).  This incidentally also corrects the emitted path, previous
path computation left us with the file in PWD.
@abertelrud
Copy link
Contributor

These new changes look good to me. The only thing left is to conditionalize the unit test which references NAME_MAX (but doesn't really need to — it could just be 255).

@abertelrud
Copy link
Contributor

Then any kind of exceeding of PATH_MAX could be done in a separate PR.

@compnerd
Copy link
Member Author

@swift-ci please test

@abertelrud
Copy link
Contributor

Thanks for helping to deal with this and sorry it landed on you unexpected. I didn't realize this would have a Windows effect, and I never was able to get Swift up and running in a Windows VM (it's not really feasible to manually test all changes in a separate Windows VM locally anyway)

@compnerd
Copy link
Member Author

I'd like to keep the authorship information for the changes to the test case (you noticed that and fixed it) which is why I haven't folded that into this change.

@abertelrud
Copy link
Contributor

I'd like to keep the authorship information for the changes to the test case (you noticed that and fixed it) which is why I haven't folded that into this change.

We need that, though, I think for this to pass? I certainly don't mind folding it in here, unless you specifically want to disavow it. :) But the fix is actually different — now that the Windows side is fixed too, through your changes, I think it makes sense to not conditionalize the unit test but just put the constant 255 instead of NAME_MAX there. Since it's just constructing test strings by repeating a phrase.

@abertelrud
Copy link
Contributor

abertelrud commented Jan 13, 2022

I'd like to keep the authorship information for the changes to the test case (you noticed that and fixed it) which is why I haven't folded that into this change.

We need that, though, I think for this to pass? I certainly don't mind folding it in here, unless you specifically want to disavow it. :) But the fix is actually different — now that the Windows side is fixed too, through your changes, I think it makes sense to not conditionalize the unit test but just put the constant 255 instead of NAME_MAX there. Since it's just constructing test strings by repeating a phrase.

So what do you suggest as the next step here? I think the only thing missing in this PR is NAME_MAX -> 255 in the unit test.

After that I'll update #278

@compnerd
Copy link
Member Author

I don't mind at all if you push your bits of the changes to this change at all, I just care about the authorship information :)

@abertelrud
Copy link
Contributor

I don't mind at all if you push your bits of the changes to this change at all, I just care about the authorship information :)

Ok, I see, so to check out your branch and add a commit to it? Happy to do that. I think the current CI will fail if we don't, right? This PR still doesn't build on Windows IIUC?

@compnerd
Copy link
Member Author

I've built it on Windows locally, and been able to use the generated TSCBasic.dll to run swift-build, so I expect that this should be okay.

@abertelrud
Copy link
Contributor

I've built it on Windows locally, and been able to use the generated TSCBasic.dll to run swift-build, so I expect that this should be okay.

Ok, sounds good. Did you build the unit tests on Windows too? Because I don't see how those would compile.

@compnerd
Copy link
Member Author

Ok, sounds good. Did you build the unit tests on Windows too? Because I don't see how those would compile.

I did not, which is why I never noticed that.

@abertelrud
Copy link
Contributor

Ok, I added a commit to your branch in your fork, so the attribution information should be correct.

@abertelrud
Copy link
Contributor

@swift-ci please test

@compnerd
Copy link
Member Author

Thanks @abertelrud!

@abertelrud
Copy link
Contributor

Thanks @compnerd for your fixes here, and sorry about now having to restart the tests. Meanwhile we should get @tomerd's signoff, and then I will update #278.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants