From 6e1aa7830c9b3a37c22eb48736929227b39b7487 Mon Sep 17 00:00:00 2001 From: Usta Shrestha Date: Mon, 13 Feb 2023 18:54:42 -0500 Subject: [PATCH] simplify `m clean` `rm -rf out` used to fail because bazel would not set write permission on some files. Now it's been fixed and thus there is little reason to prefer `m clean` (also users are accustomed to `rm -rf out`) Bug: NA Test: verified `m clean` works;interestingly soong_metrics file is created at the end Change-Id: I000d16508613045811fc7792e5798f7c150dcc05 --- tests/soong_test.sh | 8 ++------ ui/build/cleanbuild.go | 29 ----------------------------- 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/tests/soong_test.sh b/tests/soong_test.sh index f7bee4008..6779d8a95 100755 --- a/tests/soong_test.sh +++ b/tests/soong_test.sh @@ -9,12 +9,8 @@ source "$(dirname "$0")/lib.sh" function test_m_clean_works { setup - # Create a directory with files that cannot be removed - mkdir -p out/bad_directory_permissions - touch out/bad_directory_permissions/unremovable_file - # File permissions are fine but directory permissions are bad - chmod a+rwx out/bad_directory_permissions/unremovable_file - chmod a-rwx out/bad_directory_permissions + mkdir -p out/some_directory + touch out/some_directory/some_file run_soong clean } diff --git a/ui/build/cleanbuild.go b/ui/build/cleanbuild.go index fd601772c..ee5332735 100644 --- a/ui/build/cleanbuild.go +++ b/ui/build/cleanbuild.go @@ -17,7 +17,6 @@ package build import ( "bytes" "fmt" - "io/fs" "io/ioutil" "os" "path/filepath" @@ -59,37 +58,9 @@ const ( FILEMODE_USER_EXECUTE = FILEMODE_EXECUTE << FILEMODE_USER_SHIFT ) -// Ensures that files and directories in the out dir can be deleted. -// For example, Bazen can generate output directories where the write bit isn't set, causing 'm' clean' to fail. -func ensureOutDirRemovable(ctx Context, config Config) { - err := filepath.WalkDir(config.OutDir(), func(path string, d fs.DirEntry, err error) error { - if err != nil { - return err - } - if d.IsDir() { - info, err := d.Info() - if err != nil { - return err - } - // Equivalent to running chmod u+rwx on each directory - newMode := info.Mode() | FILEMODE_USER_READ | FILEMODE_USER_WRITE | FILEMODE_USER_EXECUTE - if err := os.Chmod(path, newMode); err != nil { - return err - } - } - // Continue walking the out dir... - return nil - }) - if err != nil && !os.IsNotExist(err) { - // Display the error, but don't crash. - ctx.Println(err.Error()) - } -} - // Remove everything under the out directory. Don't remove the out directory // itself in case it's a symlink. func clean(ctx Context, config Config) { - ensureOutDirRemovable(ctx, config) removeGlobs(ctx, filepath.Join(config.OutDir(), "*")) ctx.Println("Entire build directory removed.") }