Commit 3842a394 authored by inglorion's avatar inglorion Committed by Commit Bot

Correct fallback and mtime in distributed ThinLTO scripts

This change makes two improvements to the distributed ThinLTO scripts:
 1. When no code generation is necessary, invokes the local linker
    correctly even when --gomacc or --jobs options are specified.
 2. Change create_file to ensure_file to only create files if they
    do not already exist, reducing unnecessary rebuilding.

R=gbiv,hans,rnk,thakis
BUG=877722

Change-Id: I29ffa028202c31f77df95d306432f726e3f7bda9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2039996
Auto-Submit: Bob Haarman <inglorion@chromium.org>
Reviewed-by: default avatarGeorge Burgess <gbiv@chromium.org>
Commit-Queue: George Burgess <gbiv@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738684}
parent df895679
...@@ -55,14 +55,6 @@ def autoninja(): ...@@ -55,14 +55,6 @@ def autoninja():
return name return name
def create_file(path):
"""
Creates an empty file at path, creating parent directories if needed.
"""
ensure_dir(os.path.dirname(path))
open(path, 'wb').close()
def ensure_dir(path): def ensure_dir(path):
""" """
Creates path as a directory if it does not already exist. Creates path as a directory if it does not already exist.
...@@ -76,6 +68,20 @@ def ensure_dir(path): ...@@ -76,6 +68,20 @@ def ensure_dir(path):
raise raise
def ensure_file(path):
"""
Creates an empty file at path if it does not already exist.
Also creates directories as needed.
"""
ensure_dir(os.path.dirname(path))
try:
fd = os.open(path, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o644)
os.close(fd)
except OSError as e:
if e.errno != errno.EEXIST:
raise
def exe_suffix(): def exe_suffix():
if os.name == 'nt': if os.name == 'nt':
return '.exe' return '.exe'
...@@ -395,7 +401,7 @@ class GomaLinkBase(object): ...@@ -395,7 +401,7 @@ class GomaLinkBase(object):
index = common_index index = common_index
else: else:
index = obj_dir + '/' + param + '.thinlto.bc' index = obj_dir + '/' + param + '.thinlto.bc'
create_file(index) ensure_file(index)
codegen.append((os.path.normpath(native), param, index)) codegen.append((os.path.normpath(native), param, index))
else: else:
final_params.append(param) final_params.append(param)
...@@ -549,10 +555,10 @@ class GomaLinkBase(object): ...@@ -549,10 +555,10 @@ class GomaLinkBase(object):
# If we determined that no distributed code generation need be done, just # If we determined that no distributed code generation need be done, just
# invoke the original command. # invoke the original command.
if params is None: if params is None:
return subprocess.call(argv[1:]) return subprocess.call([args.linker] + args.linker_args)
if use_common_objects: if use_common_objects:
objs = [x[0] for x in params.codegen] objs = [x[0] for x in params.codegen]
create_file(common_dir + '/empty.thinlto.bc') ensure_file(common_dir + '/empty.thinlto.bc')
else: else:
objs = self.thin_link(params, gen_dir) objs = self.thin_link(params, gen_dir)
self.codegen_and_link(params, gen_dir, objs) self.codegen_and_link(params, gen_dir, objs)
......
...@@ -107,26 +107,30 @@ class GomaLinkUnitTest(unittest.TestCase): ...@@ -107,26 +107,30 @@ class GomaLinkUnitTest(unittest.TestCase):
Unit tests for goma_link. Unit tests for goma_link.
""" """
def test_create_file_no_dir(self): def test_ensure_file_no_dir(self):
with NamedDirectory() as d, WorkingDirectory(d): with NamedDirectory() as d, WorkingDirectory(d):
self.assertFalse(os.path.exists('test')) self.assertFalse(os.path.exists('test'))
goma_link.create_file('test') goma_link.ensure_file('test')
self.assertTrue(os.path.exists('test')) self.assertTrue(os.path.exists('test'))
def test_create_file_existing(self): def test_ensure_file_existing(self):
with NamedDirectory() as d, WorkingDirectory(d): with NamedDirectory() as d, WorkingDirectory(d):
self.assertFalse(os.path.exists('foo/test')) self.assertFalse(os.path.exists('foo/test'))
goma_link.create_file('foo/test') goma_link.ensure_file('foo/test')
self.assertTrue(os.path.exists('foo/test')) self.assertTrue(os.path.exists('foo/test'))
goma_link.create_file('foo/test') os.utime('foo/test', (0, 0))
statresult = os.stat('foo/test')
goma_link.ensure_file('foo/test')
self.assertTrue(os.path.exists('foo/test')) self.assertTrue(os.path.exists('foo/test'))
newstatresult = os.stat('foo/test')
self.assertEqual(newstatresult.st_mtime, statresult.st_mtime)
def test_create_file_error(self): def test_ensure_file_error(self):
with NamedDirectory() as d, WorkingDirectory(d): with NamedDirectory() as d, WorkingDirectory(d):
self.assertFalse(os.path.exists('test')) self.assertFalse(os.path.exists('test'))
goma_link.create_file('test') goma_link.ensure_file('test')
self.assertTrue(os.path.exists('test')) self.assertTrue(os.path.exists('test'))
self.assertRaises(IOError, goma_link.create_file, 'test/impossible') self.assertRaises(OSError, goma_link.ensure_file, 'test/impossible')
class GomaLinkIntegrationTest(unittest.TestCase): class GomaLinkIntegrationTest(unittest.TestCase):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment