Put the lardons into a large, cold, non-stick frying pan and turn the heat on low. Cook the lardons very gently, stirring occasionally, until the fat has melted into the pan and they are beginning to brown and crisp. Use a slotted spoon to lift the bacon into a mixing bowl and set aside, but keep all the fat in the pan.
Add the onions, oil and 2 thyme sprigs. Cook over a low heat for 20-25 mins until the onions are softened and beginning to turn golden. Stir in the sugar and cook over a higher heat for 5 mins more until golden brown. Tip into the bowl with the lardons and set aside to cool.
When the onions are just about cool, tip the bread mix into another mixing bowl with leaves stripped from 1 thyme sprig, and make up following pack instructions, but don’t knead or rise. Scatter the semolina, polenta or flour over a 30 x 40cm shallow tin or baking tray, and roll out the dough to fit it. Season the ricotta with 1 tsp salt and some pepper, and spread over the dough, leaving a small border. Mix the egg and Gruyere into the onion mixture with seasoning, then spread over the ricotta. Scatter with remaining thyme. Open-freeze for 2 hrs, then wrap well in cling film and freeze for up to 3 months. Or heat oven to 200C/ 180C fan/gas 6 to bake straight away.
Cook for 40 mins until base is crisp and golden, then eat warm or cool, sliced into pieces with a green salad. To bake from frozen, heat oven to 160C/140C fan/gas 3 and bake for 30 mins, then increase temp to 200C/180C fan/gas 6 for 15-20 mins.