MCPcopy Create free account
hub / github.com/celer-pkg/celer / Init

Method Init

configs/platform.go:29–97  ·  view source on GitHub ↗
(platformName string)

Source from the content-addressed store, hash-verified

27}
28
29func (p *Platform) Init(platformName string) error {
30 // Check if platform name is empty.
31 platformName = strings.TrimSpace(platformName)
32 if platformName == "" {
33 return fmt.Errorf("platform name is empty")
34 }
35
36 // Check if platform file exists.
37 platformPath := filepath.Join(dirs.ConfPlatformsDir, platformName+".toml")
38 if !fileio.PathExists(platformPath) {
39 return fmt.Errorf("%w: %s", errors.ErrPlatformNotExist, platformName)
40 }
41 p.Name = platformName
42
43 // Read conf/celer.toml
44 bytes, err := os.ReadFile(platformPath)
45 if err != nil {
46 return err
47 }
48 if err := toml.Unmarshal(bytes, p); err != nil {
49 return fmt.Errorf("failed to read %s -> %w", platformPath, err)
50 }
51
52 exrVars := p.ctx.ExprVars()
53 if p.RootFS != nil {
54 p.RootFS.ctx = p.ctx
55 if err := p.RootFS.Validate(); err != nil {
56 return err
57 }
58
59 // Store toolchain releated express vars.
60 exrVars.Put("SYSROOT", p.RootFS.GetAbsDir())
61 }
62 if p.Toolchain != nil {
63 p.Toolchain.ctx = p.ctx
64 if err := p.Toolchain.Validate(); err != nil {
65 return err
66 }
67
68 // Store toolchain releated express vars.
69 exrVars.Put("HOST", p.Toolchain.GetHost())
70 exrVars.Put("BUILD_HOST", p.buildHost())
71 exrVars.Put("SYSTEM_NAME", strings.ToLower(p.Toolchain.GetHost()))
72 exrVars.Put("SYSTEM_PROCESSOR", p.Toolchain.GetSystemProcessor())
73 exrVars.Put("CROSSTOOL_PREFIX", p.Toolchain.GetCrosstoolPrefix())
74 exrVars.Put("TOOLCHAIN", p.Toolchain.rootDir)
75 exrVars.Put("BUILD_HOST", p.buildHost())
76 exrVars.Put("CC", p.Toolchain.CC)
77 exrVars.Put("CXX", p.Toolchain.CXX)
78 exrVars.Put("CPP", p.Toolchain.CPP)
79 exrVars.Put("AR", p.Toolchain.AR)
80 exrVars.Put("LD", p.Toolchain.LD)
81 exrVars.Put("AS", p.Toolchain.AS)
82 exrVars.Put("OBJCOPY", p.Toolchain.OBJCOPY)
83 exrVars.Put("OBJDUMP", p.Toolchain.OBJDUMP)
84 exrVars.Put("STRIP", p.Toolchain.STRIP)
85 exrVars.Put("READELF", p.Toolchain.READELF)
86 exrVars.Put("SIZE", p.Toolchain.SIZE)

Callers

nothing calls this directly

Calls 9

buildHostMethod · 0.95
PathExistsFunction · 0.92
PutMethod · 0.80
ExprVarsMethod · 0.65
ValidateMethod · 0.65
GetAbsDirMethod · 0.65
GetHostMethod · 0.65
GetSystemProcessorMethod · 0.65
GetCrosstoolPrefixMethod · 0.65

Tested by

no test coverage detected