fix Asm cache bug, remove as_opts

This commit is contained in:
Ethan Roseman
2021-08-27 01:05:51 +09:00
parent ca25c679fe
commit 6abeb432bf
5 changed files with 21 additions and 9 deletions

View File

@@ -80,7 +80,7 @@ class AsmDifferWrapper:
# Base
if len(target_assembly.elf_object) == 0:
logger.info("Base asm empty - attempting to regenerate")
compiler_wrapper.CompilerWrapper.assemble_asm(compiler_arch, compilation.as_opts, target_assembly.source_asm, target_assembly)
compiler_wrapper.CompilerWrapper.assemble_asm(compiler_arch, target_assembly.source_asm, target_assembly)
if len(target_assembly.elf_object) == 0:
logger.error("Regeneration of base-asm failed")
return "Error: Base asm empty"

View File

@@ -184,14 +184,14 @@ class CompilerWrapper:
return (compilation, compile_proc.stderr)
@staticmethod
def assemble_asm(arch: str, as_opts: str, asm: Asm, to_regenerate:Assembly = None) -> Tuple[Optional[Assembly], Optional[str]]:
def assemble_asm(arch: str, asm: Asm, to_regenerate:Assembly = None) -> Tuple[Optional[Assembly], Optional[str]]:
if arch not in _arches:
logger.error(f"Arch {arch} not found")
return (None, "arch not found")
# Use the cache if we're not manually re-running an Assembly
if not to_regenerate:
cached_assembly, hash = _check_assembly_cache(arch, as_opts, asm)
cached_assembly, hash = _check_assembly_cache(arch, asm.data)
if cached_assembly:
logger.debug(f"Assembly cache hit!")
return (cached_assembly, None)
@@ -214,7 +214,6 @@ class CompilerWrapper:
"PATH": PATH,
"INPUT": sandbox.rewrite_path(asm_path),
"OUTPUT": sandbox.rewrite_path(object_path),
"AS_OPTS": sandbox.quote_options(as_opts),
})
except subprocess.CalledProcessError as e:
# Compilation failed
@@ -235,7 +234,6 @@ class CompilerWrapper:
assembly = Assembly(
hash=hash,
arch=arch,
as_opts=as_opts,
source_asm=asm,
elf_object=object_path.read_bytes(),
)

View File

@@ -0,0 +1,17 @@
# Generated by Django 3.2.4 on 2021-08-26 16:03
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('coreapp', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='assembly',
name='as_opts',
),
]

View File

@@ -24,7 +24,6 @@ class Assembly(models.Model):
hash = models.CharField(max_length=64, primary_key=True)
time = models.DateTimeField(auto_now_add=True)
arch = models.CharField(max_length=100)
as_opts = models.TextField(max_length=1000, blank=True, null=True)
source_asm = models.ForeignKey(Asm, on_delete=models.CASCADE)
elf_object = models.BinaryField(blank=True)

View File

@@ -82,8 +82,7 @@ def scratch(request, slug=None):
asm = get_db_asm(target_asm)
as_opts = ""
assembly, err = CompilerWrapper.assemble_asm(arch, as_opts, asm)
assembly, err = CompilerWrapper.assemble_asm(arch, asm)
if not assembly:
error_msg = f"Error when assembling target asm: {err}"
logging.error(error_msg)
@@ -104,7 +103,6 @@ def scratch(request, slug=None):
"arch": arch,
"compiler": compiler,
"cc_opts": cc_opts,
"as_opts": as_opts,
"context": context,
"source_code": source_code,
"target_assembly": assembly.pk,