pushup icon indicating copy to clipboard operation
pushup copied to clipboard

The -codegen-only flag does not generate cmd code.

Open dvogel opened this issue 1 year ago • 1 comments

When using the pushup build -codegen-only flag the _runtime/cmd/main.go templating is not performed. So you get different results from:

pushup build

versus

pushup build -codegen-only
cd build
go build

An example:

$ pushup new thing1
$ cd thing1
$ pushup build

        //                                                                  
     //  //      //////                        //                           
                //    //  //    //    //////  //////    //    //  //////    
               //////    //    //  ////      //    //  //    //  //    //   
              //        //    //      ////  //    //  //    //  //    //    
             //          //////  //////    //    //    //////  //////       
                                                              //            
                                                             //             
$ tree build
build
├── app.go
├── bin
│   └── myproject
├── cmd
│   └── myproject
│       └── main.go
├── default.layout.up.go
├── index.up.go
├── pushup_support.go
├── src
│   └── pages
│       └── index.up
└── static
    ├── htmx.min.js
    └── style.css
$ rm -rf build
$ pushup build -codegen-only

        //                                                                  
     //  //      //////                        //                           
                //    //  //    //    //////  //////    //    //  //////    
               //////    //    //  ////      //    //  //    //  //    //   
              //        //    //      ////  //    //  //    //  //    //    
             //          //////  //////    //    //    //////  //////       
                                                              //            
                                                             //             
$ (cd build && go build)
$ tree build
build
├── app.go
├── default.layout.up.go
├── index.up.go
├── pushup_support.go
├── src
│   └── pages
│       └── index.up
└── static
    ├── htmx.min.js
    └── style.css

dvogel avatar Oct 01 '24 21:10 dvogel

Good catch - the runtime main I consider not codegen per se (as in lowering Pushup markup to Go code) and more a "linking" step but that's confusing. Ultimately I want that stuff to be part of an API library that only requires the thinnest main.go wrapper.

paulsmith avatar Oct 01 '24 21:10 paulsmith

I think separating these steps into commands where you can stop just short of the next one makes sense to facilitate different use cases. However, I think regardless of what you call the steps, what is missing today is a step that gives you the complete source go just before go build is run. In my case I'm trying to deploy this to Google App Engine with the gcloud utility. I need to avoid the generated code being inside the source directory and also provide the application to GAE as a module, allowing it to make assumptions about the binary name and thus start it up correctly. To make it work I am:

  1. Clearing my own build dir with rm -rf gae && mkdir -p gae.
  2. Having pushup do codegen with cd src && pushup build -codegen-only -project thesignup -out-dir ../gae/build .
  3. Bringing the module definitions into the build dir with cp src/go.mod src/go.sum gae. This allows Google's Cloud Build to replicate the same dependency management I'm doing locally. If I use pushup build this bit is missed.
  4. Interpolating the cmd runtime code as my own main.go with sed -e 's#[{][{][.]ProjectPkg[}][}]#adhoc/thesignup/build#' ../../pushup/_runtime/cmd/main.go > gae/main.go. This is what makes the binary match the module name, in line with App Engine's expectations.
  5. Doing a build locally as Cloud Build would do it in order to get representative errors more quickly: cd gae && go build
  6. Copying my GAE app definition into the build dir with cp app.yaml gae. This will eventually be generated based on go.mod since the golang version declarations need to match.
  7. And finally deploying with cd gae && gcloud app deploy app.yaml

It seems like the current -codegen-only is targeting the use case where the pushup-generated code is embedded in another application. I want to generate the source for a standalone application but let Cloud Build build it, which is where the module requirement comes into play.

dvogel avatar Oct 15 '24 21:10 dvogel

I see now. Thanks for writing out those steps. There's very simple fix for this for the current version of Pushup.

paulsmith avatar Oct 16 '24 17:10 paulsmith