normaliser

package
v0.0.0-...-1dd1f65 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package normaliser provides utilities for archiving and transferring plans, corpora, and subjects.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrCollision = errors.New("path already mapped by normaliser")

ErrCollision occurs if the normaliser tries to map two files to the same normalised path. Usually, this is an internal error.

Functions

This section is empty.

Types

type Corpus

type Corpus struct {

	// Mappings contains the merged mapping table across all subjects.
	Mappings Map

	// BySubject contains the normalisers for each subject, which, in turn, contain the mappings.
	BySubject map[string]*Normaliser
	// contains filtered or unexported fields
}

Corpus is a corpus-level normaliser.

func NewCorpus

func NewCorpus(root string) *Corpus

NewCorpus constructs a new corpus normaliser relative to root.

func (*Corpus) Normalise

func (n *Corpus) Normalise(c corpus.Corpus) (corpus.Corpus, error)

Normalise normalises mappings for each subject in c.

type Entry

type Entry struct {
	// Original is the original path.
	Original string
	// Kind is the kind of path to which this mapping belongs.
	Kind filekind.Kind
	// Loc is an abstraction of the location of the path to which this mapping belongs.
	Loc filekind.Loc
}

Entry is a record in the normaliser's mappings. This exists mainly to make it possible to use a Normaliser to work out how to copy a plan to another host, but only copy selective subsets of files.

func NewEntry

func NewEntry(k filekind.Kind, l filekind.Loc, segs ...string) Entry

NewEntry constructs an entry with the filekind k, location l, and path constructed by segs.

type Map

type Map map[string]Entry

Map is the type of normalisation mappings.

func (Map) RenamesMatching

func (m Map) RenamesMatching(k filekind.Kind, l filekind.Loc) map[string]string

RenamesMatching filters this map to only the files matching kind k and location l.

Example

ExampleMap_RenamesMatching is a runnable example for RenamesMatching.

package main

import (
	"fmt"
	"path"

	"github.com/c4-project/c4t/internal/subject/compilation"

	"github.com/c4-project/c4t/internal/id"
	"github.com/c4-project/c4t/internal/model/litmus"

	"github.com/c4-project/c4t/internal/model/recipe"

	"github.com/c4-project/c4t/internal/model/filekind"
	"github.com/c4-project/c4t/internal/subject"
	"github.com/c4-project/c4t/internal/subject/normaliser"
	"github.com/c4-project/c4t/internal/subject/status"
)

func main() {
	n := normaliser.New("root")
	l, _ := litmus.New(path.Join("foo", "bar", "baz.litmus"))
	f, _ := litmus.New(path.Join("barbaz", "baz.1.litmus"))
	s, _ := subject.New(l,
		subject.WithFuzz(&subject.Fuzz{Litmus: *f, Trace: path.Join("barbaz", "baz.1.trace")}),
		subject.WithCompile(id.FromString("clang"),
			compilation.CompileResult{
				Result: compilation.Result{Status: status.Ok},
				Files: compilation.CompileFileset{
					Bin: path.Join("foobaz", "clang", "a.out"),
					Log: path.Join("foobaz", "clang", "errors"),
				},
			},
		),
		subject.WithRecipe(id.FromString("arm"),
			recipe.Recipe{
				Dir:   path.Join("burble", "armv8"),
				Files: []string{"inky.c", "pinky.c"},
			},
		),
		subject.WithRecipe(id.FromString("x86"),
			recipe.Recipe{
				Dir:   path.Join("burble", "i386"),
				Files: []string{"inky.c", "pinky.c"},
			},
		),
	)
	_, _ = n.Normalise(*s)
	for k, v := range n.Mappings.RenamesMatching(filekind.Any, filekind.InRecipe) {
		fmt.Println(k, "<-", v)
	}

}
Output:

root/recipes/arm/inky.c <- burble/armv8/inky.c
root/recipes/arm/pinky.c <- burble/armv8/pinky.c
root/recipes/x86/inky.c <- burble/i386/inky.c
root/recipes/x86/pinky.c <- burble/i386/pinky.c

type Normaliser

type Normaliser struct {

	// Mappings contains maps from normalised names to original names.
	// (The mappings are this way around to help us notice collisions.)
	Mappings Map
	// contains filtered or unexported fields
}

Normaliser contains state necessary to normalise a single subject's paths. This is useful for archiving the subject inside a tarball, or copying it to another host.

func New

func New(root string) *Normaliser

New constructs a new Normaliser relative to root.

func (*Normaliser) Normalise

func (n *Normaliser) Normalise(s subject.Subject) (*subject.Subject, error)

Normalise normalises mappings from subject component files to 'normalised' names.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL