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

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

Merge "Add erofs support to Soong filesystem modules" into main

parents 004074db c35d6fb1
Loading
Loading
Loading
Loading
+39 −2
Original line number Original line Diff line number Diff line
@@ -92,7 +92,7 @@ type FilesystemProperties struct {
	// Name of the partition stored in vbmeta desc. Defaults to the name of this module.
	// Name of the partition stored in vbmeta desc. Defaults to the name of this module.
	Partition_name *string
	Partition_name *string


	// Type of the filesystem. Currently, ext4, cpio, and compressed_cpio are supported. Default
	// Type of the filesystem. Currently, ext4, erofs, cpio, and compressed_cpio are supported. Default
	// is ext4.
	// is ext4.
	Type *string
	Type *string


@@ -143,6 +143,20 @@ type FilesystemProperties struct {
	// build modules, where we want to emit some not-yet-working filesystems and we don't want them
	// build modules, where we want to emit some not-yet-working filesystems and we don't want them
	// to be built.
	// to be built.
	Unchecked_module *bool `blueprint:"mutated"`
	Unchecked_module *bool `blueprint:"mutated"`

	Erofs ErofsProperties
}

// Additional properties required to generate erofs FS partitions.
type ErofsProperties struct {
	// Compressor and Compression level passed to mkfs.erofs. e.g. (lz4hc,9)
	// Please see external/erofs-utils/README for complete documentation.
	Compressor *string

	// Used as --compress-hints for mkfs.erofs
	Compress_hints *string `android:"path"`

	Sparse *bool
}
}


// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
// android_filesystem packages a set of modules and their transitive dependencies into a filesystem
@@ -178,6 +192,7 @@ type fsType int


const (
const (
	ext4Type fsType = iota
	ext4Type fsType = iota
	erofsType
	compressedCpioType
	compressedCpioType
	cpioType // uncompressed
	cpioType // uncompressed
	unknown
	unknown
@@ -195,6 +210,8 @@ func (f *filesystem) fsType(ctx android.ModuleContext) fsType {
	switch typeStr {
	switch typeStr {
	case "ext4":
	case "ext4":
		return ext4Type
		return ext4Type
	case "erofs":
		return erofsType
	case "compressed_cpio":
	case "compressed_cpio":
		return compressedCpioType
		return compressedCpioType
	case "cpio":
	case "cpio":
@@ -224,7 +241,7 @@ var pctx = android.NewPackageContext("android/soong/filesystem")
func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	validatePartitionType(ctx, f)
	validatePartitionType(ctx, f)
	switch f.fsType(ctx) {
	switch f.fsType(ctx) {
	case ext4Type:
	case ext4Type, erofsType:
		f.output = f.buildImageUsingBuildImage(ctx)
		f.output = f.buildImageUsingBuildImage(ctx)
	case compressedCpioType:
	case compressedCpioType:
		f.output = f.buildCpioImage(ctx, true)
		f.output = f.buildCpioImage(ctx, true)
@@ -437,6 +454,8 @@ func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.
		// TODO(372522486): add more types like f2fs, erofs, etc.
		// TODO(372522486): add more types like f2fs, erofs, etc.
		case ext4Type:
		case ext4Type:
			return "ext4"
			return "ext4"
		case erofsType:
			return "erofs"
		}
		}
		panic(fmt.Errorf("unsupported fs type %v", t))
		panic(fmt.Errorf("unsupported fs type %v", t))
	}
	}
@@ -486,6 +505,24 @@ func (f *filesystem) buildPropFile(ctx android.ModuleContext) (propFile android.
		addStr("uuid", uuid)
		addStr("uuid", uuid)
		addStr("hash_seed", uuid)
		addStr("hash_seed", uuid)
	}
	}
	// Add erofs properties
	if f.fsType(ctx) == erofsType {
		if compressor := f.properties.Erofs.Compressor; compressor != nil {
			addStr("erofs_default_compressor", proptools.String(compressor))
		}
		if compressHints := f.properties.Erofs.Compress_hints; compressHints != nil {
			addStr("erofs_default_compress_hints", android.PathForModuleSrc(ctx, *compressHints).String())
		}
		if proptools.BoolDefault(f.properties.Erofs.Sparse, true) {
			// https://source.corp.google.com/h/googleplex-android/platform/build/+/88b1c67239ca545b11580237242774b411f2fed9:core/Makefile;l=2292;bpv=1;bpt=0;drc=ea8f34bc1d6e63656b4ec32f2391e9d54b3ebb6b
			addStr("erofs_sparse_flag", "-s")
		}
	}
	// Raise an exception if the propfile contains erofs properties, but the fstype is not erofs
	if fs := fsTypeStr(f.fsType(ctx)); fs != "erofs" && (f.properties.Erofs.Compressor != nil || f.properties.Erofs.Compress_hints != nil || f.properties.Erofs.Sparse != nil) {
		ctx.PropertyErrorf("erofs", "erofs is non-empty, but FS type is %s\n. Please delete erofs properties if this partition should use %s\n", fs, fs)
	}

	propFile = android.PathForModuleOut(ctx, "prop").OutputPath
	propFile = android.PathForModuleOut(ctx, "prop").OutputPath
	android.WriteFileRuleVerbatim(ctx, propFile, propFileString.String())
	android.WriteFileRuleVerbatim(ctx, propFile, propFileString.String())
	return propFile, deps
	return propFile, deps
+25 −0
Original line number Original line Diff line number Diff line
@@ -559,3 +559,28 @@ func TestFilterOutUnsupportedArches(t *testing.T) {
		}
		}
	}
	}
}
}

func TestErofsPartition(t *testing.T) {
	result := fixture.RunTestWithBp(t, `
		android_filesystem {
			name: "erofs_partition",
			type: "erofs",
			erofs: {
				compressor: "lz4hc,9",
				compress_hints: "compress_hints.txt",
			},
			deps: ["binfoo"],
		}

		cc_binary {
			name: "binfoo",
		}
	`)

	partition := result.ModuleForTests("erofs_partition", "android_common")
	buildImageConfig := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("prop"))
	android.AssertStringDoesContain(t, "erofs fs type", buildImageConfig, "fs_type=erofs")
	android.AssertStringDoesContain(t, "erofs fs type compress algorithm", buildImageConfig, "erofs_default_compressor=lz4hc,9")
	android.AssertStringDoesContain(t, "erofs fs type compress hint", buildImageConfig, "erofs_default_compress_hints=compress_hints.txt")
	android.AssertStringDoesContain(t, "erofs fs type sparse", buildImageConfig, "erofs_sparse_flag=-s")
}