func (t *TargetBuilder) PrepBuild() error { cfgResolution, err := t.ExportCfg() if err != nil { return err } flashErrText := t.bspPkg.FlashMap.ErrorText() if flashErrText != "" { return util.NewNewtError(flashErrText) } if err := t.validateAndWriteCfg(cfgResolution); err != nil { return err } loaderPkgs, appPkgs, err := t.resolvePkgs(cfgResolution) if err != nil { return err } if loaderPkgs != nil { t.LoaderBuilder, err = NewBuilder(t, BUILD_NAME_LOADER, loaderPkgs, cfgResolution.ApiMap, cfgResolution.Cfg) if err != nil { return err } if err := t.LoaderBuilder.PrepBuild(); err != nil { return err } loaderFlags := toolchain.NewCompilerInfo() loaderFlags.Cflags = append(loaderFlags.Cflags, "-DSPLIT_LOADER") t.LoaderBuilder.AddCompilerInfo(loaderFlags) t.LoaderList = project.ResetDeps(nil) } t.AppBuilder, err = NewBuilder(t, BUILD_NAME_APP, appPkgs, cfgResolution.ApiMap, cfgResolution.Cfg) if err != nil { return err } if err := t.AppBuilder.PrepBuild(); err != nil { return err } if loaderPkgs != nil { appFlags := toolchain.NewCompilerInfo() appFlags.Cflags = append(appFlags.Cflags, "-DSPLIT_APPLICATION") t.AppBuilder.AddCompilerInfo(appFlags) } t.AppList = project.ResetDeps(nil) if err := t.generateCode(cfgResolution); err != nil { return err } return nil }
// Populates the builder with all the packages that need to be built and // configures each package's build settings. After this function executes, // packages are ready to be built. func (b *Builder) PrepBuild() error { // Populate the full set of packages to be built. for _, bpkg := range b.PkgMap { if err := bpkg.resolveDeps(b.cfg, b.apiMap); err != nil { return err } } b.logDepInfo() // Populate the base set of compiler flags. Flags from the following // packages get applied to every source file: // * target // * app (if present) // * bsp // * compiler (not added here) // // In the case of conflicting flags, the higher priority package's flag // wins. Package priorities are assigned as follows (highest priority // first): // * target // * app (if present) // * bsp // * <library package> // * compiler baseCi := toolchain.NewCompilerInfo() // Target flags. log.Debugf("Generating build flags for target %s", b.targetPkg.FullName()) targetCi, err := b.targetPkg.CompilerInfo(b) if err != nil { return err } baseCi.AddCompilerInfo(targetCi) // App flags. if b.appPkg != nil { log.Debugf("Generating build flags for app %s", b.appPkg.FullName()) appCi, err := b.appPkg.CompilerInfo(b) if err != nil { return err } baseCi.AddCompilerInfo(appCi) } // Bsp flags. log.Debugf("Generating build flags for bsp %s", b.bspPkg.FullName()) bspCi, err := b.bspPkg.CompilerInfo(b) if err != nil { return err } // Define a cpp symbol indicating the BSP architecture, name of the // BSP and app. archName := b.targetBuilder.bspPkg.Arch bspCi.Cflags = append(bspCi.Cflags, "-DARCH_"+util.CIdentifier(archName)) bspCi.Cflags = append(bspCi.Cflags, "-DARCH_NAME=\""+archName+"\"") if b.appPkg != nil { appName := filepath.Base(b.appPkg.Name()) bspCi.Cflags = append(bspCi.Cflags, "-DAPP_"+util.CIdentifier(appName)) bspCi.Cflags = append(bspCi.Cflags, "-DAPP_NAME=\""+appName+"\"") } bspName := filepath.Base(b.bspPkg.Name()) bspCi.Cflags = append(bspCi.Cflags, "-DBSP_"+util.CIdentifier(bspName)) bspCi.Cflags = append(bspCi.Cflags, "-DBSP_NAME=\""+bspName+"\"") baseCi.AddCompilerInfo(bspCi) // All packages have access to the generated code header directory. baseCi.Cflags = append(baseCi.Cflags, "-I"+GeneratedIncludeDir(b.targetPkg.Name())) // Note: Compiler flags get added at the end, after the flags for library // package being built are calculated. b.compilerInfo = baseCi return nil }
func (bpkg *BuildPackage) CompilerInfo( b *Builder) (*toolchain.CompilerInfo, error) { // If this package's compiler info has already been generated, returned the // cached copy. if bpkg.ci != nil { return bpkg.ci, nil } ci := toolchain.NewCompilerInfo() features := b.cfg.FeaturesForLpkg(bpkg.LocalPackage) ci.Cflags = newtutil.GetStringSliceFeatures(bpkg.PkgV, features, "pkg.cflags") ci.Lflags = newtutil.GetStringSliceFeatures(bpkg.PkgV, features, "pkg.lflags") ci.Aflags = newtutil.GetStringSliceFeatures(bpkg.PkgV, features, "pkg.aflags") // Package-specific injected settings get specified as C flags on the // command line. for k, _ := range bpkg.InjectedSettings() { ci.Cflags = append(ci.Cflags, syscfg.FeatureToCflag(k)) } ci.IgnoreFiles = []*regexp.Regexp{} ignPats := newtutil.GetStringSliceFeatures(bpkg.PkgV, features, "pkg.ign_files") for _, str := range ignPats { re, err := regexp.Compile(str) if err != nil { return nil, util.NewNewtError( "Ignore files, unable to compile re: " + err.Error()) } ci.IgnoreFiles = append(ci.IgnoreFiles, re) } ci.IgnoreDirs = []*regexp.Regexp{} ignPats = newtutil.GetStringSliceFeatures(bpkg.PkgV, features, "pkg.ign_dirs") for _, str := range ignPats { re, err := regexp.Compile(str) if err != nil { return nil, util.NewNewtError( "Ignore dirs, unable to compile re: " + err.Error()) } ci.IgnoreDirs = append(ci.IgnoreDirs, re) } bpkg.SourceDirectories = newtutil.GetStringSliceFeatures(bpkg.PkgV, features, "pkg.src_dirs") includePaths, err := bpkg.recursiveIncludePaths(b) if err != nil { return nil, err } ci.Includes = append(bpkg.privateIncludeDirs(b), includePaths...) bpkg.ci = ci return bpkg.ci, nil }