Bug 860860 - followup: fix json.dump call and be more explicit about object ordering; r=gps

It turns out the simple s/simplejson/json/ didn't work because
build_tooltool_manifest used item_sort_key to ensure that the objects
read in were written out in the same order.  This scheme was brittle,
since it only understand a couple of keys from the manifest file, and it
doesn't work with the stdlib json.

Instead, use object_pairs_hook=collections.OrderedDict with json.load,
which ensures that current objects get written out in the same order
they were read in *and* that any future keys will be handled
automagically.

DONTBUILD because NPOTB
This commit is contained in:
Nathan Froyd 2013-04-11 16:57:54 -04:00
parent 74eca3c9ea
commit a83b0a8ab2

View File

@ -16,6 +16,7 @@ import subprocess
import platform
import sys
import json
import collections
def check_run(args):
r = subprocess.call(args)
@ -74,26 +75,16 @@ def build_one_stage(env, stage_dir, is_stage_one):
with_env(env, f)
def build_tooltool_manifest():
def key_sort(item):
item = item[0]
if item == 'size':
return 0
if item == 'digest':
return 1
if item == 'algorithm':
return 3
return 4
basedir = os.path.split(os.path.realpath(sys.argv[0]))[0]
tooltool = basedir + '/tooltool.py'
setup = basedir + '/setup.sh'
manifest = 'clang.manifest'
check_run(['python', tooltool, '-m', manifest, 'add',
setup, 'clang.tar.bz2'])
data = json.load(file(manifest))
data = json.load(file(manifest), object_pairs_hook=collections.OrderedDict)
data = [{'clang_version' : 'r%s' % llvm_revision }] + data
out = file(manifest,'w')
json.dump(data, out, indent=0, item_sort_key=key_sort)
json.dump(data, out, indent=0)
out.write('\n')
assert data[2]['filename'] == 'clang.tar.bz2'