Replace roundabout way of setting up sccache

This commit is contained in:
Stephen Seo 2022-09-07 15:28:09 +09:00
parent 22203fee1f
commit 006bafc4fb

View file

@ -618,7 +618,7 @@ def cleanup_sudo(sudo_proc):
def create_executable_script(dest_filename, script_contents): def create_executable_script(dest_filename, script_contents):
"""Creates a script to be run with sudo to set up a custom command. """Creates a script via use of sudo to be executed later.
This is currently used to set up sccache by placing custom commands in This is currently used to set up sccache by placing custom commands in
"/usr/local/bin" for gcc and friends.""" "/usr/local/bin" for gcc and friends."""
@ -627,40 +627,26 @@ def create_executable_script(dest_filename, script_contents):
with tempfile.NamedTemporaryFile( with tempfile.NamedTemporaryFile(
mode="w", encoding="utf-8", delete=False mode="w", encoding="utf-8", delete=False
) as tempf: ) as tempf:
print( print(script_contents, file=tempf)
"""#!/usr/bin/env python3
import os
import stat
import argparse
def create_executable_script(dest_filename, script_contents):
with open(dest_filename, mode='w', encoding='utf-8') as f:
f.write(script_contents)
os.chmod(dest_filename, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
| stat.S_IRGRP | stat.S_IXGRP
| stat.S_IROTH | stat.S_IXOTH)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Set new file with execute permissions")
parser.add_argument("--dest_filename")
parser.add_argument("--script_contents")
args = parser.parse_args()
create_executable_script(args.dest_filename, args.script_contents)
""",
file=tempf,
)
tempf_name = tempf.name tempf_name = tempf.name
try: try:
subprocess.run( subprocess.run(
[ [
"sudo",
"/usr/bin/env", "/usr/bin/env",
"python3", "sudo",
"cp",
tempf_name, tempf_name,
"--dest_filename",
dest_filename, dest_filename,
"--script_contents", ],
script_contents, check=True,
)
subprocess.run(
[
"/usr/bin/env",
"sudo",
"chmod",
"a+rx",
dest_filename,
], ],
check=True, check=True,
) )