osbuild.py/pipeline: assign a unique id to every pipeline

This uniquely identifies a pipeline based on its content. Pipelines
are considered equal modulo whitespace and the order of object
elements.

The intention is that two runs of a pipeline with the same id
generates functionaly equivalent ids. It is up to the writers
of stages and pipelines to ensure this property holds.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2019-07-02 21:19:15 +02:00 committed by Lars Karlitski
parent 1219f1dc55
commit f25cffa151
2 changed files with 8 additions and 0 deletions

View file

@ -1,4 +1,5 @@
import hashlib
import json
import os
import subprocess
@ -203,6 +204,10 @@ def print_header(title, options, machine_name):
class Pipeline:
def __init__(self, pipeline):
m = hashlib.sha256()
m.update(json.dumps(pipeline, sort_keys=True).encode())
self.id = m.hexdigest()
self.stages = pipeline["stages"]
self.assembler = pipeline.get("assembler")