Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/go-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version: '1.22'

- name: Test
run: go test -v ./...
run: go generate ./... && go test -v ./...

- name: Build for Linux
run: CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o ut2u-linux-amd64 .
Expand Down
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,52 @@ Configure your AWS credentials similarily to the `upload` command.
```
ut2u redirect sync -b my.bucket -p ut2-redirect/ System/UT2004.ini
```


## Build

The build command simplifies the build process by isolating the package
definitions into a separate ini.

**The UCC compiler only works on Windows.**

```
$ ut2u build -h
Build a UT2004 Mutator/Mod

Usage:
ut2u build [pkg-path...]

Flags:
-d, --dep strings Dependency
-h, --help help for build
```

If no package path is defined, then it assumes the package is the current
working directory.

```
$ ut2u build
```

If your package requires another package, then you may pass in `-d pkg` to
include that package as a dependency. This does not build the dependency, it
only includes them so there must be a compiled `*.u` file in the `System`
directory.

```
$ ut2u build -d UTComp
```

To build multiple packages when developing in parallel, pass each one as
separate arguments.

```
$ ut2u build ../WSUTComp .

# If at the root directory:
$ ut2u build WSUTComp WS3SPN
```

Note that dependencies must be listed in order. For example, `WS3SPN` dependes
on `WSUTComp`, therefore `WSUTComp` must come first.
93 changes: 93 additions & 0 deletions cmd/build/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package build

import (
"context"
"fmt"
"os"
"os/signal"
"path/filepath"

"github.com/spf13/cobra"

"github.com/aldehir/ut2u/pkg/build"
)

var deps []string

var buildCommand = &cobra.Command{
Use: "build [pkg-path...]",
Short: "Build a UT2004 Mutator/Mod",
RunE: doBuild,
DisableFlagsInUseLine: true,
}

func EnrichCommand(cmd *cobra.Command) {
cmd.AddCommand(buildCommand)
}

func init() {
buildCommand.Flags().StringSliceVarP(&deps, "dep", "d", []string{}, "Dependency")
}

func doBuild(cmd *cobra.Command, args []string) error {
var err error
var packages []string

cwd, err := os.Getwd()
if err != nil {
return err
}

if len(args) == 0 {
// If no arguments, assume cwd is the package path
path, err := filepath.Abs(cwd)
if err != nil {
return fmt.Errorf("error resolving path %s: %w", cwd, err)
}

packages = append(packages, path)
} else {
for _, arg := range args {
path, err := filepath.Abs(arg)
if err != nil {
return fmt.Errorf("error resolving path %s: %w", arg, err)
}
packages = append(packages, path)
}
}

if len(packages) == 0 {
return fmt.Errorf("no packages defined")
}

// Assume the root path is the parent of the package path
root := filepath.Dir(packages[0])
fmt.Printf("Root: %s\n", root)

builder, err := build.NewBuilder(root)
if err != nil {
return err
}

// Add any explicit dependencies
for _, dep := range deps {
err := builder.AddDependency(dep)
if err != nil {
return err
}
}

// Add package to build
for _, pkg := range packages {
name := filepath.Base(pkg)
err := builder.AddPackage(name)
if err != nil {
return err
}
}

ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()

return builder.Build(ctx)
}
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"github.com/spf13/cobra"

"github.com/aldehir/ut2u/cmd/build"
"github.com/aldehir/ut2u/cmd/query"
"github.com/aldehir/ut2u/cmd/redirect"
"github.com/aldehir/ut2u/cmd/upackage"
Expand All @@ -20,6 +21,7 @@ func init() {
redirect.EnrichCommand(rootCmd)
upackage.EnrichCommand(rootCmd)
query.EnrichCommand(rootCmd)
build.EnrichCommand(rootCmd)
}

func Execute() error {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/aldehir/ut2u

go 1.20
go 1.21

require (
github.com/aws/aws-sdk-go-v2 v1.21.0 // indirect
Expand Down
Loading