You are asking two questions.
1. The Ar-15 production barrels are head spaced when they are produced. The barrel extension is installed and the chamber is reamed to spec. When you buy an AR-15 barrel, the barrel will already have the barrel extension installed on the barrel. When you install a barrel on an AR-15, you are using the barrel retain nut to tighten the completed barrel/extension on the upper receiver. The use of head spacing gauges are to confirm that the new bolt, and barrel/attached extension are within specs. This can be done with just the bolt and raw barrel not installed in the rifle.
2. To build a barrel out of blank stock(rifled only), then you must turn the barrel to the correct outside dimensions, thread the barrel for a extension(barrel locking lugs).
Once the extension is installed(spec'd to allow the bolt to lock up, yet not rattle due to too large of spacing), the barrel port is cut to aline with the the feed ramps and indexing pin. The bolt is spec'd for distance from the rear of the lugs, the bolt face, and them the barrel is reamed to match the bolt to chamber.
On production barrels, there is a mil-spec used to allow a broad range of tolerances of chambers and bolts. On match barrels, the process takes longer due to holding tighter tolerances between a specific bolt that will be used with the barrel chamber. Also, depending on the type of bullets that will be used for the new barrel, twist and barrel throat are taken into consideration too.
Here is a link to the whole process.
www.compasslake.com/barrels.htmHope this helps.