Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 03b228e7 authored by Zi Wang's avatar Zi Wang Committed by Gerrit Code Review
Browse files

Merge "Remove OutputFileProducer" into main

parents e952680e d38e63d4
Loading
Loading
Loading
Loading
+3 −32
Original line number Diff line number Diff line
@@ -1207,29 +1207,7 @@ func (m *ModuleBase) GenerateTaggedDistFiles(ctx BaseModuleContext) TaggedDistFi
				continue
			}
		}

		// if the tagged dist file cannot be obtained from OutputFilesProvider,
		// fall back to use OutputFileProducer
		// TODO: remove this part after OutputFilesProvider fully replaces OutputFileProducer
		if outputFileProducer, ok := m.module.(OutputFileProducer); ok {
			// Call the OutputFiles(tag) method to get the paths associated with the tag.
			distFilesForTag, err := outputFileProducer.OutputFiles(tag)
			// If the tag was not supported and is not DefaultDistTag then it is an error.
			// Failing to find paths for DefaultDistTag is not an error. It just means
			// that the module type requires the legacy behavior.
			if err != nil && tag != DefaultDistTag {
				ctx.PropertyErrorf("dist.tag", "%s", err.Error())
			}
			distFiles = distFiles.addPathsForTag(tag, distFilesForTag...)
		} else if tag != DefaultDistTag {
			// If the tag was specified then it is an error if the module does not
			// implement OutputFileProducer because there is no other way of accessing
			// the paths for the specified tag.
			ctx.PropertyErrorf("dist.tag",
				"tag %s not supported because the module does not implement OutputFileProducer", tag)
	}
	}

	return distFiles
}

@@ -2385,7 +2363,7 @@ type sourceOrOutputDependencyTag struct {
	// The name of the module.
	moduleName string

	// The tag that will be passed to the module's OutputFileProducer.OutputFiles(tag) method.
	// The tag that will be used to get the specific output file(s).
	tag string
}

@@ -2439,14 +2417,7 @@ type SourceFileProducer interface {
	Srcs() Paths
}

// A module that implements OutputFileProducer can be referenced from any property that is tagged with `android:"path"`
// using the ":module" syntax or ":module{.tag}" syntax and provides a list of output files to be used as if they were
// listed in the property.
type OutputFileProducer interface {
	OutputFiles(tag string) (Paths, error)
}

// OutputFilesForModule returns the paths from an OutputFileProducer with the given tag.  On error, including if the
// OutputFilesForModule returns the output file paths with the given tag. On error, including if the
// module produced zero paths, it reports errors to the ctx and returns nil.
func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string) Paths {
	paths, err := outputFilesForModule(ctx, module, tag)
@@ -2457,7 +2428,7 @@ func OutputFilesForModule(ctx PathContext, module blueprint.Module, tag string)
	return paths
}

// OutputFileForModule returns the path from an OutputFileProducer with the given tag.  On error, including if the
// OutputFileForModule returns the output file paths with the given tag.  On error, including if the
// module produced zero or multiple paths, it reports errors to the ctx and returns nil.
func OutputFileForModule(ctx PathContext, module blueprint.Module, tag string) Path {
	paths, err := outputFilesForModule(ctx, module, tag)
+6 −6
Original line number Diff line number Diff line
@@ -463,8 +463,8 @@ func ExistentPathsForSources(ctx PathGlobContext, paths []string) Paths {
//   - glob, relative to the local module directory, resolves as filepath(s), relative to the local
//     source directory.
//   - other modules using the ":name{.tag}" syntax. These modules must implement SourceFileProducer
//     or OutputFileProducer. These resolve as a filepath to an output filepath or generated source
//     filepath.
//     or set the OutputFilesProvider. These resolve as a filepath to an output filepath or generated
//     source filepath.
//
// Properties passed as the paths argument must have been annotated with struct tag
// `android:"path"` so that dependencies on SourceFileProducer modules will have already been handled by the
@@ -491,8 +491,8 @@ type SourceInput struct {
//   - glob, relative to the local module directory, resolves as filepath(s), relative to the local
//     source directory. Not valid in excludes.
//   - other modules using the ":name{.tag}" syntax. These modules must implement SourceFileProducer
//     or OutputFileProducer. These resolve as a filepath to an output filepath or generated source
//     filepath.
//     or set the OutputFilesProvider. These resolve as a filepath to an output filepath or generated
//     source filepath.
//
// excluding the items (similarly resolved
// Properties passed as the paths argument must have been annotated with struct tag
@@ -620,8 +620,8 @@ func GetModuleFromPathDep(ctx ModuleWithDepsPathContext, moduleName, tag string)
//   - glob, relative to the local module directory, resolves as filepath(s), relative to the local
//     source directory. Not valid in excludes.
//   - other modules using the ":name{.tag}" syntax. These modules must implement SourceFileProducer
//     or OutputFileProducer. These resolve as a filepath to an output filepath or generated source
//     filepath.
//     or set the OutputFilesProvider. These resolve as a filepath to an output filepath or generated
//     source filepath.
//
// and a list of the module names of missing module dependencies are returned as the second return.
// Properties passed as the paths argument must have been annotated with struct tag
+5 −15
Original line number Diff line number Diff line
@@ -1018,31 +1018,21 @@ func (m TestingModule) VariablesForTestsRelativeToTop() map[string]string {
	return normalizeStringMapRelativeToTop(m.config, m.module.VariablesForTests())
}

// OutputFiles first checks if module base outputFiles property has any output
// OutputFiles checks if module base outputFiles property has any output
// files can be used to return.
// If not, it calls OutputFileProducer.OutputFiles on the
// encapsulated module, exits the test immediately if there is an error and
// Exits the test immediately if there is an error and
// otherwise returns the result of calling Paths.RelativeToTop
// on the returned Paths.
func (m TestingModule) OutputFiles(t *testing.T, tag string) Paths {
	// TODO: remove OutputFileProducer part
	outputFiles := m.Module().base().outputFiles
	if tag == "" && outputFiles.DefaultOutputFiles != nil {
		return outputFiles.DefaultOutputFiles.RelativeToTop()
	} else if taggedOutputFiles, hasTag := outputFiles.TaggedOutputFiles[tag]; hasTag {
		return taggedOutputFiles
		return taggedOutputFiles.RelativeToTop()
	}

	producer, ok := m.module.(OutputFileProducer)
	if !ok {
		t.Fatalf("%q must implement OutputFileProducer\n", m.module.Name())
	}
	paths, err := producer.OutputFiles(tag)
	if err != nil {
		t.Fatal(err)
	}

	return paths.RelativeToTop()
	t.Fatal(fmt.Errorf("No test output file has been set for tag %q", tag))
	return nil
}

// TestingSingleton is wrapper around an android.Singleton that provides methods to find information about individual