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

Commit 21143a60 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Specify module dependency in the srcs list"

parents ed62b9cc bbd25aeb
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -106,7 +106,8 @@ func (binary *binaryDecorator) nativeCoverage() bool {
func (binary *binaryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
	fileName := binary.getStem(ctx) + ctx.toolchain().ExecutableSuffix()

	srcPath := srcPathFromModuleSrcs(ctx, binary.baseCompiler.Properties.Srcs)
	srcPath, paths := srcPathFromModuleSrcs(ctx, binary.baseCompiler.Properties.Srcs)
	deps.SrcDeps = paths

	outputFile := android.PathForModuleOut(ctx, fileName)
	binary.unstrippedOutputFile = outputFile
+1 −0
Original line number Diff line number Diff line
@@ -166,6 +166,7 @@ func transformSrctoCrate(ctx ModuleContext, main android.Path, deps PathDeps, fl
	implicits = append(implicits, rustLibsToPaths(deps.ProcMacros)...)
	implicits = append(implicits, deps.StaticLibs...)
	implicits = append(implicits, deps.SharedLibs...)
	implicits = append(implicits, deps.SrcDeps...)
	if deps.CrtBegin.Valid() {
		implicits = append(implicits, deps.CrtBegin.Path(), deps.CrtEnd.Path())
	}
+19 −5
Original line number Diff line number Diff line
@@ -253,10 +253,24 @@ func (compiler *baseCompiler) relativeInstallPath() string {
	return String(compiler.Properties.Relative_install_path)
}

func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) android.Path {
	srcPaths := android.PathsForModuleSrc(ctx, srcs)
	if len(srcPaths) != 1 {
		ctx.PropertyErrorf("srcs", "srcs can only contain one path for rust modules")
	}
	return srcPaths[0]
func srcPathFromModuleSrcs(ctx ModuleContext, srcs []string) (android.Path, android.Paths) {
	// The srcs can contain strings with prefix ":".
	// They are dependent modules of this module, with android.SourceDepTag.
	// They are not the main source file compiled by rustc.
	numSrcs := 0
	srcIndex := 0
	for i, s := range srcs {
		if android.SrcIsModule(s) == "" {
			numSrcs++
			srcIndex = i
		}
	}
	if numSrcs != 1 {
		ctx.PropertyErrorf("srcs", "srcs can only contain one path for a rust file")
	}
	if srcIndex != 0 {
		ctx.PropertyErrorf("srcs", "main source file must be the first in srcs")
	}
	paths := android.PathsForModuleSrc(ctx, srcs)
	return paths[srcIndex], paths
}
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ func TestFeaturesToFlags(t *testing.T) {
// Test that we reject multiple source files.
func TestEnforceSingleSourceFile(t *testing.T) {

	singleSrcError := "srcs can only contain one path for rust modules"
	singleSrcError := "srcs can only contain one path for a rust file"

	// Test libraries
	testRustError(t, singleSrcError, `
+2 −1
Original line number Diff line number Diff line
@@ -368,7 +368,8 @@ func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) F
func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
	var outputFile android.WritablePath

	srcPath := srcPathFromModuleSrcs(ctx, library.baseCompiler.Properties.Srcs)
	srcPath, paths := srcPathFromModuleSrcs(ctx, library.baseCompiler.Properties.Srcs)
	deps.SrcDeps = paths

	flags.RustFlags = append(flags.RustFlags, deps.depFlags...)

Loading