func (p *Processor) absPath(s string) string { if strings.TrimLeft(s, "//") != s { return filepath.Join(util.GetProjectPath(), strings.Trim(s, "//")) } else { return filepath.Join(p.document.Path, s) } }
func NewTargetURLFromString(u string) (tu TargetURL) { switch { case u[:2] == "//": u = u[2:] break case u[0] == ':': if wd, err := os.Getwd(); err == nil { rel, err := filepath.Rel(util.GetProjectPath(), wd) if err == nil { tu.Package = rel } else { log.Fatal(err) } } else { log.Fatal(err) } break default: errorf := `'%s' is not a valid target. a target url can only start with a '//' or a ':' for relative targets.` log.Fatalf(errorf, u) } tu.Package, tu.Target = split(u, ":", true) return }
func init() { if data, err := ioutil.ReadFile(filepath.Join(util.GetProjectPath(), ".build")); err == nil { vars = make(map[string]string) err = yaml.Unmarshal(data, &vars) if err != nil { log.Fatalf("error: %v", err) } } }
func (p *Processor) glob(f *ast.Func) []string { if !filepath.IsAbs(p.wd) { return []string{fmt.Sprintf("Error parsing glob: %s is not an absolute path.", p.wd)} } var files []string var excludes []*regexp.Regexp if len(f.AnonParams) != 1 { return []string{"Error parsing glob: proper usage is like so glob(include, exclude=[], exclude_directories=1)"} } if exs, ok := f.Params["exclude"]; ok { for _, ex := range exs.([]interface{}) { r, _ := regexp.Compile(ex.(string)) excludes = append(excludes, r) } } //BUG(sevki): put some type checking here for _, s := range f.AnonParams[0].([]interface{}) { globPtrn := "" switch s.(type) { case string: globPtrn = filepath.Clean(filepath.Join(p.wd, s.(string))) log.Println(globPtrn) default: return nil } globFiles, err := filepath.Glob(globPtrn) if err != nil { return []string{"Error parsing glob: %s"} } RESIZED: for i, f := range globFiles { t, _ := filepath.Rel(util.GetProjectPath(), f) t = fmt.Sprintf("//%s", t) for _, x := range excludes { if x.Match([]byte(t)) { globFiles = append(globFiles[:i], globFiles[i+1:]...) goto RESIZED } } globFiles[i] = t } files = append(files, globFiles...) } return files }
func ReadBuildFile(url TargetURL, wd string) (i *ast.File, err error) { BUILDPATH := filepath.Join(url.BuildDir(wd, util.GetProjectPath()), "BUILD") BUCKPATH := filepath.Join(url.BuildDir(wd, util.GetProjectPath()), "BUCK") var FILEPATH string if _, err := os.Stat(BUCKPATH); err == nil { FILEPATH = BUCKPATH } else if _, err := os.Stat(BUILDPATH); err == nil { FILEPATH = BUILDPATH } else { return nil, err } i = &ast.File{} ks, _ := os.Open(FILEPATH) if err := New("BUILD", url.BuildDir(wd, util.GetProjectPath()), ks).Decode(i); err != nil { return nil, err } return i, nil }
func New() (c Builder) { c.Nodes = make(map[string]*Node) c.Error = make(chan error) c.Done = make(chan *Node) c.BuildQueue = make(chan *Node) c.Updates = make(chan Update) var err error c.Wd, err = os.Getwd() if err != nil { log.Fatal(err) } c.ProjectPath = util.GetProjectPath() return }
func (c Dependencies) toSSlice() SSlice { ProjectPath := util.GetProjectPath() var t SSlice for _, s := range c { dir, file := filepath.Split(string(s)) dir = strings.TrimRight(dir, "/") targ := file[:len(file)-len(filepath.Ext(file))] if len(dir) > 0 { if dir[0] != "/"[0] { rel, _ := filepath.Rel(ProjectPath, dir) t = append(t, fmt.Sprintf("//%s/%s:%s", rel, dir, targ)) } else { t = append(t, fmt.Sprintf("/%s:%s", dir, targ)) } } else { t = append(t, fmt.Sprintf("%s", targ)) } } return t }
// New returns a new PostProcessor func New(p string) PostProcessor { return PostProcessor{ packagePath: p, projectPath: util.GetProjectPath(), } }
func (b *Builder) work(jq chan *Node, workerNumber int) { for { select { case job := <-jq: if job.Status != Pending { continue } job.Lock() defer job.Unlock() job.Status = Building b.Updates <- Update{ Worker: workerNumber, TimeStamp: time.Now(), Target: job.Url.String(), Status: Started, } buildErr := b.build(job) if buildErr != nil { job.Status = Fail b.Updates <- Update{ Worker: workerNumber, TimeStamp: time.Now(), Target: job.Url.String(), Status: Fail, } b.Error <- buildErr } else { job.Status = Success b.Updates <- Update{ Worker: workerNumber, TimeStamp: time.Now(), Target: job.Url.String(), Status: Success, } } b.Done <- job if !job.IsRoot { job.once.Do(func() { for _, parent := range job.Parents { parent.wg.Done() } }) } else { buildOut := filepath.Join( util.GetProjectPath(), "build_out", ) os.RemoveAll(buildOut) if err := os.MkdirAll( buildOut, os.ModeDir|os.ModePerm, ); err != nil { log.Fatalf("linking job %s failed: %s", job.Target.GetName(), err.Error()) } for dst, src := range job.Target.Installs() { target := filepath.Base(dst) targetDir := strings.TrimRight(dst, target) buildOutTarget := filepath.Join( buildOut, targetDir, ) if err := os.MkdirAll( buildOutTarget, os.ModeDir|os.ModePerm, ); err != nil { log.Fatalf("linking job %s failed: %s", job.Target.GetName(), err.Error()) } os.Symlink( filepath.Join( "/tmp", "build", fmt.Sprintf("%s-%x", job.Target.GetName(), job.HashNode()), src, ), filepath.Join( buildOutTarget, target, ), ) } close(b.Done) return } } } }