Skip to content

Commit

Permalink
Various fixes.
Browse files Browse the repository at this point in the history
* Fix support for interactive and stub tasks in polygon.
* Fix task_yaml's Languages method when it is a communication task without stubs.
  • Loading branch information
mraron committed Apr 11, 2024
1 parent 3537161 commit 7a1344f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
4 changes: 4 additions & 0 deletions pkg/problems/config/polygon/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ func ParserAndIdentifier(opts ...Option) (problems.ConfigParser, problems.Config
if err := cpp.AutoCompile(context.TODO(), fs, s, workingDirectory, filepath.Join(p.Path, p.Assets.Interactor.Source.Path), filepath.Join(p.Path, "files/interactor")); err != nil {
return nil, err
}
p.Assets.Interactor.binary, err = os.ReadFile(filepath.Join(p.Path, "files/interactor"))
if err != nil {
return nil, err
}
}
}

Expand Down
14 changes: 12 additions & 2 deletions pkg/problems/config/polygon/polygon.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/mraron/njudge/pkg/problems/evaluation/batch"
"github.com/mraron/njudge/pkg/problems/evaluation/communication"
"github.com/mraron/njudge/pkg/problems/evaluation/output_only"
"github.com/mraron/njudge/pkg/problems/evaluation/stub"
"path/filepath"

"github.com/mraron/njudge/pkg/language"
Expand Down Expand Up @@ -47,6 +48,7 @@ type Checker struct {

type Interactor struct {
Source Source `xml:"source"`
binary []byte
}

type Assets struct {
Expand Down Expand Up @@ -154,13 +156,21 @@ func (p Problem) GetTaskType() problems.TaskType {
return communication.New(evaluation.CompileCheckSupported{
List: p.Languages(),
NextCompiler: evaluation.Compile{},
}, []byte("@TODO"), p.Checker())
}, p.Assets.Interactor.binary, p.Checker())
}
if p.TaskType == "outputonly" {
return output_only.New(p.Checker())
}
if p.TaskType == "stub" {
panic("TODO")
compiler := evaluation.NewCompilerWithStubs()
for _, lang := range p.Languages() {
for _, file := range p.EvaluationFiles() {
if file.StubOf(lang) {
compiler.AddStub(lang, file)
}
}
}
return stub.New(compiler, evaluation.BasicRunnerWithChecker(p.Checker()))
}
return batch.New(evaluation.CompileCheckSupported{
List: p.Languages(),
Expand Down
23 changes: 8 additions & 15 deletions pkg/problems/config/task_yaml/task_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,19 @@ func (p Problem) Interactive() bool {
return false
}

func (p Problem) probablyStubOf(f problems.EvaluationFile, lang language.Language) bool {
return f.Role == "stub_"+lang.ID() || (f.Role == "stub_cpp" && strings.HasPrefix(lang.ID(), "cpp"))
}

func (p Problem) Languages() []language.Language {
if p.OutputOnly {
return []language.Language{zip.Zip{}}
}

lst1 := language.DefaultStore.List()
lst1 := language.ListExcept(language.DefaultStore, []string{"zip"})

lst2 := make([]language.Language, 0, len(lst1))
for _, val := range lst1 {
if p.tasktype == "stub" || p.tasktype == "communication" {
hasStub := false
for _, f := range p.files {
if p.probablyStubOf(f, val) {
if f.StubOf(val) {
hasStub = true
break
}
Expand All @@ -130,12 +126,12 @@ func (p Problem) Languages() []language.Language {
lst2 = append(lst2, val)
}
} else {
if val.ID() != "zip" {
lst2 = append(lst2, val)
}
lst2 = append(lst2, val)
}
}

if p.tasktype == "communication" && len(lst2) == 0 {
return lst1
}
return lst2
}

Expand Down Expand Up @@ -287,15 +283,12 @@ func (p Problem) makeCompiler() problems.Compiler {
compiler := evaluation.NewCompilerWithStubs()
for _, lang := range p.Languages() {
for _, file := range p.files {
if p.probablyStubOf(file, lang) {
if file.StubOf(lang) {
compiler.AddStub(lang, file)
}
}
}
return evaluation.CompileCheckSupported{
List: p.Languages(),
NextCompiler: compiler,
}
return compiler
}
return evaluation.CompileCopyFile{}
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/problems/problem.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"github.com/mraron/njudge/pkg/language"
"github.com/mraron/njudge/pkg/language/memory"
"strings"
)

type Problem interface {
Expand All @@ -26,6 +27,10 @@ type EvaluationFile struct {
Path string
}

func (f EvaluationFile) StubOf(lang language.Language) bool {
return f.Role == "stub_"+lang.ID() || (f.Role == "stub_cpp" && strings.HasPrefix(lang.ID(), "cpp"))
}

type EvaluationInfo interface {
InputOutputFiles() (string, string)
Languages() []language.Language
Expand Down

0 comments on commit 7a1344f

Please sign in to comment.