Skip to content

Commit

Permalink
add: added out_dir to build command
Browse files Browse the repository at this point in the history
  • Loading branch information
DefinitelyNotBen committed Dec 3, 2023
1 parent 828d0d7 commit 70f78cc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/please.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ var opts struct {
Rebuild bool `long:"rebuild" description:"To force the optimisation and rebuild one or more targets."`
NoDownload bool `long:"nodownload" hidden:"true" description:"Don't download outputs after building. Only applies when using remote build execution."`
Download bool `long:"download" hidden:"true" description:"Force download of all outputs regardless of original target spec. Only applies when using remote build execution."`
OutDir string `long:"out_dir" optional:"true" description:"Copies build output to given directory"`
Args struct {
Targets []core.BuildLabel `positional-arg-name:"targets" description:"Targets to build"`
} `positional-args:"true" required:"true"`
Expand Down Expand Up @@ -456,7 +457,24 @@ var opts struct {
var buildFunctions = map[string]func() int{
"build": func() int {
success, state := runBuild(opts.Build.Args.Targets, true, false, false)
return toExitCode(success, state)
if !success || opts.Build.OutDir == "" {
return toExitCode(success, state)
}
for _, label := range state.ExpandOriginalLabels() {
target := state.Graph.TargetOrDie((label))
for _, out := range target.Outputs() {
from := filepath.Join(target.OutDir(), out)
fm, err := os.Lstat(from)
if err != nil {
log.Fatalf("Failed to get file mode on build output files: %s", err)
}
err = fs.CopyFile(from, filepath.Join(opts.Build.OutDir, target.PackageDir(), out), fm.Mode())
if err != nil {
log.Fatalf("Failed to output build to provided directory: %s", err)
}
}
}
return 0
},
"hash": func() int {
if opts.Hash.Update {
Expand Down
8 changes: 8 additions & 0 deletions test/build_outdir/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
subinclude("//test/build_defs")

please_repo_e2e_test(
name = "out_dir_test",
expected_output = {"bar/foo/testy": "wibble wibble wibble"},
plz_command = "plz build //foo:testy --out_dir=bar",
repo = "test_repo",
)
Empty file.
4 changes: 4 additions & 0 deletions test/build_outdir/test_repo/foo/BUILD_FILE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
text_file(
name = "testy",
content = "wibble wibble wibble",
)

0 comments on commit 70f78cc

Please sign in to comment.