github.com/bitrise-io/go-xamarin@v0.0.0-20211005113058-bf60a8bae851/cli/build.go (about) 1 package cli 2 3 import ( 4 "fmt" 5 6 "time" 7 8 "github.com/bitrise-io/go-utils/log" 9 "github.com/bitrise-io/go-xamarin/builder" 10 "github.com/bitrise-io/go-xamarin/constants" 11 "github.com/bitrise-io/go-xamarin/tools/buildtools" 12 "github.com/urfave/cli" 13 ) 14 15 func buildCmd(c *cli.Context) error { 16 solutionPth := c.String(solutionFilePathKey) 17 solutionConfiguration := c.String(solutionConfigurationKey) 18 solutionPlatform := c.String(solutionPlatformKey) 19 buildToolName := c.String(buildToolKey) 20 21 fmt.Println() 22 log.Infof("Config:") 23 log.Printf("- solution: %s", solutionPth) 24 log.Printf("- configuration: %s", solutionConfiguration) 25 log.Printf("- platform: %s", solutionPlatform) 26 log.Printf("- build-tool: %s", buildToolName) 27 28 if solutionPth == "" { 29 return fmt.Errorf("missing required input: %s", solutionFilePathKey) 30 } 31 if solutionConfiguration == "" { 32 return fmt.Errorf("missing required input: %s", solutionConfigurationKey) 33 } 34 if solutionPlatform == "" { 35 return fmt.Errorf("missing required input: %s", solutionPlatformKey) 36 } 37 38 buildTool := buildtools.Msbuild 39 if buildToolName == "xbuild" { 40 buildTool = buildtools.Xbuild 41 } 42 43 buildHandler, err := builder.New(solutionPth, nil, buildTool) 44 if err != nil { 45 return cli.NewExitError(err.Error(), 1) 46 } 47 48 fmt.Println() 49 log.Infof("Building all projects in solution: %s", solutionPth) 50 51 callback := func(solutionName string, projectName string, sdk constants.SDK, testFramwork constants.TestFramework, commandStr string, alreadyPerformed bool) { 52 if projectName != "" { 53 fmt.Println() 54 log.Infof("Building project: %s", projectName) 55 log.Donef("$ %s", commandStr) 56 if alreadyPerformed { 57 log.Warnf("build command already performed, skipping...") 58 } 59 fmt.Println() 60 } 61 } 62 63 startTime := time.Now() 64 65 warnings, err := buildHandler.BuildAllProjects(solutionConfiguration, solutionPlatform, true, nil, callback) 66 for _, warning := range warnings { 67 log.Warnf(warning) 68 } 69 if err != nil { 70 return cli.NewExitError(err.Error(), 1) 71 } 72 73 endTime := time.Now() 74 75 fmt.Println() 76 log.Infof("Collecting generated outputs") 77 78 outputMap, err := buildHandler.CollectProjectOutputs(solutionConfiguration, solutionPlatform, startTime, endTime) 79 if err != nil { 80 return err 81 } 82 83 for projectName, projectOutput := range outputMap { 84 fmt.Println() 85 log.Infof("%s outputs:", projectName) 86 87 for _, output := range projectOutput.Outputs { 88 log.Donef("%s: %s", output.OutputType, output.Pth) 89 } 90 } 91 92 return nil 93 }