-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
format comments, walk_derivation_graph, more progress
- Loading branch information
Showing
20 changed files
with
591 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package bramble | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/davecgh/go-spew/spew" | ||
build "github.com/maxmcd/bramble/pkg/bramblebuild" | ||
project "github.com/maxmcd/bramble/pkg/brambleproject" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBasic(t *testing.T) { | ||
projectLocation, err := filepath.Abs("../brambleproject/testdata/project") | ||
require.NoError(t, err) | ||
gotOutput, err := project.ExecModule(project.ExecModuleInput{ | ||
Command: "build", | ||
Arguments: []string{":chain"}, | ||
ProjectInput: project.ProjectInput{ | ||
WorkingDirectory: projectLocation, | ||
ProjectLocation: projectLocation, | ||
ModuleName: "testproject", | ||
}, | ||
}) | ||
require.NoError(t, err) | ||
a := gotOutput.AllDerivations[0] | ||
|
||
store, err := build.NewStore("") | ||
require.NoError(t, err) | ||
|
||
exists, drv, err := store.NewDerivation2(build.NewDerivationOptions{ | ||
Args: a.Args, | ||
Builder: a.Builder, | ||
Env: a.Env, | ||
// InputDerivations: , TODO | ||
Name: a.Name, | ||
Outputs: a.Outputs, | ||
Platform: a.Platform, | ||
Sources: build.SourceFiles{ | ||
ProjectLocation: projectLocation, | ||
Location: a.Sources.Location, | ||
Files: a.Sources.Files, | ||
}, | ||
}) | ||
require.NoError(t, err) | ||
spew.Dump(exists, drv) | ||
|
||
// Arrange the allDerivations so that you're starting with dependencies | ||
// without dependents. Crawl the grap, when you run NewDerivation above take | ||
// the hash and replace it in all child dependents. Then build that new | ||
// derivation. Then hand those derivations to a build function and build the | ||
// unbuilt derivations while patching up the graph again. | ||
// | ||
// Maybe think about a good generalization for building the graph and then | ||
// patching it up, would be great to stop implementing that everywhere. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package bramblebuild | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"sort" | ||
|
||
"github.com/maxmcd/bramble/pkg/fileutil" | ||
"github.com/maxmcd/bramble/pkg/hasher" | ||
"github.com/maxmcd/bramble/pkg/reptar" | ||
) | ||
|
||
type NewDerivationOptions struct { | ||
Args []string | ||
Builder string | ||
Env map[string]string | ||
InputDerivations DerivationOutputs | ||
Name string | ||
Outputs []string | ||
Platform string | ||
Sources SourceFiles | ||
} | ||
|
||
type SourceFiles struct { | ||
ProjectLocation string | ||
Location string | ||
Files []string | ||
} | ||
|
||
func (s *Store) hashAndStoreSources(drv *Derivation, sources SourceFiles) (err error) { | ||
// TODO: could extend reptar to handle hasing the files before moving | ||
// them to a tempdir | ||
tmpDir, err := s.TempDir() | ||
if err != nil { | ||
return | ||
} | ||
|
||
absDir, err := filepath.Abs(sources.Location) | ||
if err != nil { | ||
return | ||
} | ||
// get absolute paths for all sources | ||
for i, src := range sources.Files { | ||
sources.Files[i] = filepath.Join(sources.ProjectLocation, src) | ||
} | ||
|
||
prefix := fileutil.CommonFilepathPrefix(append(sources.Files, absDir)) | ||
relBramblefileLocation, err := filepath.Rel(prefix, absDir) | ||
if err != nil { | ||
return | ||
} | ||
|
||
if err = fileutil.CopyFilesByPath(prefix, sources.Files, tmpDir); err != nil { | ||
return | ||
} | ||
// sometimes the location the derivation runs from is not present | ||
// in the structure of the copied source files. ensure that we add it | ||
runLocation := filepath.Join(tmpDir, relBramblefileLocation) | ||
if err = os.MkdirAll(runLocation, 0755); err != nil { | ||
return | ||
} | ||
hshr := hasher.NewHasher() | ||
if err = reptar.Reptar(tmpDir, hshr); err != nil { | ||
return | ||
} | ||
storeLocation := s.JoinStorePath(hshr.String()) | ||
if fileutil.PathExists(storeLocation) { | ||
if err = os.RemoveAll(tmpDir); err != nil { | ||
return | ||
} | ||
} else { | ||
if err = os.Rename(tmpDir, storeLocation); err != nil { | ||
return | ||
} | ||
} | ||
drv.BuildContextSource = hshr.String() | ||
drv.BuildContextRelativePath = relBramblefileLocation | ||
drv.SourcePaths = append(drv.SourcePaths, hshr.String()) | ||
sort.Strings(drv.SourcePaths) | ||
return | ||
} | ||
|
||
func (s *Store) NewDerivation2(options NewDerivationOptions) (exists bool, drv *Derivation, err error) { | ||
drv = s.NewDerivation() | ||
if err = s.hashAndStoreSources(drv, options.Sources); err != nil { | ||
return | ||
} | ||
drv.store = s | ||
drv.Args = options.Args | ||
drv.Builder = options.Builder | ||
drv.Name = options.Name | ||
drv.Env = options.Env | ||
drv.InputDerivations = options.InputDerivations | ||
drv.Platform = options.Platform | ||
drv.OutputNames = options.Outputs // TODO: Validate, and others | ||
|
||
exists, err = drv.PopulateOutputsFromStore() | ||
return exists, drv, err | ||
} |
Oops, something went wrong.