It's done a bit more cleverly than that, but the general approach of running a competition in a way that makes it difficult for non-domestic competitors is definitely done, if not in railways then certainly in other sectors. I suspect the reason it doesn't get legally challenged - which would definitely be justified - is that (e.g.) Siemens knows it's got the German market, and Alstom knows it's got the French market, and both feel that losing out on contracts on the other is an acceptable price for being secure in their home market.
The UK makes a rod for its' own back with this in some ways - the classic case in my sector is the MARS contracts for naval logistic support ships. EU competition rules require that the contract goes out to an open tender - the nature of the ships isn't sufficiently military for a national security exemption. The first contract went to a Korean shipyard, and no UK yards bid as they didn't feel they had the ability to compete. There have been political demands for the second contract to be awarded in the UK, regardless of the requirement for competition. The point is raised that, somehow, the French Navy builds equivalent ships in France, the Italian Navy in Italy, the Spanish Navy in Spain, and so forth. Exactly how they do it isn't clear, but they're definitely doing something. I'd imagine that whatever the Marine Nationale is doing, SNCF is also doing.