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

fix: use shared .ftl folder for stubs #1843

Merged
merged 7 commits into from
Jul 4, 2024
Merged

Conversation

wesbillman
Copy link
Collaborator

@wesbillman wesbillman commented Jun 20, 2024

Fixes #1662
Fixes #1827

@ftl-robot ftl-robot mentioned this pull request Jun 21, 2024
Copy link
Collaborator

@alecthomas alecthomas left a comment

Choose a reason for hiding this comment

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

I imagine we don't really need tests, because if this wasn't working, all of our integration tests would fail.

.gitignore Outdated
**/testdata/**/_ftl
**/examples/**/_ftl
**/testdata/**/.ftl
**/examples/**/.ftl
**/_ftl
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove these, they were deliberately not present because they exclude the same name in templates.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I added the equivalent of what we had before with _ftl but maybe I'm missing something. I reordered these a bit to group them as well.

Copy link
Collaborator

@alecthomas alecthomas Jun 21, 2024

Choose a reason for hiding this comment

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

**/_ftl and **/.ftl, shouldn't be there. It's the reason why your new template dir is missing. They need to be removed.

Edit: sorry, I removed **/_ftl a while back but it looks like someone added it back in

Copy link
Collaborator

Choose a reason for hiding this comment

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

But let's remove them now!


meta, ok := e.moduleMetas.Load(module)
if !ok {
return fmt.Errorf("Module %q not found", module)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: errors shouldn't be upper cased

@@ -16,7 +16,7 @@ func TestEngine(t *testing.T) {
t.SkipNow()
}
ctx := log.ContextWithNewDefaultLogger(context.Background())
engine, err := buildengine.New(ctx, nil, []string{"testdata/alpha", "testdata/other", "testdata/another"})
engine, err := buildengine.New(ctx, nil, t.TempDir(), []string{"testdata/alpha", "testdata/other", "testdata/another"})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a heads up that t.TempDir() will create a new tempdir each time it's called. Just make sure that's what you want.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had to look that up while I was working on this :)

Replace map[string]string `short:"r" help:"Replace a module import path with a local path in the initialised FTL module." placeholder:"OLD=NEW,..." env:"FTL_INIT_GO_REPLACE"`
Dir string `arg:"" help:"Directory to initialize the module in."`
Name string `arg:"" help:"Name of the FTL module to create underneath the base directory."`
GoVersion string
Copy link
Collaborator

Choose a reason for hiding this comment

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

Delete

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added this one so that it could be used in the scaffolding template since that uses newGoCmd directly as it's context. Would it be better to create a new context and add what I need there for the template instead of using the newGoCmd for template context?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, if you need it in the context but it's not a flag, it shouldn't be in the flag struct.

@@ -87,14 +93,15 @@ func (b ExternalModuleContext) NonMainModules() []*schema.Module {
return modules
}

const buildDirName = "_ftl"
const buildDirName = ".ftl"
const DefaultGoModVersion = "1.21"
Copy link
Collaborator

Choose a reason for hiding this comment

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

There should never be a need for something like this, we should always pull the Go version from the module's go.mod file.

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 was something I wanted to chat about. With this new shared setup, I'm not sure which version to use here. Given that we might be generating shared modules for multiple modules. Or in the initial case we're generating shared modules for just builtins so I don't have a go version to get from a module. In the other cases we're very likely generating a single shared .ftl/go/modules for a multiple modules, so I wasn't sure which go version to use there either.

The big one is the builtins though. That's what led to me adding this here, but it felt dirty for sure. I also added this central one so we could share it with the cmd_new.go go code that was using a hardcoded version in it's template.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah good question. In that case we should use the highest version.

@@ -58,6 +60,8 @@ func (i newGoCmd) Run(ctx context.Context) error {

logger := log.FromContext(ctx)
logger.Debugf("Creating FTL Go module %q in %s", name, path)

i.GoVersion = compile.DefaultGoModVersion
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should never be needed, either pull it from the go.mod file or if that's really not possible, from the go tool itself.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah maybe we should use the go tool for this one too. Before this change the version was hard coded in the template.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah yes this is for ftl new - in that case it should definitely use the Go tool.

@@ -8,9 +8,14 @@ import (
"github.com/TBD54566975/ftl/internal"
)

func mainWorkTemplateFiles() *zip.Reader {
return internal.ZipRelativeToCaller("main-work-template")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see these files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ahh maybe a .gitignore issue. I'll fix. Thanks!

@@ -1,9 +1,9 @@
module ftl/{{ .Name }}

go 1.21
Copy link
Collaborator

Choose a reason for hiding this comment

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

OMG I wonder if this is the source of all those bugs we've seen ...

@wesbillman wesbillman force-pushed the generate-shared-stubs branch from 80a8da6 to b6a7150 Compare June 21, 2024 18:22
.gitignore Outdated
buildengine/.gitignore
go.work*
junit*.xml
/readme-tests
**/_ftl
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one shouldn't have been there.

.gitignore Outdated
**/testdata/**/_ftl
**/examples/**/_ftl
**/testdata/**/.ftl
**/examples/**/.ftl
**/_ftl
Copy link
Collaborator

Choose a reason for hiding this comment

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

But let's remove them now!

@alecthomas
Copy link
Collaborator

Let's not forget about this, looking forward to it!

@wesbillman wesbillman force-pushed the generate-shared-stubs branch 6 times, most recently from 73fbaa0 to b975a47 Compare July 2, 2024 19:14
@wesbillman wesbillman marked this pull request as ready for review July 2, 2024 19:42
@wesbillman wesbillman requested review from a team and worstell and removed request for a team July 2, 2024 19:42
@wesbillman wesbillman force-pushed the generate-shared-stubs branch from b975a47 to 9ba22ba Compare July 3, 2024 21:08
@wesbillman wesbillman force-pushed the generate-shared-stubs branch from 9ba22ba to caf6be9 Compare July 3, 2024 21:16
Copy link
Collaborator

@alecthomas alecthomas left a comment

Choose a reason for hiding this comment

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

Absolutely mammoth effort, thanks Wes :)

@alecthomas alecthomas merged commit 0a69db1 into main Jul 4, 2024
45 checks passed
@alecthomas alecthomas deleted the generate-shared-stubs branch July 4, 2024 10:03
matt2e added a commit that referenced this pull request Jul 8, 2024
matt2e added a commit that referenced this pull request Jul 8, 2024
wesbillman added a commit that referenced this pull request Jul 8, 2024
wesbillman added a commit that referenced this pull request Jul 8, 2024
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.

Rename _ftl directory to .ftl Codegen all known modules, not just dependencies
2 participants