-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
RevEng: Canonicalizing output paths #3959
Conversation
@namespace += "." + CSharpUtilities.Instance.GenerateCSharpIdentifier(pathPart, null); | ||
Check.NotEmpty(canonicalizedFullOutputPath, nameof(canonicalizedFullOutputPath)); | ||
|
||
CanonicalizedFullOutputPath = canonicalizedFullOutputPath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why repeat the words of the name of the class in each property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change them.
I might be wrong, but a quick look at the change gives me the impression that something simpler could work and be more maintainable. I would the usual reviewers for thus area to chip in though. Cc @natemcmaster, @bricelam |
@lajones note that the Travis build for this PR is failing. @natemcmaster noticed last night that it seems to be a legitimate issue with the PR. Apparently either something in the new path handling logic or on one of the new tests doesn't work well in non-Windows platforms. |
@divega - feel free to suggest. The only thing I've found that canonicalizes is Path.GetFullPath(). And this algorithm was already in use to produce the namespace - I've just adapted it so we can use it both for the output paths and the namespace. I would have preferred out params and skipping the |
The failing test on Linux is:
|
{ | ||
Check.NotEmpty(rootNamespace, nameof(rootNamespace)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this check intentionally removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope - well spotted. Will put back in.
@natemcmaster re Linux test: typo on my end. Should be fixed with commit c698808. Let me know if not. |
: canonicalizedFullOutputPath.StartsWith(canonicalizedFullProjectPath) | ||
? canonicalizedFullOutputPath | ||
.Substring(canonicalizedFullProjectPath.Count() + 1) | ||
: null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not completely sure if this is the same, but this looks almost the same as Uri.MakeRelativeUri
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried Uri
stuff a while back. Don't remember exactly what the problem was now but would rather keep full control over what we are doing.
// canonicalizedOutputPath is outside of project - so just use root namespace | ||
return rootNamespace; | ||
foreach (var pathPart in canonicalizedRelativeOutputPath | ||
.Split(directorySeparatorChars, StringSplitOptions.RemoveEmptyEntries)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use Uri.Segments
to make this more x-plat safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm. It seems to be passing on both Linux and Windows platforms already? I'd rather not complicate it unless I have to.
Per @divega about simplifying, here are a few suggestions:
|
@natemcmaster @divega actually I agree it could return a Re Re overall simplicity: |
Agreed. Anonymous types or private type instead? A public type adds API surface for something that isn't an API.
I still suggest splitting. From a design perspective, constructing a namespace and canonicalizing paths are separate responsibilities. Avoiding a precondition check is not reason enough to push them together.
Make it |
@natemcmaster Happy to do internal. And will see what I can do to make |
… match where the source code has been moved to.
Have updated it so the class |
Discussed in person with @lajones. We will keep the function and it's datatype internal. |
Checked in with commit 036140f. |
Fix for #3830. For Scaffold-DbContext we send back a list of the paths to the generated files to powershell so that it can update the VS project to include them in the project. When the output directory looked like ".\Models" we were sending back filenames like "X:\Project\Path.\Models\MyEntity.cs". The extra "." was being interpreted by the VS AddFromFile() API as a real part of the name of the file. This fixes that by canonicalizing the name of the path before it get sent back so that the above now becomes "X:\Project\Path\Models\MyEntity.cs".