Preheat oven to 375 degrees F.
Place the eggplant and onions on a baking sheet lined with parchment paper. Drizzle with the oil and toss to combine. Roast for 75 to 80 minutes, stirring occasionally, until the eggplant is very tender and caramelized. Transfer the roasted vegetables to a medium-sized pot and mix in the strained tomatoes or tomato sauce and stock. Bring the mixture to a gentle simmer. Loosely cover and gently simmer 10 minutes. Mix in the pesto, salt and pepper and the sauce is ready to use.