Skip to content

Commit

Permalink
Merge pull request #4 from wings-software/python_cpp_c
Browse files Browse the repository at this point in the history
autogen changes for python, c, cpp
  • Loading branch information
raghavharness authored Dec 4, 2023
2 parents e290f06 + d601007 commit f359ef9
Show file tree
Hide file tree
Showing 4 changed files with 484 additions and 2 deletions.
2 changes: 2 additions & 0 deletions builder/rules/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func (h Harness) GetRules() []Rule {
harness.ConfigureGo,
harness.ConfigureNode,
harness.ConfigurePython,
harness.ConfigureC,
harness.ConfigureCPP,
harness.ConfigureRails,
harness.ConfigureRuby,
harness.ConfigureRust,
Expand Down
152 changes: 152 additions & 0 deletions builder/rules/harness/rule_c.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// Copyright 2023 Harness Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package harness

import (
"io/fs"

spec "github.com/drone/spec/dist/go"
"github.com/wings-software/autogen-go/utils"
)

// ConfigureC configures a C step.
func ConfigureC(fsys fs.FS, pipeline *spec.Pipeline) error {
stage := pipeline.Stages[0].Spec.(*spec.StageCI)

if utils.Match(fsys, "*/*.c") || utils.Match(fsys, "*.c") {
if utils.Exists(fsys, "Makefile") {
{
script := new(spec.StepExec)
script.Run = "make"

step := new(spec.Step)
step.Name = "build make"
step.Type = "script"
step.Spec = script

stage.Steps = append(stage.Steps, step)
}

{
script := new(spec.StepExec)
script.Run = "make lint"

step := new(spec.Step)
step.Name = "make lint"
step.Type = "script"
step.Spec = script

stage.Steps = append(stage.Steps, step)
}

{
script := new(spec.StepExec)
script.Run = "make test"
script.Reports = []*spec.Report{
{
Path: []string{
"**/*.xml",
},
Type: "JUnit",
},
}

step := new(spec.Step)
step.Name = "run tests"
step.Type = "script"
step.Spec = script

stage.Steps = append(stage.Steps, step)
}
} else if utils.Match(fsys, "CMakeLists.txt") {
{
script := new(spec.StepExec)
script.Run = "sudo apt-get update\nsudo apt-get install check && sudo apt-get install lcov"
step := new(spec.Step)
step.Name = "install and update deps"
step.Type = "script"
step.Spec = script

stage.Steps = append(stage.Steps, step)
}

{
script := new(spec.StepExec)
script.Run = "mkdir build && cd build && cmake .. && cmake --build ."

step := new(spec.Step)
step.Name = "cmake build && make"
step.Type = "script"
step.Spec = script

stage.Steps = append(stage.Steps, step)
}

{
script := new(spec.StepExec)
script.Run = "cd build && make test"
script.Reports = []*spec.Report{
{
Path: []string{
"**/*.xml",
},
Type: "JUnit",
},
}

step := new(spec.Step)
step.Name = "run tests"
step.Type = "script"
step.Spec = script

stage.Steps = append(stage.Steps, step)
}
} else if utils.Match(fsys, "Makefile.am") {
{
script := new(spec.StepExec)
script.Run = "./bootstrap && ./configure --with-coverage"
step := new(spec.Step)
step.Name = "configure"
step.Type = "script"
step.Spec = script

stage.Steps = append(stage.Steps, step)
}

{
script := new(spec.StepExec)
script.Run = "make clean && make check"

step := new(spec.Step)
step.Name = "run tests and get coverage"
step.Type = "script"
step.Spec = script
script.Reports = []*spec.Report{
{
Path: []string{
"**/*.xml",
},
Type: "JUnit",
},
}
stage.Steps = append(stage.Steps, step)
}

{
script := new(spec.StepExec)
script.Run = "make cov"

step := new(spec.Step)
step.Name = "get coverage"
step.Type = "script"
step.Spec = script

stage.Steps = append(stage.Steps, step)
}
}
}

return nil
}
112 changes: 112 additions & 0 deletions builder/rules/harness/rule_cpp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright 2023 Harness Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package harness

import (
"io/fs"

spec "github.com/drone/spec/dist/go"
"github.com/wings-software/autogen-go/utils"
)

// ConfigureCPP configures a CPP step.
func ConfigureCPP(fsys fs.FS, pipeline *spec.Pipeline) error {
stage := pipeline.Stages[0].Spec.(*spec.StageCI)

if utils.Match(fsys, "*.cpp") || utils.Match(fsys, "*/*.cpp") || utils.Match(fsys, "*/*.cc") || utils.Match(fsys, "*.cc") {
if utils.Exists(fsys, "Makefile") {
{
script := new(spec.StepExec)
script.Run = "make"

step := new(spec.Step)
step.Name = "build make"
step.Type = "script"
step.Spec = script

stage.Steps = append(stage.Steps, step)
}

{
script := new(spec.StepExec)
script.Run = "make lint"

step := new(spec.Step)
step.Name = "make lint"
step.Type = "script"
step.Spec = script

stage.Steps = append(stage.Steps, step)
}

{
script := new(spec.StepExec)
script.Run = "TEST_NODE_INDEX=<+strategy.iteration>\nTEST_NODE_TOTAL=<+strategy.iterations>\n" +
"export TEST_FILES=`split_tests --glob 'test/**/*.cpp' --split-by file_timing --verbose " +
"--split-index '${TEST_NODE_INDEX}' --split-total '${TEST_NODE_TOTAL}'`"
script.Reports = []*spec.Report{
{
Path: []string{
"**/*.xml",
},
Type: "JUnit",
},
}

step := new(spec.Step)
step.Name = "run tests"
step.Type = "script"
step.Spec = script

stage.Steps = append(stage.Steps, step)
}
} else if utils.Exists(fsys, "CMakeLists.txt") {
{
script := new(spec.StepExec)
script.Run = "sudo apt-get update\nsudo apt-get install libgtest-dev"
step := new(spec.Step)
step.Name = "install and update deps"
step.Type = "script"
step.Spec = script

stage.Steps = append(stage.Steps, step)
}

{
script := new(spec.StepExec)
script.Run = "mkdir build && cd build && cmake .. && cmake --build ."

step := new(spec.Step)
step.Name = "cmake build && make"
step.Type = "script"
step.Spec = script

stage.Steps = append(stage.Steps, step)
}

{
script := new(spec.StepExec)
script.Run = "cd build && make check"
script.Reports = []*spec.Report{
{
Path: []string{
"**/*.xml",
},
Type: "JUnit",
},
}

step := new(spec.Step)
step.Name = "run tests"
step.Type = "script"
step.Spec = script

stage.Steps = append(stage.Steps, step)
}
}
}

return nil
}
Loading

0 comments on commit f359ef9

Please sign in to comment.