Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
fix(config): update template name after specifying double precision (#…
Browse files Browse the repository at this point in the history
…145)

* fix(template): handle name update when compiling with double precision

* fix(config): correctly update name after assigning default architecture
  • Loading branch information
coffeebeats authored Apr 8, 2024
1 parent 250e94e commit 241837a
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 19 deletions.
3 changes: 1 addition & 2 deletions cmd/gdbuild/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@ func exportProject( //nolint:funlen,ireturn
return nil, err
}

templateName := template.Name(rc.Platform, tl.Arch, rc.Profile)
xp.PathTemplate = osutil.Path(filepath.Join(pathTmp, templateName))
xp.PathTemplate = osutil.Path(filepath.Join(pathTmp, tl.Name))

hasTarget, err := store.HasTarget(storePath, cs)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/config/common/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (t Template) Collect(src engine.Source, rc *run.Context) *template.Template
},
},
ExtraArtifacts: nil,
Name: template.Name(rc.Platform, t.Arch, rc.Profile, config.Dereference(t.DoublePrecision)),
Paths: nil,
Prebuild: t.Hook.PreActions(rc),
Postbuild: t.Hook.PostActions(rc),
Expand Down
1 change: 1 addition & 0 deletions pkg/config/linux/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (t *Template) Collect(g engine.Source, rc *run.Context) *template.Template
if t.Arch == platform.ArchUnknown {
out.Arch = platform.ArchAmd64
out.Builds[0].Arch = platform.ArchAmd64
out.Name = template.Name(rc.Platform, out.Arch, rc.Profile, out.Builds[0].DoublePrecision)
}

scons := &out.Builds[0].SCons
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/macos/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (t *Template) Collect(g engine.Source, rc *run.Context) *template.Template

out.Arch = t.Arch
out.Builds[0].Platform = platform.OSMacOS
out.Name = template.Name(rc.Platform, out.Arch, rc.Profile, out.Builds[0].DoublePrecision)

scons := &out.Builds[0].SCons
if config.Dereference(t.Vulkan.Dynamic) {
Expand Down Expand Up @@ -80,6 +81,7 @@ func (t *Template) Collect(g engine.Source, rc *run.Context) *template.Template
platform.OSMacOS,
platform.ArchUniversal,
rc.Profile,
config.Dereference(t.DoublePrecision),
)

cmdLipo := &action.Process{
Expand All @@ -105,6 +107,7 @@ func (t *Template) Collect(g engine.Source, rc *run.Context) *template.Template
out := t.Template.Collect(g, rc)

out.Arch = platform.ArchUniversal
out.Name = templateNameUniversal

// Register the additional artifact.
out.ExtraArtifacts = append(out.ExtraArtifacts, templateNameUniversal)
Expand Down
31 changes: 19 additions & 12 deletions pkg/config/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestBuildTemplate(t *testing.T) {
Profile: engine.ProfileDebug,
},
},
Name: "godot.linuxbsd.template_debug.x86_64",
Paths: nil,
Prebuild: nil,
Postbuild: nil,
Expand All @@ -105,6 +106,7 @@ func TestBuildTemplate(t *testing.T) {
godot.version = "4.0.0"
[template.platform.macos]
double_precision = true
vulkan = { sdk_path = "$TEST_TMPDIR/vulkan" }`,
},

Expand All @@ -119,10 +121,11 @@ func TestBuildTemplate(t *testing.T) {
Arch: platform.ArchUniversal,
Builds: []template.Build{
{
Arch: platform.ArchAmd64,
Source: engine.Source{Version: mustParseVersion(t, "4.0.0")},
Platform: platform.OSMacOS,
Profile: engine.ProfileDebug,
Arch: platform.ArchAmd64,
DoublePrecision: true,
Source: engine.Source{Version: mustParseVersion(t, "4.0.0")},
Platform: platform.OSMacOS,
Profile: engine.ProfileDebug,
SCons: template.SCons{
ExtraArgs: []string{
"use_volk=no",
Expand All @@ -131,10 +134,11 @@ func TestBuildTemplate(t *testing.T) {
},
},
{
Arch: platform.ArchArm64,
Source: engine.Source{Version: mustParseVersion(t, "4.0.0")},
Platform: platform.OSMacOS,
Profile: engine.ProfileDebug,
Arch: platform.ArchArm64,
DoublePrecision: true,
Source: engine.Source{Version: mustParseVersion(t, "4.0.0")},
Platform: platform.OSMacOS,
Profile: engine.ProfileDebug,
SCons: template.SCons{
ExtraArgs: []string{
"use_volk=no",
Expand All @@ -143,7 +147,8 @@ func TestBuildTemplate(t *testing.T) {
},
},
},
ExtraArtifacts: []string{"godot.macos.template_debug.universal"},
ExtraArtifacts: []string{"godot.macos.template_debug.double.universal"},
Name: "godot.macos.template_debug.double.universal",
Paths: []osutil.Path{osutil.Path(filepath.Join(tmp, "vulkan"))},
Prebuild: nil,
Postbuild: &action.Process{
Expand All @@ -152,10 +157,10 @@ func TestBuildTemplate(t *testing.T) {
Args: []string{
"lipo",
"-create",
"godot.macos.template_debug.x86_64",
"godot.macos.template_debug.arm64",
"godot.macos.template_debug.double.x86_64",
"godot.macos.template_debug.double.arm64",
"-output",
"godot.macos.template_debug.universal",
"godot.macos.template_debug.double.universal",
},
},
},
Expand Down Expand Up @@ -194,6 +199,7 @@ func TestBuildTemplate(t *testing.T) {
Profile: engine.ProfileDebug,
},
},
Name: "godot.windows.template_debug.x86_64.exe",
ExtraArtifacts: []string{"godot.windows.template_debug.x86_64.console.exe"},
},
got,
Expand Down Expand Up @@ -256,6 +262,7 @@ func TestBuildTemplate(t *testing.T) {
},
},
ExtraArtifacts: []string{"godot.windows.template_debug.x86_64.console.exe"},
Name: "godot.windows.template_debug.x86_64.exe",
Paths: []osutil.Path{image},
},
got,
Expand Down
1 change: 1 addition & 0 deletions pkg/config/windows/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (t *Template) Collect(g engine.Source, rc *run.Context) *template.Template
if t.Arch == platform.ArchUnknown {
out.Arch = platform.ArchAmd64
out.Builds[0].Arch = platform.ArchAmd64
out.Name = template.Name(rc.Platform, out.Arch, rc.Profile, out.Builds[0].DoublePrecision)
}

scons := &out.Builds[0].SCons
Expand Down
21 changes: 16 additions & 5 deletions pkg/godot/template/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,31 @@ func EncryptionKeyFromEnv() string {
// Filename returns the base name of the export template generated by this
// 'Binary' specification.
func (b *Build) Filename() string {
return Name(b.Platform, b.Arch, b.Profile)
return Name(b.Platform, b.Arch, b.Profile, b.DoublePrecision)
}

/* ----------------------------- Function: Name ----------------------------- */

// Name returns the base name of the export template defined by the
// specified parameters.
func Name(pl platform.OS, arch platform.Arch, pr engine.Profile) string {
name := fmt.Sprintf("godot.%s.%s.%s", pl, pr.TargetName(), arch)
func Name(pl platform.OS, arch platform.Arch, pr engine.Profile, double bool) string {
var name strings.Builder

name.WriteString("godot")
name.WriteString("." + pl.String())
name.WriteString("." + pr.TargetName())

if double {
name.WriteString(".double")
}

name.WriteString("." + arch.String())

if pl == platform.OSWindows {
name += ".exe"
name.WriteString(".exe")
}

return name
return name.String()
}

/* -------------------------- Method: SConsCommand -------------------------- */
Expand Down
4 changes: 4 additions & 0 deletions pkg/godot/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ type Template struct {
// the artifacts pertaining to 'Builds' do not need to be specified.
ExtraArtifacts []string `hash:"ignore"`

// Name is the base name of the resulting export template. This exists for
// convenience when exporting.
Name string `hash:"ignore"`

// Paths is a list of additional files and folders which this template
// depends on. Useful for recording dependencies which are defined in
// otherwise opaque properties like 'Hook'.
Expand Down

0 comments on commit 241837a

Please sign in to comment.