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

refactor: More directory layout refactoring #14007

Merged
merged 2 commits into from
Dec 17, 2024

Conversation

jskeet
Copy link
Collaborator

@jskeet jskeet commented Dec 16, 2024

No description provided.

@jskeet jskeet requested a review from amanda-tarafa December 16, 2024 12:42
@jskeet jskeet requested a review from a team as a code owner December 16, 2024 12:42
@@ -383,7 +382,7 @@ private int ExecuteForUnconfigured(string[] args)
private void GenerateUnconfigured(string arg)
{
Console.WriteLine($"{DateTime.UtcNow:yyyy-MM-dd'T'HH:mm:ss.fff}Z Generating {arg}");
var apiDirectory = Path.Combine(_rootLayout.GeneratorOutput, arg);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is deliberately a change btw - it was broken before. (It should have been relative to _rootLayout.Googleapis.)

Copy link
Contributor

@amanda-tarafa amanda-tarafa left a comment

Choose a reason for hiding this comment

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

Approving but there's a bug on one of the snippets source properties, I've flagged it there.

Otherwise, the only thing I'm not certain about is the sepration in two of ApiLayout. I understand the need to use one or the other of repo-root and output, but other than that I don't understand why we'd need the distinction. And the using of one root or the other can be solved with factory methods. But, I know I might be missing something, so this is not a blocker for me.


// Type just to allow us to write a constructor that is obviously geared towards help snippets,
// and ensure that the calling code is clear too.
private sealed class HelpSnippetsMarker { }
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Or magic word like "help" received as id?

Copy link
Contributor

Choose a reason for hiding this comment

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

"help" is actually used below for deciding on which factory method to call.

Although I see it goes throug ApiLayou which would have to understand "help" as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I've basically been trying to localize magic, as it were - being explicit in code where possible.

/// <summary>
/// Directory for snippets for the library, including hand-written snippets.
/// </summary>
public string SnippetsDirectory => Path.Combine(SourceDirectory, $"{Id}.GeneratedSnippets");
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't suggest, but this one shouldn't have the "Generated" part.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, thanks.

public string GeneratedSnippetsDirectory => Path.Combine(SourceDirectory, $"{Id}.GeneratedSnippets");

/// <summary>
/// Directory for purely generated snippets for the library.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Update after copy/paste

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

public string UnitTestsDirectory => Path.Combine(SourceDirectory, $"{Id}.Tests");

/// <summary>
/// Directory for purely generated snippets for the library.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Update after copy/paste

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

/// </summary>
public class ApiLayout
public class RepositoryApiLayout
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this one inherit from GeneratorApiLayout so that a lot of the properties don't need to be redefined? both root and output should be the same on the repo, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could they even go back to being be the same type ApiLayout with two factory methods each choosing the right of ReposirotyRoot and GeneratorOutput?

var sourceRoot = rootLayout.CreateApiLayout(options.Package).SourceDirectory;
file = Path.Combine(sourceRoot, options.Package, "bin", "Release", options.Framework, $"{options.Package}.dll");
var productionRoot = rootLayout.CreateRepositoryApiLayout(options.Package).ProductionDirectory;
file = Path.Combine(rootLayout.CreateRepositoryApiLayout(options.Package).GetReleaseAssembly(options.Framework));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you don't need Path.Combine anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you create a single RepositoryApiLayout and reuse in both lines?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup, it's much smaller now.

@@ -564,6 +563,9 @@ bool HasApis(string file)
}
}

private string GetApiProtosDirectory(ApiMetadata api) => GetApiProtosDirectory(api.ProtoPath);
Copy link
Contributor

Choose a reason for hiding this comment

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

ApiLayout? Or in the two that replaced it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, that doesn't know the path to the protos for the API (and can't, if we've just provided an ID).

@jskeet
Copy link
Collaborator Author

jskeet commented Dec 16, 2024

Thanks - will fix the comments in the morning.

This may change further, but it's a cleaner separation of what most tooling needs vs doc-specific tooling.
@jskeet jskeet force-pushed the more-directory-layout branch 2 times, most recently from ae60d83 to a0b0ddf Compare December 17, 2024 08:04
@jskeet
Copy link
Collaborator Author

jskeet commented Dec 17, 2024

Approving but there's a bug on one of the snippets source properties, I've flagged it there.

Otherwise, the only thing I'm not certain about is the sepration in two of ApiLayout. I understand the need to use one or the other of repo-root and output, but other than that I don't understand why we'd need the distinction. And the using of one root or the other can be solved with factory methods. But, I know I might be missing something, so this is not a blocker for me.

Separating the two into different types with different properties makes it less likely that someone will use the wrong one. For example, because GeneratorApiLayout doesn't have CreateDocsLayout, you can't accidentally try to use the generator layout (which is incapable of building docs) when you need anything about docs. In the other direction, if you're using anything about "tweaks" but you're expecting a full repo, then there's probably something wrong. (Obviously we can add properties if we really need to.)

Copy link
Contributor

@amanda-tarafa amanda-tarafa left a comment

Choose a reason for hiding this comment

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

Yep, looks good, thanks!

Building requires a full repo; generation requires only generator output/input directories.

This is also the first pass of centralising knowledge of things like "the production source directory".
At this point most *directories* are standardised; we could potentially start moving knowledge of filenames (e.g. OwlBot configuratoin etc) - if we see significant benefit.
@jskeet jskeet force-pushed the more-directory-layout branch from a0b0ddf to c870250 Compare December 17, 2024 08:11
@jskeet jskeet merged commit 172b218 into googleapis:main Dec 17, 2024
9 checks passed
@jskeet jskeet deleted the more-directory-layout branch December 17, 2024 08:15
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.

2 participants