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
30 changes: 29 additions & 1 deletion build/docker/debian.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,35 @@ RUN apt -y update && apt -y install ca-certificates && \
python3-pip \
openjdk-17-jdk

RUN dotnet --version && go version
# Install Swift toolchain for Swift Package Manager resolution in CI.
ARG SWIFT_VERSION="6.3.3"
ENV SWIFTLY_HOME_DIR="/root/.local/share/swiftly"
ENV PATH="$SWIFTLY_HOME_DIR/bin:$PATH"
RUN apt -y update && apt -y install --no-install-recommends \
clang \
curl \
libcurl4 \
libedit2 \
libgcc-s1 \
libncurses6 \
libpython3-dev \
libsqlite3-0 \
libstdc++6 \
libxml2 \
libz3-4 \
pkg-config \
tar \
xz-utils \
zlib1g && \
curl -O https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz && \
tar zxf swiftly-$(uname -m).tar.gz && \
./swiftly init --quiet-shell-followup && \
. "${SWIFTLY_HOME_DIR:-$HOME/.local/share/swiftly}/env.sh" && \
swiftly install "$SWIFT_VERSION" && \
swiftly use "$SWIFT_VERSION" && \
rm -f swiftly swiftly-$(uname -m).tar.gz

RUN dotnet --version && go version && swift --version

RUN apt update -y && \
apt install lsb-release apt-transport-https ca-certificates software-properties-common -y && \
Expand Down
1 change: 1 addition & 0 deletions internal/file/exclusion.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var defaultExclusions = DefaultExclusionList{
"obj", // nuget
"bower_components", // bower
".vscode-test", // excluding testing framework
".build", // swiftpm checkouts and build artifacts
},
}

Expand Down
1 change: 1 addition & 0 deletions internal/file/exclusion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestExclusionsWithEmptyTokenEnvVariable(t *testing.T) {
"**/obj/**",
"**/bower_components/**",
"**/.vscode-test/**",
"**/.build/**",
}
defaultExclusions := Exclusions()
assert.Equal(t, gt, defaultExclusions)
Expand Down
7 changes: 7 additions & 0 deletions internal/file/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,14 @@ func (finder *Finder) GetSupportedFormats() ([]*CompiledFormat, error) {
LockFileRegexes: []string{""},
}

swiftEntry := &Format{
ManifestFileRegex: "^Package\\.swift$",
DocumentationUrl: "https://docs.debricked.com/overview/language-support/swift",
LockFileRegexes: []string{"^Package\\.resolved$", "^\\.spm\\.debricked\\.lock$"},
}

formats = append(formats, sbtEntry)
formats = append(formats, swiftEntry)

var compiledDependencyFileFormats []*CompiledFormat
for _, format := range formats {
Expand Down
2 changes: 2 additions & 0 deletions internal/resolution/pm/pm.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/debricked/cli/internal/resolution/pm/poetry"
"github.com/debricked/cli/internal/resolution/pm/pub"
"github.com/debricked/cli/internal/resolution/pm/sbt"
"github.com/debricked/cli/internal/resolution/pm/swift"
"github.com/debricked/cli/internal/resolution/pm/uv"
"github.com/debricked/cli/internal/resolution/pm/yarn"
)
Expand All @@ -38,5 +39,6 @@ func Pms() []IPm {
composer.NewPm(),
sbt.NewPm(),
pub.NewPm(),
swift.NewPm(),
}
}
1 change: 1 addition & 0 deletions internal/resolution/pm/pm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func TestPms(t *testing.T) {
"gradle",
"composer",
"pub",
"swift",
}

for _, pmName := range pmNames {
Expand Down
63 changes: 63 additions & 0 deletions internal/resolution/pm/swift/cmd_factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package swift

import (
"os"
"os/exec"
"path/filepath"
)

const (
resolveCmd = "resolve"
showDeps = "show-dependencies"
)

type ICmdFactory interface {
MakeResolveCmd(manifestFile string) (*exec.Cmd, error)
MakeDepsCmd(manifestFile string) (*exec.Cmd, error)
}

type IExecPath interface {
LookPath(file string) (string, error)
}

type ExecPath struct{}

func (_ ExecPath) LookPath(file string) (string, error) {
return exec.LookPath(file)
}

type CmdFactory struct {
execPath IExecPath
}

func (cmdf CmdFactory) MakeResolveCmd(manifestFile string) (*exec.Cmd, error) {
swiftPath, err := cmdf.execPath.LookPath("swift")
if err != nil {
return nil, err
}

workingDir := filepath.Dir(filepath.Clean(manifestFile))

return &exec.Cmd{
Path: swiftPath,
Args: []string{"swift", "package", resolveCmd},
Dir: workingDir,
Env: os.Environ(),
}, nil
}

func (cmdf CmdFactory) MakeDepsCmd(manifestFile string) (*exec.Cmd, error) {
swiftPath, err := cmdf.execPath.LookPath("swift")
if err != nil {
return nil, err
}

workingDir := filepath.Dir(filepath.Clean(manifestFile))

return &exec.Cmd{
Path: swiftPath,
Args: []string{"swift", "package", showDeps, "--format", "json"},
Dir: workingDir,
Env: os.Environ(),
}, nil
}
69 changes: 69 additions & 0 deletions internal/resolution/pm/swift/cmd_factory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package swift

import (
"errors"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
)

type execPathMock struct{}

type failingExecPathMock struct{}

func (execPathMock) LookPath(file string) (string, error) {
return "/usr/bin/" + file, nil
}

func (failingExecPathMock) LookPath(_ string) (string, error) {
return "", errors.New("swift executable not found")
}

func TestMakeResolveCmd(t *testing.T) {
factory := CmdFactory{execPath: execPathMock{}}
manifest := filepath.Join("some", "path", "Package.swift")

cmd, err := factory.MakeResolveCmd(manifest)
assert.NoError(t, err)
assert.NotNil(t, cmd)
assert.Equal(t, "/usr/bin/swift", cmd.Path)
assert.Contains(t, cmd.Args, "swift")
assert.Contains(t, cmd.Args, "package")
assert.Contains(t, cmd.Args, "resolve")
assert.Equal(t, filepath.Dir(manifest), cmd.Dir)
}

func TestMakeDepsCmd(t *testing.T) {
factory := CmdFactory{execPath: execPathMock{}}
manifest := filepath.Join("some", "path", "Package.swift")

cmd, err := factory.MakeDepsCmd(manifest)
assert.NoError(t, err)
assert.NotNil(t, cmd)
assert.Equal(t, "/usr/bin/swift", cmd.Path)
assert.Contains(t, cmd.Args, "swift")
assert.Contains(t, cmd.Args, "package")
assert.Contains(t, cmd.Args, "show-dependencies")
assert.Contains(t, cmd.Args, "--format")
assert.Contains(t, cmd.Args, "json")
assert.Equal(t, filepath.Dir(manifest), cmd.Dir)
}

func TestMakeResolveCmdLookupError(t *testing.T) {
factory := CmdFactory{execPath: failingExecPathMock{}}

cmd, err := factory.MakeResolveCmd("Package.swift")

assert.Nil(t, cmd)
assert.EqualError(t, err, "swift executable not found")
}

func TestMakeDepsCmdLookupError(t *testing.T) {
factory := CmdFactory{execPath: failingExecPathMock{}}

cmd, err := factory.MakeDepsCmd("Package.swift")

assert.Nil(t, cmd)
assert.EqualError(t, err, "swift executable not found")
}
Loading
Loading