Skip to content
Merged
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
12 changes: 9 additions & 3 deletions cuecfg/cuecfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func Marshal(valuePtr any, extension string) ([]byte, error) {
return marshalYaml(valuePtr)
case ".toml":
return marshalToml(valuePtr)
case ".xml", ".csproj":
case ".xml":
return marshalXML(valuePtr)
}
return nil, errors.Errorf("Unsupported file format '%s' for config file", extension)
Expand All @@ -52,7 +52,7 @@ func Unmarshal(data []byte, extension string, valuePtr any) error {
return errors.WithStack(err)
}
return nil
case ".xml", ".csproj":
case ".xml":
err := unmarshalXML(data, valuePtr)
if err != nil {
return errors.WithStack(err)
Expand All @@ -78,12 +78,18 @@ func InitFile(path string, valuePtr any) (bool, error) {
}

func ParseFile(path string, valuePtr any) error {
return ParseFileWithExtension(path, filepath.Ext(path), valuePtr)
}

// ParserFileWithExtension lets the caller override the extension of the `path` filename
// For example, project.csproj files should be treated as having extension .xml
func ParseFileWithExtension(path string, ext string, valuePtr any) error {
data, err := os.ReadFile(path)
if err != nil {
return errors.WithStack(err)
}

return Unmarshal(data, filepath.Ext(path), valuePtr)
return Unmarshal(data, ext, valuePtr)
}

func WriteFile(path string, value any) error {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright 2022 Jetpack Technologies Inc and contributors. All rights reserved.
// Use of this source code is governed by the license in the LICENSE file.

package csharp
package dotnet

import (
"fmt"
"strings"

"github.com/pkg/errors"
Expand All @@ -17,13 +18,17 @@ type Project struct {
} `xml:"PropertyGroup,omitempty"`
}

const CSharpExtension = "csproj"
const FSharpExtension = "fsproj"

// The .Net Planner supports C# and F# languages.
type Planner struct{}

// Implements interface Planner (compile-time check)
var _ plansdk.Planner = (*Planner)(nil)

func (p *Planner) Name() string {
return "csharp.Planner"
return "dotnet.Planner"
}

func (p *Planner) IsRelevant(srcDir string) bool {
Expand All @@ -32,15 +37,19 @@ func (p *Planner) IsRelevant(srcDir string) bool {
// We should log that an error has occurred.
return false
}
return a.HasAnyFile("*.csproj")
isRelevant := a.HasAnyFile(
fmt.Sprintf("*.%s", CSharpExtension),
fmt.Sprintf("*.%s", FSharpExtension),
)
return isRelevant
}

func (p *Planner) GetPlan(srcDir string) *plansdk.Plan {
plan, err := p.getPlan(srcDir)
if err != nil {
// Added this Printf because `devbox shell` was silently swallowing this error.
// TODO savil. Have `devbox shell` error out or print it instead.
// fmt.Printf("error in getPlan: %s\n", err)
fmt.Printf("error in getPlan: %+v\n", err)
plan = &plansdk.Plan{}
plan.WithError(err)
}
Expand Down Expand Up @@ -98,14 +107,22 @@ func project(srcDir string) (*Project, error) {
// We should log that an error has occurred.
return nil, err
}
paths := a.GlobFiles("*.csproj")
paths := a.GlobFiles(
fmt.Sprintf("*.%s", CSharpExtension),
fmt.Sprintf("*.%s", FSharpExtension),
)
if len(paths) < 1 {
return nil, errors.Errorf("expected to find a .csproj file in directory %s", srcDir)
return nil, errors.Errorf(
"expected to find a %s or %s file in directory %s",
CSharpExtension,
FSharpExtension,
srcDir,
)
}
projectFilePath := paths[0]

proj := &Project{}
err = cuecfg.ParseFile(projectFilePath, proj)
err = cuecfg.ParseFileWithExtension(projectFilePath, ".xml", proj)
return proj, err
}

Expand Down
1 change: 1 addition & 0 deletions planner/languages/dotnet/fsharp_planner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package dotnet
4 changes: 2 additions & 2 deletions planner/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"go.jetpack.io/devbox/planner/languages/clojure"
"go.jetpack.io/devbox/planner/languages/cplusplus"
"go.jetpack.io/devbox/planner/languages/crystal"
"go.jetpack.io/devbox/planner/languages/csharp"
"go.jetpack.io/devbox/planner/languages/dart"
"go.jetpack.io/devbox/planner/languages/deno"
"go.jetpack.io/devbox/planner/languages/dotnet"
"go.jetpack.io/devbox/planner/languages/elixir"
"go.jetpack.io/devbox/planner/languages/erlang"
"go.jetpack.io/devbox/planner/languages/fsharp"
Expand Down Expand Up @@ -41,7 +41,7 @@ var PLANNERS = []plansdk.Planner{
&clojure.Planner{},
&cplusplus.Planner{},
&crystal.Planner{},
&csharp.Planner{},
&dotnet.Planner{},
&dart.Planner{},
&deno.Planner{},
&elixir.Planner{},
Expand Down
2 changes: 2 additions & 0 deletions testdata/fsharp/fsharp-hello-world/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/
obj/
12 changes: 12 additions & 0 deletions testdata/fsharp/fsharp-hello-world/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// For more information see https://aka.ms/fsharp-console-apps

[<EntryPoint>]
let main args =
let dotNetVersion = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription
printfn "Installed version is %A" dotNetVersion

let expectedVersionPrefix = ".NET 6"
if (not (dotNetVersion.StartsWith(expectedVersionPrefix))) then
raise (System.Exception(sprintf "Expected version %A but got version %A" expectedVersionPrefix dotNetVersion))
else
0
6 changes: 6 additions & 0 deletions testdata/fsharp/fsharp-hello-world/devbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"packages": [],
"shell": {
"init_hook": null
}
}
13 changes: 13 additions & 0 deletions testdata/fsharp/fsharp-hello-world/fsharp-hello-world.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>fsharp_hello_world</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>

</Project>
24 changes: 24 additions & 0 deletions testdata/fsharp/fsharp-hello-world/plan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"dev_packages": [
"dotnet-sdk"
],
"runtime_packages": [
"dotnet-sdk"
],
"install_stage": {
"command": ""
},
"build_stage": {
"command": "dotnet publish",
"input_files": [
"."
]
},
"start_stage": {
"command": "dotnet run",
"input_files": [
"."
]
},
"definitions": null
}