@@ -915,7 +915,6 @@ func doXgo(cmdline []string) {
915915 env := build .Env ()
916916
917917 if * xtarget == "" || strings .Contains (* xtarget , "*" ) {
918- // TODO: not sure about this, limiting xgo to a single target, but it lets us manage the output to a target-based folder
919918 log .Println ("must supply a single xgo build target for cross-compliation" )
920919 os .Exit (1 )
921920 }
@@ -931,31 +930,48 @@ func doXgo(cmdline []string) {
931930 build .MustRun (gogetxgo )
932931
933932 for _ , cmd := range debExecutables {
933+
934+ exeOutDir := filepath .Join (outDir , cmd .BinaryName + "_folder" )
935+ os .MkdirAll (filepath .Join (exeOutDir , "github.com" , "darcys22" ), os .ModePerm )
934936 xgoArgs := append (buildFlags (env ), flag .Args ()... )
935937 xgoArgs = append (xgoArgs , []string {"--targets" , * xtarget }... )
936- xgoArgs = append (xgoArgs , []string {"--dest" , outDir }... )
938+ xgoArgs = append (xgoArgs , []string {"--dest" , exeOutDir }... )
937939 xgoArgs = append (xgoArgs , "-v" )
938- xgoArgs = append (xgoArgs , "./" + cmd .BinaryName ) // relative package name (assumes we are inside GOPATH)
940+ xgoArgs = append (xgoArgs , []string {"--pkg" , cmd .BinaryName }... )
941+ xgoArgs = append (xgoArgs , "." )
939942 xgo := xgoTool (xgoArgs )
940943 build .MustRun (xgo )
941944
942- // strip the suffix out of the binary name
943- // TODO: add this ability into xgo
944- filepath .Walk (outDir , func (path string , info os.FileInfo , err error ) error {
945+ // move the executables to the build directory
946+ filepath .Walk (exeOutDir , func (path string , info os.FileInfo , err error ) error {
945947 if info .IsDir () {
946948 return nil // skip
947949 }
948950
949- suffix := filepath .Base (filepath .Dir (path ))
950- if strings .HasPrefix (info .Name (), cmd .BinaryName ) && strings .Contains (info .Name (), suffix ) {
951- newName := strings .Replace (info .Name (), "-" + suffix , "" , 1 )
952- newPath := filepath .Join (filepath .Dir (path ), newName )
951+ if strings .Contains (info .Name (), "godbledger" ) {
952+ newPath := filepath .Join (outDir , cmd .BinaryName )
953953 log .Println ("renaming:" , path )
954954 log .Println (" to:" , newPath )
955- os .Rename (path , newPath )
955+ err := os .Rename (path , newPath )
956+ if err != nil {
957+ log .Fatal (err )
958+ }
956959 }
957960 return nil
958961 })
962+
963+ // Delete the temporary folders made
964+ files , err := os .ReadDir (outDir )
965+ if err != nil {
966+ log .Fatal (err )
967+ }
968+
969+ for _ , file := range files {
970+ if file .IsDir () {
971+ log .Println ("deleting:" , file .Name ())
972+ os .RemoveAll (filepath .Join (outDir , file .Name ()))
973+ }
974+ }
959975 }
960976}
961977
0 commit comments