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

Commit ecc495fd authored by Jooyung Han's avatar Jooyung Han Committed by Gerrit Code Review
Browse files

Merge "Apply "excludes" for OutputFileProducer"

parents 0ae555df 7607dd35
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -2099,15 +2099,6 @@ func (m *moduleContext) CheckbuildFile(srcPath Path) {
	m.checkbuildFiles = append(m.checkbuildFiles, srcPath)
}

func findStringInSlice(str string, slice []string) int {
	for i, s := range slice {
		if s == str {
			return i
		}
	}
	return -1
}

// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input
// was not a module reference.
func SrcIsModule(s string) (module string) {
+15 −13
Original line number Diff line number Diff line
@@ -380,6 +380,18 @@ func (e missingDependencyError) Error() string {
}

func expandOneSrcPath(ctx ModuleContext, s string, expandedExcludes []string) (Paths, error) {
	excludePaths := func(paths Paths) Paths {
		if len(expandedExcludes) == 0 {
			return paths
		}
		remainder := make(Paths, 0, len(paths))
		for _, p := range paths {
			if !InList(p.String(), expandedExcludes) {
				remainder = append(remainder, p)
			}
		}
		return remainder
	}
	if m, t := SrcIsModuleWithTag(s); m != "" {
		module := ctx.GetDirectDepWithTag(m, sourceOrOutputDepTag(t))
		if module == nil {
@@ -390,20 +402,11 @@ func expandOneSrcPath(ctx ModuleContext, s string, expandedExcludes []string) (P
			if err != nil {
				return nil, fmt.Errorf("path dependency %q: %s", s, err)
			}
			return outputFiles, nil
			return excludePaths(outputFiles), nil
		} else if t != "" {
			return nil, fmt.Errorf("path dependency %q is not an output file producing module", s)
		} else if srcProducer, ok := module.(SourceFileProducer); ok {
			moduleSrcs := srcProducer.Srcs()
			for _, e := range expandedExcludes {
				for j := 0; j < len(moduleSrcs); j++ {
					if moduleSrcs[j].String() == e {
						moduleSrcs = append(moduleSrcs[:j], moduleSrcs[j+1:]...)
						j--
					}
				}
			}
			return moduleSrcs, nil
			return excludePaths(srcProducer.Srcs()), nil
		} else {
			return nil, fmt.Errorf("path dependency %q is not a source file producing module", s)
		}
@@ -418,8 +421,7 @@ func expandOneSrcPath(ctx ModuleContext, s string, expandedExcludes []string) (P
			reportPathErrorf(ctx, "module source path %q does not exist", p)
		}

		j := findStringInSlice(p.String(), expandedExcludes)
		if j >= 0 {
		if InList(p.String(), expandedExcludes) {
			return nil, nil
		}
		return Paths{p}, nil
+15 −0
Original line number Diff line number Diff line
@@ -1090,6 +1090,21 @@ func TestPathsForModuleSrc(t *testing.T) {
			srcs: []string{buildDir + "/.intermediates/ofp/b/gen/c"},
			rels: []string{"gen/c"},
		},
		{
			name: "output file provider with exclude",
			bp: `
			test {
				name: "foo",
				srcs: [":b", ":c"],
				exclude_srcs: [":c"]
			}
			output_file_provider {
				name: "c",
				outs: ["gen/c"],
			}`,
			srcs: []string{buildDir + "/.intermediates/ofp/b/gen/b"},
			rels: []string{"gen/b"},
		},
		{
			name: "special characters glob",
			bp: `