Skip to content

Allow relative paths in output file map #63

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 1 commit into from
Feb 13, 2020

Conversation

zienag
Copy link
Contributor

@zienag zienag commented Jan 27, 2020

This allows having relative paths on output file map json file.
Also, I've made working directory to default to cwd if no -working-directory arg is supplied.
Also, there is small bug, if there is two identical inputs in output file map, driver would silently crash, as it uses Dictionary(uniqueKeysWithValues:) initializer, now it will choose last record (behaviour that usually seen in clang, for example), but is it better to have warning or error? There is some difficulty thought, as closure that handles duplicates doesn't have key as argument, so we need to find duplicates beforehand.

Also, it looks that there is a lot of dangling whitespaces, is it ok to remove them? May be e need some codestyle tool (swift-format?) that will make codestyle automated?

This is my first contribution to swift project, so any help would be very much appreciated :)

@zienag zienag requested a review from DougGregor January 27, 2020 17:33
Copy link
Contributor

@owenv owenv left a comment

Choose a reason for hiding this comment

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

Sorry it took so long to look over this! I just have a few small comments, but everything else looks good to me. Also, could you add a test for output file map resolution to SwiftDriverTests.swift?

@@ -46,7 +46,7 @@ public struct Driver {
case subcommandPassedToDriver
case relativeFrontendPath(String)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mind breaking these whitespace changes out into a separate PR? We can probably get those merged faster and they make this diff a little harder to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done #70

@@ -233,10 +233,10 @@ public struct Driver {
}

// Compute the working directory.
let cwd = localFileSystem.currentWorkingDirectory
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we necessarily want to set the cwd here if we're not overriding it. It doesn't look like the C++ driver applies the cwd to the inputs in that case, it just uses relative paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thing that bothers me here, that you can override working directory with relative path, and if you override it with . like this -working-directory=. and not override it at all, code will take completely different paths.

Do you think that instead of making all arguments absolute we need to teach code to correctly handle relative paths?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this change for now, it works only when -working-directory supplied. To work relative to cwd, further changes needed to teach code to work with relative paths.

return .absolute(.init(base, relPath))
}

fileprivate static let singleDep = VirtualPath.relative(.init(""))
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 only used once, so I think you can just inline it into the if statement above with a comment explaining what it means.

(try VirtualPath(path: input), try entry.paths.mapValues(VirtualPath.init(path:)))
})
}, uniquingKeysWith: { $1 })
Copy link
Contributor

Choose a reason for hiding this comment

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

This behavior looks good to me, and I think it's consistent with the C++ driver

@zienag zienag force-pushed the rel_paths_in_outputmap branch from a911c1d to 224d9e6 Compare February 12, 2020 16:40
@zienag zienag force-pushed the rel_paths_in_outputmap branch from 224d9e6 to bc1d31b Compare February 12, 2020 16:42
@zienag
Copy link
Contributor Author

zienag commented Feb 13, 2020

@owenv thanks for reviewing!

@DougGregor
Copy link
Member

@swift-ci please test

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

Thanks for working through this, it looks really good

@DougGregor DougGregor merged commit c835d02 into swiftlang:master Feb 13, 2020
@zienag zienag deleted the rel_paths_in_outputmap branch February 13, 2020 17:29
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