Add clobber mach commands

RESOLVED FIXED in mozilla20

Status

defect
RESOLVED FIXED
7 years ago
Last year

People

(Reporter: gps, Assigned: gps)

Tracking

Trunk
mozilla20

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [mach])

Attachments

(1 attachment, 1 obsolete attachment)

Assignee

Description

7 years ago
A couple people asked for mach to have "clean" and "clobber" commands. This patch implements them.

Patch is trivial. It does include a minor change to proxy process exit codes properly. The ignore_errors bit is there so we don't raise an exception if make exits with a non-0 exit code.
Attachment #673071 - Flags: review?(mh+mozilla)
Comment on attachment 673071 [details] [diff] [review]
clobber and clean mach commands, v1

Review of attachment 673071 [details] [diff] [review]:
-----------------------------------------------------------------

::: python/mozbuild/mach/commands/build.py
@@ +48,5 @@
>              self.log(logging.INFO, 'build_output', {'line': line}, '{line}')
>  
> +        result = self._run_make(srcdir=True, filename='client.mk',
> +            line_handler=on_line, log=False, print_directory=False,
> +            ignore_errors=True)

ignore_errors=True doesn't seem like a good idea for build().

@@ +62,5 @@
> +    @Command('clean', help='Clean the build directory.')
> +    def clean(self):
> +        return self._run_make_target('clean')
> +
> +    @Command('clobber', help='Clobber (remove) the object directory.')

That's a lie. make clobber is strictly identical to make clean. However, I'd be in favor of a rule that actually just does that.

@@ +70,5 @@
> +    def _run_make_target(self, target):
> +        root_makefile = os.path.join(self.topobjdir, 'Makefile')
> +
> +        if not os.path.exists(root_makefile):
> +            print('%s does not contain build files. Nothing to do.' %

I've had cases where my objdir was lacking the Makefile, but almost nothing else. Might be better to just tell the truth and that there was no Makefile found thus nothing can be done.
Attachment #673071 - Flags: review?(mh+mozilla) → review-
Assignee

Comment 2

7 years ago
Removed contentious clean command. Focusing on clobber for now.

Added mozfile to mach's fake virtualenv environment because it has faster implementation of "delete all the things."
Assignee: nobody → gps
Attachment #673071 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Attachment #689071 - Flags: review?(mh+mozilla)
Assignee

Updated

7 years ago
Summary: Add clean and clobber mach commands → Add clobber mach commands
Whiteboard: [mach]
Attachment #689071 - Flags: review?(mh+mozilla) → review+
Assignee

Comment 3

7 years ago
https://hg.mozilla.org/mozilla-central/rev/051613fd8775
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla20

Comment 4

6 years ago
Comment on attachment 689071 [details] [diff] [review]
Add clobber mach command, v2

># HG changeset patch
># Parent 137d80a07e64b82e2fbc95c9a0a7cc8690376bf4
># User Gregory Szorc <gps@mozilla.com>
>Bug 803400 - Add clobber mach command
>
>diff --git a/mach b/mach
>--- a/mach
>+++ b/mach
>@@ -27,16 +27,17 @@
>     'python/blessings',
>     'python/psutil',
>     'python/which',
>     'other-licenses/ply',
>     'xpcom/idl-parser',
>     'testing',
>     'testing/xpcshell',
>     'testing/mozbase/mozprocess',
>+    'testing/mozbase/mozfile',
>     'testing/mozbase/mozinfo',
> ]
> 
> # Individual files providing mach commands.
> MACH_MODULES = [
>     'layout/tools/reftest/mach_commands.py',
>     'python/mozboot/mozboot/mach_commands.py',
>     'python/mozbuild/mozbuild/config.py',
>diff --git a/python/mozbuild/mozbuild/base.py b/python/mozbuild/mozbuild/base.py
>--- a/python/mozbuild/mozbuild/base.py
>+++ b/python/mozbuild/mozbuild/base.py
>@@ -8,16 +8,18 @@
> import os
> import subprocess
> import sys
> import which
> 
> from mach.mixin.logging import LoggingMixin
> from mach.mixin.process import ProcessExecutionMixin
> 
>+from mozfile.mozfile import rmtree
>+
> from .config import BuildConfig
> from .mozconfig import (
>     MozconfigFindException,
>     MozconfigLoadException,
>     MozconfigLoader,
> )
> 
> 
>@@ -77,16 +79,23 @@
>     @property
>     def bindir(self):
>         return os.path.join(self.topobjdir, 'dist', 'bin')
> 
>     @property
>     def statedir(self):
>         return os.path.join(self.topobjdir, '.mozbuild')
> 
>+    def remove_objdir(self):
>+        """Remove the entire object directory."""
>+
>+        # We use mozfile because it is faster than shutil.rmtree().
>+        # mozfile doesn't like unicode arguments (bug 818783).
>+        rmtree(self.topobjdir.encode('utf-8'))
>+
>     @property
>     def _config_guess(self):
>         if self._config_guess_output is None:
>             p = os.path.join(self.topsrcdir, 'build', 'autoconf',
>                 'config.guess')
>             args = self._normalize_command([p], True)
>             self._config_guess_output = subprocess.check_output(args,
>                 cwd=self.topsrcdir).strip()
>diff --git a/python/mozbuild/mozbuild/mach_commands.py b/python/mozbuild/mozbuild/mach_commands.py
>--- a/python/mozbuild/mozbuild/mach_commands.py
>+++ b/python/mozbuild/mozbuild/mach_commands.py
>@@ -56,16 +56,21 @@
>         self.log(logging.WARNING, 'warning_summary',
>             {'count': len(warnings_collector.database)},
>             '{count} compiler warnings present.')
> 
>         warnings_database.save_to_file(warnings_path)
> 
>         return status
> 
>+    @Command('clobber', help='Clobber the tree (delete the object directory).')
>+    def clobber(self):
>+        self.remove_objdir()
>+        return 0
>+
> 
> @CommandProvider
> class Warnings(MachCommandBase):
>     """Provide commands for inspecting warnings."""
> 
>     @property
>     def database_path(self):
>         return self._get_state_filename('warnings.json')

Comment 5

6 years ago
Comment on attachment 689071 [details] [diff] [review]
Add clobber mach command, v2

># HG changeset patch
># Parent 137d80a07e64b82e2fbc95c9a0a7cc8690376bf4
># User Gregory Szorc <gps@mozilla.com>
>Bug 803400 - Add clobber mach command
>
>diff --git a/mach b/mach
>--- a/mach
>+++ b/mach
>@@ -27,16 +27,17 @@
>     'python/blessings',
>     'python/psutil',
>     'python/which',
>     'other-licenses/ply',
>     'xpcom/idl-parser',
>     'testing',
>     'testing/xpcshell',
>     'testing/mozbase/mozprocess',
>+    'testing/mozbase/mozfile',
>     'testing/mozbase/mozinfo',
> ]
> 
> # Individual files providing mach commands.
> MACH_MODULES = [
>     'layout/tools/reftest/mach_commands.py',
>     'python/mozboot/mozboot/mach_commands.py',
>     'python/mozbuild/mozbuild/config.py',
>diff --git a/python/mozbuild/mozbuild/base.py b/python/mozbuild/mozbuild/base.py
>--- a/python/mozbuild/mozbuild/base.py
>+++ b/python/mozbuild/mozbuild/base.py
>@@ -8,16 +8,18 @@
> import os
> import subprocess
> import sys
> import which
> 
> from mach.mixin.logging import LoggingMixin
> from mach.mixin.process import ProcessExecutionMixin
> 
>+from mozfile.mozfile import rmtree
>+
> from .config import BuildConfig
> from .mozconfig import (
>     MozconfigFindException,
>     MozconfigLoadException,
>     MozconfigLoader,
> )
> 
> 
>@@ -77,16 +79,23 @@
>     @property
>     def bindir(self):
>         return os.path.join(self.topobjdir, 'dist', 'bin')
> 
>     @property
>     def statedir(self):
>         return os.path.join(self.topobjdir, '.mozbuild')
> 
>+    def remove_objdir(self):
>+        """Remove the entire object directory."""
>+
>+        # We use mozfile because it is faster than shutil.rmtree().
>+        # mozfile doesn't like unicode arguments (bug 818783).
>+        rmtree(self.topobjdir.encode('utf-8'))
>+
>     @property
>     def _config_guess(self):
>         if self._config_guess_output is None:
>             p = os.path.join(self.topsrcdir, 'build', 'autoconf',
>                 'config.guess')
>             args = self._normalize_command([p], True)
>             self._config_guess_output = subprocess.check_output(args,
>                 cwd=self.topsrcdir).strip()
>diff --git a/python/mozbuild/mozbuild/mach_commands.py b/python/mozbuild/mozbuild/mach_commands.py
>--- a/python/mozbuild/mozbuild/mach_commands.py
>+++ b/python/mozbuild/mozbuild/mach_commands.py
>@@ -56,16 +56,21 @@
>         self.log(logging.WARNING, 'warning_summary',
>             {'count': len(warnings_collector.database)},
>             '{count} compiler warnings present.')
> 
>         warnings_database.save_to_file(warnings_path)
> 
>         return status
> 
>+    @Command('clobber', help='Clobber the tree (delete the object directory).')
>+    def clobber(self):
>+        self.remove_objdir()
>+        return 0
>+
> 
> @CommandProvider
> class Warnings(MachCommandBase):
>     """Provide commands for inspecting warnings."""
> 
>     @property
>     def database_path(self):
>         return self._get_state_filename('warnings.json')

Updated

Last year
Product: Core → Firefox Build System
You need to log in before you can comment on or make changes to this bug.