Skip to content

PackageModel: relative paths for cross-compilation destinations #5812

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 5 commits into from
Nov 15, 2022

Conversation

MaxDesiatov
Copy link
Contributor

@MaxDesiatov MaxDesiatov commented Oct 14, 2022

Depends on #5871.

This introduces support for relative paths in v2 scheme of destination.json files. The path is then normalized relative to the location of destination.json file.

Motivation:

Currently, destination.json files only support absolute paths, which makes it hard to move cross-compilation sysroots between directories and copying them to different machines.

Modifications:

struct DestinationInfo is renamed to DestinationInfoV1. New struct DestinationInfoV2 is added to handle the new version that supports relative paths. This is also used as an opportunity to make the schema more consistent with manifests for artifact bundles, in which properties use camelCase instead of dash-case naming. Also new in schema version 2 are linkerFlags and renaming of extraCPPFlags to extraCXXFlags, to follow up on #5827 and #5837.

Added tests to verify that both schema versions are parsed correctly and that relative paths in V2 are correctly expanded to absolute paths.

Result:

New version of destination.json files can be supplied as a --destination option passed to swift build.

As a result, it's to move cross-compilation sysroots and their corresponding destination.json files between different directories on the same filesystem, or even between different machines.

if isRelative {
return directory.appending(RelativePath(string))
} else {
return AbsolutePath(string)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should use AbsolutePath(validating:)

@MaxDesiatov MaxDesiatov force-pushed the maxd/destination-relative-path branch from 103ed52 to d678992 Compare October 14, 2022 21:10
Copy link
Contributor

@stevapple stevapple left a comment

Choose a reason for hiding this comment

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

Is there any reason we cannot add it in v1 scheme? Supporting relative paths looks like a pure addition.

@MaxDesiatov
Copy link
Contributor Author

This PR is still a draft, there highly likely will be incompatible changes in future commits.

@tomerd tomerd added the WIP Work in progress label Oct 17, 2022
@MaxDesiatov MaxDesiatov force-pushed the maxd/destination-relative-path branch from d678992 to b5ae29e Compare October 21, 2022 15:57
// Check schema version.
guard version.version == 1 else {
if version.version == 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

use switch?

return directory.appending(RelativePath(string))
} else {
return try AbsolutePath(validating: string)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

iirc the absolute path constructor already takes care of it? @neonichu ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yah, init(validating:, relativeTo:) should do the same thing, I believe

@MaxDesiatov MaxDesiatov force-pushed the maxd/destination-relative-path branch 2 times, most recently from b42b666 to 29f73b4 Compare November 2, 2022 17:20
@MaxDesiatov

This comment was marked as outdated.

@MaxDesiatov MaxDesiatov force-pushed the maxd/destination-relative-path branch from c5ad2a6 to ae196db Compare November 2, 2022 18:37
@MaxDesiatov
Copy link
Contributor Author

@swift-ci please smoke test

@MaxDesiatov MaxDesiatov force-pushed the maxd/destination-relative-path branch from ae196db to 07efc00 Compare November 3, 2022 14:53
@MaxDesiatov MaxDesiatov changed the base branch from main to maxd/destination-properties November 3, 2022 14:53
@MaxDesiatov MaxDesiatov force-pushed the maxd/destination-relative-path branch from f9da45f to 8e3c204 Compare November 3, 2022 15:09
@MaxDesiatov MaxDesiatov marked this pull request as ready for review November 3, 2022 15:09
@MaxDesiatov
Copy link
Contributor Author

@swift-ci please test

@MaxDesiatov MaxDesiatov removed the WIP Work in progress label Nov 3, 2022
Base automatically changed from maxd/destination-properties to main November 4, 2022 10:55
This introduces support for relative paths in v2 scheme of `destination.json` files. The path is then normalized relative to the location of `destination.json` files. As a result, it makes it easier for moving cross-compilation sysroots between different directories on the same filesystem, or even between different machines.
@MaxDesiatov MaxDesiatov force-pushed the maxd/destination-relative-path branch from 02c9ff2 to b997076 Compare November 4, 2022 10:57
@MaxDesiatov
Copy link
Contributor Author

@swift-ci please smoke test

@MaxDesiatov
Copy link
Contributor Author

@swift-ci please smoke test

@tomerd
Copy link
Contributor

tomerd commented Nov 14, 2022

@MaxDesiatov is this ready to be merged?

@MaxDesiatov
Copy link
Contributor Author

MaxDesiatov commented Nov 15, 2022

I'm waiting for #5876 to be merged, otherwise this PR will cause conflicts in that one. Unless @neonichu is fine with the conflicts? Or if I could rebase his PR myself after I merge this one? IDK how much more #5876 is going to take though.

@MaxDesiatov
Copy link
Contributor Author

After double-checking, it seems both PRs don't overlap on specific lines, although Destination.swift is modified in both. I'll go ahead and merge this one.

@MaxDesiatov MaxDesiatov merged commit 5378f8d into main Nov 15, 2022
@MaxDesiatov MaxDesiatov deleted the maxd/destination-relative-path branch November 15, 2022 11:52
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.

4 participants