Skip to content

Commit 08d80a8

Browse files
committed
Honor out name for stage out default filename.
1 parent de06f5b commit 08d80a8

File tree

9 files changed

+23
-25
lines changed

9 files changed

+23
-25
lines changed

martian/core/stage.go

+3-19
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,8 @@ func makeOutArgs(outParams *syntax.OutParams, filesPath string, nullAll bool) ma
3333
(syntax.GetEnforcementLevel() == syntax.EnforceError &&
3434
param.GetArrayDim() > 0) {
3535
args[id] = nil
36-
} else if param.IsFile() {
37-
if t := param.GetTname(); t == "path" || t == "file" {
38-
args[id] = path.Join(filesPath, param.GetId())
39-
} else {
40-
args[id] = path.Join(filesPath, param.GetId()+"."+param.GetTname())
41-
}
36+
} else if fn := param.GetOutFilename(); fn != "" {
37+
args[id] = path.Join(filesPath, fn)
4238
} else {
4339
args[id] = nil
4440
}
@@ -1101,19 +1097,7 @@ func (self *Fork) postProcess() {
11011097
}
11021098

11031099
// Generate the outs path for this param
1104-
outPath := ""
1105-
if len(param.GetOutName()) > 0 {
1106-
// If MRO explicitly specifies an out name
1107-
// override, just use that verbatim.
1108-
outPath = path.Join(outsPath, param.GetOutName())
1109-
} else {
1110-
// Otherwise, just use the parameter name, and
1111-
// append the type unless it is a path.
1112-
outPath = path.Join(outsPath, id)
1113-
if param.GetTname() != "path" {
1114-
outPath += "." + param.GetTname()
1115-
}
1116-
}
1100+
outPath := path.Join(outsPath, param.GetOutFilename())
11171101

11181102
// Only continue if path to be copied is inside the pipestance
11191103
if absFilePath, err := filepath.Abs(filePath); err == nil {

martian/syntax/callable.go

+14
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,20 @@ func (s *OutParam) getSubnodes() []AstNodable {
311311
return nil
312312
}
313313

314+
// Returns the default base filename for this output parameter, or an
315+
// empty string if the parameter is not a file type.
316+
func (s *OutParam) GetOutFilename() string {
317+
if !s.IsFile() {
318+
return ""
319+
} else if s.OutName != "" {
320+
return s.OutName
321+
} else if s.Tname == KindFile || s.Tname == KindPath {
322+
return s.Id
323+
} else {
324+
return s.Id + "." + s.Tname
325+
}
326+
}
327+
314328
func (s *SrcParam) getNode() *AstNode { return &s.Node }
315329
func (s *SrcParam) File() *SourceFile { return s.Node.Loc.File }
316330
func (s *SrcParam) inheritComments() bool { return false }
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"result": "/user/test/files_test/pipeline_test/AWESOME/MERGE_JSON/fork0/files/result.json"
2+
"result": "/user/test/files_test/pipeline_test/AWESOME/MERGE_JSON/fork0/files/merged.json"
33
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"result": "/user/test/files_test/pipeline_test/AWESOME/MERGE_JSON/fork0/files/result.json"
2+
"result": "/user/test/files_test/pipeline_test/AWESOME/MERGE_JSON/fork0/files/merged.json"
33
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"result": "/user/test/files_test/pipeline_test/AWESOME/MERGE_JSON/fork0/files/result.json"
2+
"result": "/user/test/files_test/pipeline_test/AWESOME/MERGE_JSON/fork0/files/merged.json"
33
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"outfile": "/user/test/files_test/pipeline_test/AWESOME/MERGE_JSON/fork0/files/result.json"
2+
"outfile": "/user/test/files_test/pipeline_test/AWESOME/MERGE_JSON/fork0/files/merged.json"
33
}

test/files_test/expected/_mrosource

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/files_test/pipeline.mro

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ stage ADD_KEY(
2121
# Takes two files containing json dictionaries and merges them.
2222
stage MERGE_JSON(
2323
in json[] inputs,
24-
out json result,
24+
out json result "The final merged result." "merged.json",
2525
src py "stages/merge_json",
2626
) using (
2727
mem_gb = 1,

0 commit comments

Comments
 (0)