Skip to content

Commit

Permalink
Bug 1530134 - Run clang-format without docker as a fallback, r=jcj
Browse files Browse the repository at this point in the history
Running clang-format with a bad version is better than not running it at all.

Reviewers: jcj

Reviewed By: jcj

Bug #: 1530134

Differential Revision: https://phabricator.services.mozilla.com/D20938

--HG--
extra : rebase_source : 9ce88b3080bb5dfd2b3705da44f972a6a9d96526
extra : amend_source : 855c6537e98728049e0256a2601b8ca32c166320
  • Loading branch information
martinthomson committed Feb 25, 2019
1 parent 2b7e5b9 commit 8017135
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions mach
Expand Up @@ -39,28 +39,33 @@ def run_tests(test, cycles="standard", env={}, silent=False):
subprocess.check_call(command, env=os_env, stdout=stdout, stderr=stderr)

class cfAction(argparse.Action):
docker_command = ["docker"]
docker_command = None
restorecon = None

def __call__(self, parser, args, values, option_string=None):
if not args.noroot:
self.setDockerCommand()
self.setDockerCommand(args)

if values:
files = [os.path.relpath(os.path.abspath(x), start=cwd) for x in values]
else:
files = self.modifiedFiles()
files = [os.path.join('/home/worker/nss', x) for x in files]

# First check if we can run docker.
try:
with open(os.devnull, "w") as f:
subprocess.check_call(
self.docker_command + ["images"], stdout=f)
except:
print("Please install docker and start the docker daemon.")
sys.exit(1)
self.docker_command = None

if self.docker_command is None:
print("warning: running clang-format directly, which isn't guaranteed to be correct")
command = [cwd + "/automation/clang-format/run_clang_format.sh"] + files
repr(command)
subprocess.call(command)
return

files = [os.path.join('/home/worker/nss', x) for x in files]
docker_image = 'clang-format-service:latest'
cf_docker_folder = cwd + "/automation/clang-format"

Expand Down Expand Up @@ -113,11 +118,17 @@ class cfAction(argparse.Action):
subprocess.check_call(command)
return

def setDockerCommand(self):
def setDockerCommand(self, args):
from distutils.spawn import find_executable
if platform.system() == "Linux":
from distutils.spawn import find_executable
self.restorecon = find_executable('restorecon')
self.docker_command = ["sudo"] + self.docker_command
self.restorecon = find_executable("restorecon")
dcmd = find_executable("docker")
if dcmd is not None:
self.docker_command = [dcmd]
if not args.noroot:
self.docker_command = ["sudo"] + self.docker_command
else:
self.docker_command = None

def modifiedFiles(self):
files = []
Expand Down

0 comments on commit 8017135

Please sign in to comment.