models: link current variant more carefully #1329
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of changes:
We were still seeing some rare, random build failures after #1303, and tracked it down to the fact that cargo calls models' build.rs script multiple times: once for the build-dep in storewolf, once for the (regular) dep in storewolf, and once (much later) for the dep in the static build of apiclient. The first two have a chance of running at the same time and racing to delete/create the symlink, causing a failure. (I think it's correct for cargo to run it multiple times, since each of those is running in a different environment; build-dep vs. dep, for example, use the host build toolchain versus the target build toolchain.)
Example error from #1318:
Failed to create symlink at 'src/variant/current' pointing to '../aws-ecs-1' - we need this to support different API models for different variants. Error: File exists (os error 17)"
This PR makes a few related changes to make this process safer. First, we only run the model build.rs once, during the "host" build for the build-dep in storewolf, by checking CARGO_CFG_TARGET_VENDOR. Second, in case they do happen to run at the same time for other unexpected reasons, it now uses an atomic link-swap rather than a remove/create so we can't race. Third, just to be tidy, it alerts cargo that it should rerun if either of our links change, though this should only happen if someone manually deletes a link or something.
Testing done:
I built and ran a k8s AMI OK, then an ECS AMI, then a k8s AMI again. (This is to ensure I didn't reintroduce the issue solved in #1319, and for general health.)
I checked the build log and saw that later build.rs runs exited quickly:
Also, local testing shows the symlink being swapped around OK. Starting with aws-k8s-1.17 linked, rebuilding keeps it:
Changing variant works:
Removing the files gets them recreated:
Changing them does too:
Terms of contribution:
By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.