Skip to content

Commit

Permalink
Merge branch 'master' of github.com:HashLoad/boss
Browse files Browse the repository at this point in the history
� Conflicts:
�	consts/consts.go
  • Loading branch information
snakeice committed Nov 4, 2019
2 parents 8a950b8 + ff6c60e commit a597969
Show file tree
Hide file tree
Showing 31 changed files with 427 additions and 182 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ boss update
###### Aliases: up

### > Upgrade
This command upgrade the client version
This command upgrade the client latest version. Add `--dev` to upgrade to the latest pre-release.
```
boss upgrade
boss upgrade --dev
```

## Flags
Expand Down
15 changes: 13 additions & 2 deletions consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@ import "path/filepath"

const FilePackage = "boss.json"
const FilePackageLock = "boss-lock.json"
const FilePackageLockOld = "boss.lock"
const FileBplOrder = "bpl_order.txt"
const FileExtensionBpl = ".bpl"
const FileExtensionDcp = ".dcp"
const FileExtensionDpk = ".dpk"

const FilePackageLockOld = "boss.lock"
const FolderDependencies = "modules"

const FolderEnv = "env"

var FolderEnvBpl = filepath.Join(FolderEnv, "bpl")
var FolderEnvDcp = filepath.Join(FolderEnv, "dcp")
var FolderEnvDcu = filepath.Join(FolderEnv, "dcu")

const FolderBossHome = ".boss"

const BinFolder string = ".bin"
Expand Down Expand Up @@ -36,6 +47,6 @@ const BplIdentifierName = "BplIdentifier.exe"

const RegexArtifacts = "(.*.inc$|.*.pas$|.*.dfm$|.*.fmx$|.*.dcu$|.*.bpl$|.*.dcp$)"

const RegistyBasePath = `Software\Embarcadero\BDS\`
const RegistryBasePath = `Software\Embarcadero\BDS\`

var DefaultPaths = []string{BplFolder, DcuFolder, DcpFolder, BinFolder}
36 changes: 32 additions & 4 deletions core/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,40 @@ package compiler

import (
"github.com/hashload/boss/consts"
"github.com/hashload/boss/core/compiler/graphs"
"github.com/hashload/boss/env"
"github.com/hashload/boss/models"
"github.com/hashload/boss/msg"
"github.com/hashload/boss/utils"
"io/ioutil"
"os"
"path/filepath"
"strings"
)

func Build(pkg *models.Package) {
buildOrderedPackages(pkg)
graph := LoadOrderGraphAll(pkg)
saveLoadOrder(graph)
}

func saveLoadOrder(queue graphs.NodeQueue) {
var projects = ""
for {
if queue.IsEmpty() {
break
}
node := queue.Dequeue()
dependencyPath := filepath.Join(env.GetModulesDir(), node.Dep.GetName(), consts.FilePackage)
if dependencyPackage, err := models.LoadPackageOther(dependencyPath); err == nil {
for _, value := range dependencyPackage.Projects {
projects += strings.TrimSuffix(filepath.Base(value), filepath.Ext(value)) + consts.FileExtensionBpl + "\n"
}
}
}
outDir := filepath.Join(env.GetModulesDir(), consts.BplFolder, consts.FileBplOrder)

utils.HandleError(ioutil.WriteFile(outDir, []byte(projects), os.ModePerm))
}

func buildOrderedPackages(pkg *models.Package) {
Expand All @@ -28,10 +54,12 @@ func buildOrderedPackages(pkg *models.Package) {
dependency.Changed = false
if dependencyPackage, err := models.LoadPackageOther(filepath.Join(dependencyPath, consts.FilePackage)); err == nil {
dprojs := dependencyPackage.Projects
for _, dproj := range dprojs {
s, _ := filepath.Abs(filepath.Join(env.GetModulesDir(), node.Dep.GetName(), dproj))
if !compile(s, env.GetModulesDir(), &node.Dep) {
dependency.Failed = true
if len(dprojs) > 0 {
for _, dproj := range dprojs {
dprojPath, _ := filepath.Abs(filepath.Join(env.GetModulesDir(), node.Dep.GetName(), dproj))
if !compile(dprojPath, &node.Dep, pkg.Lock) {
dependency.Failed = true
}
}
ensureArtifacts(&dependency, node.Dep, env.GetModulesDir())
moveArtifacts(node.Dep, env.GetModulesDir())
Expand Down
31 changes: 8 additions & 23 deletions core/compiler/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,9 @@ import (
"github.com/hashload/boss/core/compiler/graphs"
"github.com/hashload/boss/env"
"github.com/hashload/boss/models"
"github.com/hashload/boss/msg"
"path/filepath"
)

//Use to print graph
func _() {
pkg, err := models.LoadPackage(false)
if err != nil {
msg.Die(err.Error())
}
msg.Info("Compiling order:")
queue := loadOrderGraph(pkg)
index := 1
for {
if queue.IsEmpty() {
break
}
msg.Info(" %d. %s", index, queue.Dequeue().Value)
index++
}
}

func loadOrderGraphDep(dep *models.Dependency) (queue *graphs.NodeQueue, err error) {
if pkg, err := models.LoadPackageOther(filepath.Join(env.GetModulesDir(), dep.GetName(), consts.FilePackage)); err != nil {
return nil, err
Expand All @@ -41,11 +22,16 @@ func loadOrderGraphDep(dep *models.Dependency) (queue *graphs.NodeQueue, err err

func loadOrderGraph(pkg *models.Package) graphs.NodeQueue {
var graph graphs.GraphItem
rawDeps := pkg.Dependencies.(map[string]interface{})
deps := models.GetDependencies(rawDeps)
deps := pkg.GetParsedDependencies()
loadGraph(&graph, nil, deps, nil)
return graph.Queue(pkg, false)
}
func LoadOrderGraphAll(pkg *models.Package) graphs.NodeQueue {
var graph graphs.GraphItem
deps := pkg.GetParsedDependencies()
loadGraph(&graph, nil, deps, nil)
return graph.Queue(pkg, true)
}

func loadGraph(graph *graphs.GraphItem, dep *models.Dependency, deps []models.Dependency, father *graphs.Node) {
var localFather *graphs.Node
Expand All @@ -66,8 +52,7 @@ func loadGraph(graph *graphs.GraphItem, dep *models.Dependency, deps []models.De
graph.AddEdge(localFather, node)
}
} else {
rawDeps := pkgModule.Dependencies.(map[string]interface{})
deps := models.GetDependencies(rawDeps)
deps := pkgModule.GetParsedDependencies()
loadGraph(graph, &dep, deps, localFather)
}
}
Expand Down
44 changes: 37 additions & 7 deletions core/compiler/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/hashload/boss/models"
"github.com/hashload/boss/msg"
"github.com/hashload/boss/utils"
"github.com/hashload/boss/utils/dcp"
"io/ioutil"
"os"
"os/exec"
Expand Down Expand Up @@ -37,8 +38,15 @@ func getCompilerParameters(rootPath string, dep *models.Dependency, platform str
"/P:platform=" + platform + " "
}

func compile(dprojPath string, rootPath string, dep *models.Dependency) bool {
func compile(dprojPath string, dep *models.Dependency, rootLock models.PackageLock) bool {
msg.Info(" Building " + filepath.Base(dprojPath))

bossPackagePath := filepath.Join(env.GetModulesDir(), dep.GetName(), consts.FilePackage)

if dependencyPackage, err := models.LoadPackageOther(bossPackagePath); err == nil {
dcp.InjectDpcsFile(dprojPath, dependencyPackage, rootLock)
}

dccDir := env.GetDcc32Dir()
rsvars := filepath.Join(dccDir, "rsvars.bat")
fileRes := "build_boss_" + strings.TrimSuffix(filepath.Base(dprojPath), filepath.Ext(dprojPath))
Expand All @@ -52,9 +60,12 @@ func compile(dprojPath string, rootPath string, dep *models.Dependency) bool {
readFileStr := string(readFile)
project, _ := filepath.Abs(dprojPath)

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

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

Expand All @@ -80,15 +91,18 @@ func compile(dprojPath string, rootPath string, dep *models.Dependency) bool {
}
}

func getNewPathsDep(dep *models.Dependency, basePath string) string {
func _(dep *models.Dependency, basePath string) string {
if graphDep, err := loadOrderGraphDep(dep); err == nil {
var result = ""
var result = filepath.Join(env.GetModulesDir(), consts.DcpFolder) + ";"
for {
if graphDep.IsEmpty() {
break
}
dequeue := graphDep.Dequeue()
var modulePath = filepath.Join(env.GetModulesDir(), dequeue.Dep.GetName())
if modulePath == basePath {
continue
}
if depPkg, err := models.LoadPackageOther(filepath.Join(modulePath, consts.FilePackage)); err == nil {
result += getPaths(filepath.Join(modulePath, depPkg.MainSrc), basePath)
} else {
Expand All @@ -97,7 +111,7 @@ func getNewPathsDep(dep *models.Dependency, basePath string) string {
}
return result
} else {
return getNewPathsAll(basePath)
return getNewPathsAll(basePath) + ";" + filepath.Join(env.GetModulesDir(), consts.DcpFolder)
}
}

Expand Down Expand Up @@ -129,5 +143,21 @@ func getPaths(path string, basePath string) string {
}
return nil
})
return strings.Join(paths, ";")
return strings.Join(paths, ";") + ";"
}

func buildDCU(path string) {
msg.Info(" Building %s", filepath.Base(path))
var unitScopes = "-NSWinapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;System;Xml;Data;Datasnap;Web" +
";Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell"
var unitInputDir = "-U" + filepath.Join(env.GetModulesDir(), consts.DcuFolder)
var unitOutputDir = "-NU" + filepath.Join(env.GetModulesDir(), consts.DcuFolder)
command := exec.Command("cmd", "/c dcc32.exe "+unitScopes+" "+unitInputDir+" "+unitOutputDir+" "+path)
command.Dir = filepath.Dir(path)
if out, err := command.Output(); err != nil {
msg.Err(" - Failed to compile")
msg.Err(string(out))
} else {
msg.Info(" - Success!")
}
}
5 changes: 2 additions & 3 deletions core/compiler/graphs/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/hashload/boss/models"
"github.com/hashload/boss/msg"
"strings"
"sync"
)

Expand All @@ -13,7 +14,7 @@ type Node struct {
}

func NewNode(dependency *models.Dependency) *Node {
return &Node{Dep: *dependency, Value: dependency.GetName()}
return &Node{Dep: *dependency, Value: strings.ToLower(dependency.GetName())}
}

func (n *Node) String() string {
Expand Down Expand Up @@ -154,7 +155,6 @@ func (g *GraphItem) Queue(pkg *models.Package, allDeps bool) NodeQueue {
}
}

//Ord
for {
if len(nodes) == 0 {
break
Expand All @@ -178,7 +178,6 @@ type NodeQueue struct {
lock sync.RWMutex
}

// New creates a new NodeQueue
func (s *NodeQueue) New() *NodeQueue {
s.lock.Lock()
s.items = []Node{}
Expand Down
47 changes: 41 additions & 6 deletions core/dependency_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@ package core

import (
"github.com/hashload/boss/consts"
"github.com/hashload/boss/core/installer"
"github.com/hashload/boss/env"
"github.com/hashload/boss/models"
"github.com/hashload/boss/msg"
"github.com/hashload/boss/utils"
"github.com/masterminds/semver"
"github.com/xlab/treeprint"
"os"
"path/filepath"
)

var tree = treeprint.New()

const (
updated = 0
outdated = 1
usingMaster = 2
)

func PrintDependencies() {
pkg, err := models.LoadPackage(false)
if err != nil {
Expand All @@ -22,9 +31,8 @@ func PrintDependencies() {
}
}

rawDeps := pkg.Dependencies.(map[string]interface{})
master := tree.AddBranch(pkg.Name + ":")
deps := models.GetDependencies(rawDeps)
deps := pkg.GetParsedDependencies()
printDeps(nil, deps, pkg.Lock, master)
print(tree.String())
}
Expand All @@ -43,8 +51,7 @@ func printDeps(dep *models.Dependency, deps []models.Dependency, lock models.Pac
if err != nil {
printSingleDependency(&dep, lock, localTree)
} else {
rawDeps := pkgModule.Dependencies.(map[string]interface{})
deps := models.GetDependencies(rawDeps)
deps := pkgModule.GetParsedDependencies()
printDeps(&dep, deps, lock, localTree)
}
}
Expand All @@ -53,9 +60,37 @@ func printDeps(dep *models.Dependency, deps []models.Dependency, lock models.Pac
func printSingleDependency(dep *models.Dependency, lock models.PackageLock, tree treeprint.Tree) treeprint.Tree {
var output = dep.GetName()
output += "@"
output += dep.GetVersion()
output += " --> "
output += lock.GetInstalled(*dep).Version
switch isOutdated(*dep, lock.GetInstalled(*dep).Version) {
case outdated:
output += " outdated"
break
case usingMaster:
output += " using master"
break
}

return tree.AddBranch(output)
}

func isOutdated(dependency models.Dependency, version string) int {
installer.GetDependency(dependency)
info, err := models.RepoData(dependency.GetHashName())
if err != nil {
utils.HandleError(err)
} else {
locked, err := semver.NewVersion(version)
if err != nil {
return usingMaster
}
constraint, _ := semver.NewConstraint(dependency.GetVersion())
for _, value := range info.Versions {
version, err := semver.NewVersion(value)
if err == nil && version.GreaterThan(locked) && constraint.Check(version) {
return outdated
}
}
}
return updated

}
Loading

0 comments on commit a597969

Please sign in to comment.