示例#1
0
func cnv_tdaq_install_scripts(wscript *hlib.Wscript_t, stmt Stmt) error {
	pkgname := filepath.Base(wscript.Package.Name)
	tgt := hlib.Target_t{Name: pkgname + "-install-scripts"}
	tgt.Features = []string{"tdaq_install_scripts"}
	tgt.Source = []hlib.Value{hlib.DefaultValue(
		"script-files",
		[]string{"scripts/*"},
	)}
	wscript.Build.Targets = append(wscript.Build.Targets, tgt)
	return nil
}
示例#2
0
func cnv_atlas_install_data(wscript *hlib.Wscript_t, stmt Stmt) error {
	//x := stmt.(*ApplyPattern)
	//fmt.Printf(">>> [%s] \n", x.Name)
	pkgname := filepath.Base(wscript.Package.Name)
	tgt := hlib.Target_t{Name: pkgname + "-install-data"}
	tgt.Features = []string{"atlas_install_data"}
	tgt.Source = []hlib.Value{hlib.DefaultValue(
		"data-files",
		[]string{"data/*"},
	)}
	wscript.Build.Targets = append(wscript.Build.Targets, tgt)
	return nil
}
示例#3
0
func (r *Renderer) analyze() error {
	var err error

	basedir := filepath.Dir(filepath.Dir(r.req.Filename))

	r.pkg = hlib.Wscript_t{
		Package:   hlib.Package_t{Name: basedir},
		Configure: hlib.Configure_t{Env: make(hlib.Env_t)},
		Build:     hlib.Build_t{Env: make(hlib.Env_t)},
	}
	wscript := &r.pkg

	// targets
	apps := make(map[string]*Application)
	libs := make(map[string]*Library)

	// first pass: discover targets
	for _, stmt := range r.req.Stmts {
		switch stmt.(type) {
		case *Application:
			x := stmt.(*Application)
			apps[x.Name] = x

		case *Library:
			x := stmt.(*Library)
			libs[x.Name] = x
		}
	}

	// list of macros related to targets.
	// this will be used to:
	//  - fold them together
	//  - pre-process macro_append, macro_remove, ...
	//  - dispatch to wscript equivalents. e.g.:
	//     - <name>linkopts -> ctx(use=[...], cxxshlibflags=[...])
	//     - <name>_dependencies -> ctx(depends_on=[...])
	//     - includes -> ctx(includes=[..])
	macros := make(map[string][]Stmt)

	tgt_names := make([]string, 0, len(apps)+len(libs))
	for k, _ := range apps {
		tgt_names = append(tgt_names, k)
	}
	for k, _ := range libs {
		tgt_names = append(tgt_names, k)
	}
	sort.Strings(tgt_names)

	//fmt.Printf("+++ tgt_names: %v\n", tgt_names)

	// second pass: collect macros
	for _, stmt := range r.req.Stmts {
		switch x := stmt.(type) {
		default:
			continue
		case *Macro:
			//fmt.Printf("== [%s] ==\n", x.Name)
			//pat := x.Name+"(_dependencies|linkopts)"
			pat := ".*?"
			if !re_is_in_slice_suffix(tgt_names, x.Name, pat) {
				continue
			}
			macros[x.Name] = append(macros[x.Name], x)

		case *MacroAppend:
			pat := ".*?"
			if !re_is_in_slice_suffix(tgt_names, x.Name, pat) {
				continue
			}
			macros[x.Name] = append(macros[x.Name], x)

		case *MacroRemove:
			pat := ".*?"
			if !re_is_in_slice_suffix(tgt_names, x.Name, pat) {
				continue
			}
			macros[x.Name] = append(macros[x.Name], x)

		}
	}

	// models private/public, end_private/end_public
	ctx_visible := []bool{true}

	// 3rd pass: collect libraries and apps
	// this is to make sure the profile-converters get them already populated
	for _, stmt := range r.req.Stmts {
		wbld := &wscript.Build
		switch x := stmt.(type) {
		case *Library:
			tgt := hlib.Target_t{Name: x.Name}
			srcs, rest := sanitize_srcs(x.Source, "src")
			// FIXME: handle -s=some/dir
			if len(rest) > 0 {
			}
			val := hlib.Value{
				Name: x.Name,
				Set: []hlib.KeyValue{
					{Tag: "default", Value: srcs},
				},
			}
			tgt.Source = append(tgt.Source, val)
			if features, ok := g_profile.features["library"]; ok {
				tgt.Features = features
			}
			w_distill_tgt(&tgt, macros)
			wbld.Targets = append(wbld.Targets, tgt)

		case *Application:
			tgt := hlib.Target_t{Name: x.Name}
			srcs, rest := sanitize_srcs(x.Source, "src")
			// FIXME: handle -s=some/dir
			if len(rest) > 0 {
			}
			val := hlib.Value{
				Name: x.Name,
				Set: []hlib.KeyValue{
					{Tag: "default", Value: srcs},
				},
			}

			tgt.Source = append(tgt.Source, val)
			if features, ok := g_profile.features["application"]; ok {
				tgt.Features = features
			}
			w_distill_tgt(&tgt, macros)
			wbld.Targets = append(wbld.Targets, tgt)
		}
	}

	// 4th pass to collect
	for _, stmt := range r.req.Stmts {
		wpkg := &wscript.Package
		wbld := &wscript.Build
		wcfg := &wscript.Configure
		switch x := stmt.(type) {

		case *BeginPublic:
			ctx_visible = append(ctx_visible, true)
		case *EndPublic:
			ctx_visible = ctx_visible[:len(ctx_visible)-1]

		case *BeginPrivate:
			ctx_visible = append(ctx_visible, false)
		case *EndPrivate:
			ctx_visible = ctx_visible[:len(ctx_visible)-1]

		case *Author:
			wpkg.Authors = append(wpkg.Authors, hlib.Author(x.Name))

		case *Manager:
			wpkg.Managers = append(wpkg.Managers, hlib.Manager(x.Name))

		case *Version:
			wpkg.Version = hlib.Version(x.Value)

		case *UsePkg:
			deptype := hlib.PrivateDep
			if ctx_visible[len(ctx_visible)-1] {
				deptype = hlib.PublicDep
			}
			if str_is_in_slice(x.Switches, "-no_auto_imports") {
				deptype = hlib.RuntimeDep | deptype
			}
			wpkg.Deps = append(
				wpkg.Deps,
				hlib.Dep_t{
					Name:    path.Join(x.Path, x.Package),
					Version: hlib.Version(x.Version),
					Type:    deptype,
				},
			)

		case *Alias:
			val := hlib.Value(*x)
			wcfg.Stmts = append(wcfg.Stmts, &hlib.AliasStmt{Value: val})

		case *Macro:
			if _, ok := macros[x.Name]; ok {
				// this will be used by a library or application
				continue
			}
			val := hlib.Value(*x)
			wcfg.Stmts = append(wcfg.Stmts, &hlib.MacroStmt{Value: val})

		case *MacroAppend:
			if _, ok := macros[x.Name]; ok {
				// this will be used by a library or application
				continue
			}
			val := hlib.Value(*x)
			wcfg.Stmts = append(wcfg.Stmts, &hlib.MacroAppendStmt{Value: val})

		case *MacroPrepend:
			if _, ok := macros[x.Name]; ok {
				// this will be used by a library or application
				continue
			}
			val := hlib.Value(*x)
			wcfg.Stmts = append(wcfg.Stmts, &hlib.MacroPrependStmt{Value: val})

		case *MacroRemove:
			if _, ok := macros[x.Name]; ok {
				// this will be used by a library or application
				continue
			}
			val := hlib.Value(*x)
			wcfg.Stmts = append(wcfg.Stmts, &hlib.MacroRemoveStmt{Value: val})

		case *Path:
			val := hlib.Value(*x)
			wcfg.Stmts = append(wcfg.Stmts, &hlib.PathStmt{Value: val})

		case *PathAppend:
			val := hlib.Value(*x)
			wcfg.Stmts = append(wcfg.Stmts, &hlib.PathAppendStmt{Value: val})

		case *PathPrepend:
			val := hlib.Value(*x)
			wcfg.Stmts = append(wcfg.Stmts, &hlib.PathPrependStmt{Value: val})

		case *PathRemove:
			val := hlib.Value(*x)
			wcfg.Stmts = append(wcfg.Stmts, &hlib.PathRemoveStmt{Value: val})

		case *Pattern:
			wcfg.Stmts = append(wcfg.Stmts, (*hlib.PatternStmt)(x))

		case *ApplyPattern:
			if cnv, ok := g_profile.cnvs[x.Name]; ok {
				err = cnv(wscript, x)
				if err != nil {
					return err
				}
			} else {
				wbld.Stmts = append(wbld.Stmts, (*hlib.ApplyPatternStmt)(x))
			}

		case *Tag:
			wcfg.Stmts = append(wcfg.Stmts, (*hlib.TagStmt)(x))

		case *ApplyTag:
			val := hlib.Value(*x)
			wcfg.Stmts = append(wcfg.Stmts, &hlib.ApplyTagStmt{Value: val})

		case *TagExclude:
			wcfg.Stmts = append(wcfg.Stmts, (*hlib.TagExcludeStmt)(x))

		case *MakeFragment:
			wcfg.Stmts = append(wcfg.Stmts, (*hlib.MakeFragmentStmt)(x))

		case *SetEnv:
			val := hlib.Value(*x)
			wcfg.Stmts = append(wcfg.Stmts, &hlib.SetStmt{Value: val})

		case *SetAppend:
			val := hlib.Value(*x)
			wcfg.Stmts = append(wcfg.Stmts, &hlib.SetAppendStmt{Value: val})

		case *SetRemove:
			val := hlib.Value(*x)
			wcfg.Stmts = append(wcfg.Stmts, &hlib.SetRemoveStmt{Value: val})

		case *Package:
			// already dealt with

		case *Action:
			// FIXME

		case *IncludePaths:
			wcfg.Stmts = append(wcfg.Stmts, (*hlib.IncludePathStmt)(x))

		case *IncludeDirs:
			wcfg.Stmts = append(wcfg.Stmts, (*hlib.IncludeDirsStmt)(x))

		case *CmtPathPattern:
			// FIXME

		case *CmtPathPatternReverse:
			// FIXME

		case *IgnorePattern:
			// FIXME

		case *Document:
			wbld.Stmts = append(wbld.Stmts, (*hlib.DocumentStmt)(x))

		case *Library:
			// already dealt with
		case *Application:
			// already dealt with

		default:
			return fmt.Errorf("unhandled statement [%v] (type=%T)\ndir=%v", x, x, r.req.Filename)
		}
	}

	for _, stmt := range r.req.Stmts {
		switch stmt := stmt.(type) {
		case *PathRemove, *MakeFragment, *Pattern, *MacroRemove:
			r.wscript = true
			break
		case *Macro:
			if len(stmt.Set) > 1 {
				r.wscript = true
				break
			}
		}
	}

	// FIXME: refactor ?
	if strings.HasPrefix(r.pkg.Package.Name, "External") {
		r.wscript = true
	}

	// fixups for boost
	for _, tgt := range wscript.Build.Targets {
		for _, use := range tgt.Use {
			for _, kv := range use.Set {
				for i, vv := range kv.Value {
					vv = strings.Replace(vv, "-${boost_libsuffix}", "", -1)
					vv = strings.Replace(vv, "boost_", "boost-", -1)
					kv.Value[i] = vv
				}
			}
		}
	}
	return err
}