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
8 changes: 8 additions & 0 deletions internal/adapters/secondary/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"io"
"os"
"path/filepath"
"testing"
"time"

Expand All @@ -27,13 +28,15 @@ func NewMockFileSystem() *MockFileSystem {
}

func (m *MockFileSystem) ReadFile(name string) ([]byte, error) {
name = filepath.ToSlash(name)
if data, ok := m.files[name]; ok {
return data, nil
}
return nil, errors.New("file not found")
}

func (m *MockFileSystem) WriteFile(name string, data []byte, _ os.FileMode) error {
name = filepath.ToSlash(name)
m.files[name] = data
return nil
}
Expand All @@ -43,6 +46,7 @@ func (m *MockFileSystem) MkdirAll(_ string, _ os.FileMode) error {
}

func (m *MockFileSystem) Stat(name string) (os.FileInfo, error) {
name = filepath.ToSlash(name)
if _, ok := m.files[name]; ok {
//nolint:nilnil // Mock for testing
return nil, nil
Expand All @@ -51,6 +55,7 @@ func (m *MockFileSystem) Stat(name string) (os.FileInfo, error) {
}

func (m *MockFileSystem) Remove(name string) error {
name = filepath.ToSlash(name)
delete(m.files, name)
return nil
}
Expand All @@ -60,6 +65,8 @@ func (m *MockFileSystem) RemoveAll(_ string) error {
}

func (m *MockFileSystem) Rename(oldpath, newpath string) error {
oldpath = filepath.ToSlash(oldpath)
newpath = filepath.ToSlash(newpath)
if data, ok := m.files[oldpath]; ok {
m.files[newpath] = data
delete(m.files, oldpath)
Expand All @@ -82,6 +89,7 @@ func (m *MockFileSystem) Create(_ string) (io.WriteCloser, error) {
}

func (m *MockFileSystem) Exists(name string) bool {
name = filepath.ToSlash(name)
_, ok := m.files[name]
return ok
}
Expand Down
42 changes: 35 additions & 7 deletions internal/core/services/compiler/executor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package compiler

import (
"fmt"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -95,25 +96,47 @@ func compile(dprojPath string, dep *domain.Dependency, rootLock domain.PackageLo
abs, _ := filepath.Abs(filepath.Dir(dprojPath))
buildLog := filepath.Join(abs, fileRes+".log")
buildBat := filepath.Join(abs, fileRes+".bat")
cfgPath := filepath.Join(abs, "boss.cfg")

// Create boss.cfg to hold search paths and avoid command-line too long errors (Issue #205)
var cfgContent strings.Builder
dcuPath := filepath.Join(env.GetModulesDir(), consts.DcuFolder)
dcpPath := filepath.Join(env.GetModulesDir(), consts.DcpFolder)
cfgContent.WriteString(fmt.Sprintf("-I\"%s\"\n-U\"%s\"\n", dcuPath, dcuPath))
cfgContent.WriteString(fmt.Sprintf("-I\"%s\"\n-U\"%s\"\n", dcpPath, dcpPath))

if searchPathsStr := buildSearchPath(dep); searchPathsStr != "" {
paths := strings.Split(searchPathsStr, ";")
for _, p := range paths {
p = strings.TrimSpace(p)
if p != "" {
cfgContent.WriteString(fmt.Sprintf("-I\"%s\"\n-U\"%s\"\n", p, p))
}
}
}

err := os.WriteFile(cfgPath, []byte(cfgContent.String()), 0600)
if err != nil {
if tracker == nil || !tracker.IsEnabled() {
msg.Warn(" ⚠️ Error on create compiler configuration file")
}
return false
}

readFile, err := os.ReadFile(rsvars) // #nosec G304 -- Reading Delphi environment variables file from known location
if err != nil {
msg.Err(" ❌ Error on read rsvars.bat")
}
readFileStr := string(readFile)
project, _ := filepath.Abs(dprojPath)

readFileStr += "\n@SET DCC_UnitSearchPath=%DCC_UnitSearchPath%;" +
filepath.Join(env.GetModulesDir(), consts.DcuFolder) +
";" + filepath.Join(env.GetModulesDir(), consts.DcpFolder) //+ ";" + getNewPathsDep(dep, abs) + " "

readFileStr += ";" + buildSearchPath(dep)

readFileStr += "\n@SET PATH=%PATH%;" + filepath.Join(env.GetModulesDir(), consts.BplFolder) + ";"
for _, value := range []string{platform} {
readFileStr += " \n msbuild \"" +
project +
"\" /p:Configuration=Debug " +
getCompilerParameters(env.GetModulesDir(), dep, value)
getCompilerParameters(env.GetModulesDir(), dep, value) +
" /p:DCC_AdditionalParameters=\"@" + cfgPath + "\""
}
readFileStr += " > \"" + buildLog + "\""

Expand All @@ -122,6 +145,7 @@ func compile(dprojPath string, dep *domain.Dependency, rootLock domain.PackageLo
if tracker == nil || !tracker.IsEnabled() {
msg.Warn(" ⚠️ Error on create build file")
}
_ = os.Remove(cfgPath)
return false
}

Expand All @@ -131,6 +155,7 @@ func compile(dprojPath string, dep *domain.Dependency, rootLock domain.PackageLo
if tracker == nil || !tracker.IsEnabled() {
msg.Err(" ❌ Failed to compile, see " + buildLog + " for more information")
}
_ = os.Remove(cfgPath)
return false
}
if tracker == nil || !tracker.IsEnabled() {
Expand All @@ -143,6 +168,9 @@ func compile(dprojPath string, dep *domain.Dependency, rootLock domain.PackageLo
if err := os.Remove(buildBat); err != nil {
msg.Debug("Could not remove build script %s: %v", buildBat, err)
}
if err := os.Remove(cfgPath); err != nil {
msg.Debug("Could not remove boss.cfg %s: %v", cfgPath, err)
}

return true
}
Loading