Exemplo n.º 1
0
//export AddProvide
func AddProvide(cTarget uintptr, cLanguage *C.char, cDep *C.char) *C.char {
	target := unsizet(cTarget)
	label, err := core.TryParseBuildLabel(C.GoString(cDep), target.Label.PackageName)
	if err != nil {
		return C.CString(err.Error())
	}
	target.AddProvide(C.GoString(cLanguage), label)
	return nil
}
Exemplo n.º 2
0
//export AddExportedDep
func AddExportedDep(cTarget uintptr, cDep *C.char) *C.char {
	target := unsizet(cTarget)
	dep, err := core.TryParseBuildLabel(C.GoString(cDep), target.Label.PackageName)
	if err != nil {
		return C.CString(err.Error())
	}
	target.AddMaybeExportedDependency(dep, true)
	return nil
}
Exemplo n.º 3
0
//export AddVis
func AddVis(cTarget uintptr, cVis *C.char) *C.char {
	target := unsizet(cTarget)
	vis := C.GoString(cVis)
	if vis == "PUBLIC" || (core.State.Config.Bazel.Compatibility && vis == "//visibility:public") {
		target.Visibility = append(target.Visibility, core.WholeGraph[0])
	} else {
		label, err := core.TryParseBuildLabel(vis, target.Label.PackageName)
		if err != nil {
			return C.CString(err.Error())
		}
		target.Visibility = append(target.Visibility, label)
	}
	return nil
}
Exemplo n.º 4
0
//export AddDependency
func AddDependency(cPackage uintptr, cTarget *C.char, cDep *C.char, exported bool) *C.char {
	target, err := getTargetPost(cPackage, cTarget)
	if err != nil {
		return C.CString(err.Error())
	}
	dep, err := core.TryParseBuildLabel(C.GoString(cDep), target.Label.PackageName)
	if err != nil {
		return C.CString(err.Error())
	}
	target.AddMaybeExportedDependency(dep, exported)
	// Note that here we're in a post-build function so we must call this explicitly
	// (in other callbacks it's handled after the package parses all at once).
	core.State.Graph.AddDependency(target.Label, dep)
	return nil
}
Exemplo n.º 5
0
//export GetLabels
func GetLabels(cPackage uintptr, cTarget *C.char, cPrefix *C.char) **C.char {
	// Two formats are supported here: either passing just the name of a target in the current
	// package, or a build label referring specifically to one.
	lbl := C.GoString(cTarget)
	prefix := C.GoString(cPrefix)
	if core.LooksLikeABuildLabel(lbl) {
		label, err := core.TryParseBuildLabel(lbl, unsizep(cPackage).Name)
		if err != nil {
			log.Fatalf("%s", err) // TODO(pebers): report proper errors here and below
		}
		return stringSliceToCStringArray(getLabels(core.State.Graph.TargetOrDie(label), prefix, core.Built))
	}
	target, err := getTargetPost(cPackage, cTarget)
	if err != nil {
		log.Fatalf("%s", err)
	}
	return stringSliceToCStringArray(getLabels(target, prefix, core.Building))
}
Exemplo n.º 6
0
// Parses an incoming source label as either a file or a build label.
// Identifies if the file is owned by this package and returns an error if not.
func parseSource(src, packageName string, systemAllowed bool) (core.BuildInput, error) {
	if core.LooksLikeABuildLabel(src) {
		return core.TryParseBuildLabel(src, packageName)
	} else if src == "" {
		return nil, fmt.Errorf("Empty source path (in package %s)", packageName)
	} else if strings.Contains(src, "../") {
		return nil, fmt.Errorf("'%s' (in package %s) is an invalid path; build target paths can't contain ../", src, packageName)
	} else if src[0] == '/' || src[0] == '~' {
		if !systemAllowed {
			return nil, fmt.Errorf("'%s' (in package %s) is an absolute path; that's not allowed.", src, packageName)
		}
		return core.SystemFileLabel{Path: core.ExpandHomePath(src)}, nil
	} else if strings.Contains(src, "/") {
		// Target is in a subdirectory, check nobody else owns that.
		for dir := path.Dir(path.Join(packageName, src)); dir != packageName && dir != "."; dir = path.Dir(dir) {
			if core.IsPackage(dir) {
				return nil, fmt.Errorf("Package %s tries to use file %s, but that belongs to another package (%s).", packageName, src, dir)
			}
		}
	}
	return core.FileLabel{File: src, Package: packageName}, nil
}