@@ -672,7 +672,19 @@ fn resolve_api<'a>(
672672 let latest_generated = api_generated. latest_link ( ) . expect (
673673 "\" generated\" source should always have a \" latest\" link" ,
674674 ) ;
675- let symlink = match api_local. and_then ( |l| l. latest_link ( ) ) {
675+ let generated_version =
676+ latest_generated. version ( ) . expect ( "versioned APIs have a version" ) ;
677+ let resolution =
678+ by_version. get ( generated_version) . unwrap_or_else ( || {
679+ panic ! (
680+ "by_version map should have a version \
681+ corresponding to latest_generated ({})",
682+ latest_generated
683+ )
684+ } ) ;
685+
686+ let latest_local = api_local. and_then ( |l| l. latest_link ( ) ) ;
687+ let symlink = match latest_local {
676688 Some ( latest_local) => {
677689 if latest_local == latest_generated {
678690 None
@@ -689,95 +701,123 @@ fn resolve_api<'a>(
689701 // 1. latest_local is blessed, latest_generated has the same
690702 // version as latest_local, and it has wire-compatible
691703 // changes. In that case, don't update the symlink.
704+ //
692705 // 2. latest_local is blessed, latest_generated has the same
693706 // version as latest_local, and latest_generated has
694707 // wire-*incompatible* changes. In that case, we'd have
695708 // returned errors in the by_version map above, and we
696709 // wouldn't want to update the symlink in any case.
710+ //
697711 // 3. latest_local is blessed, and latest_generated is
698712 // blessed but a *different* version. This means that
699713 // the latest version was retired. In this case,
700714 // we want to update the symlink to the blessed hash
701715 // corresponding to the latest generated version.
716+ //
702717 // 4. latest_local is not blessed. In that case, we do
703718 // want to update the symlink.
704- let generated_version = latest_generated
705- . version ( )
706- . expect ( "versioned APIs have a version" ) ;
707719 let local_version = latest_local
708720 . version ( )
709721 . expect ( "versioned APIs have a version" ) ;
710- if let Some ( resolution) = by_version. get ( generated_version)
711- {
712- match resolution. kind ( ) {
713- ResolutionKind :: Lockstep => {
714- unreachable ! ( "this is a versioned API" ) ;
715- }
716- // Case 1 and 2 above.
717- ResolutionKind :: Blessed
718- if generated_version == local_version =>
719- {
720- // latest_generated is blessed and the same
721- // version as latest_local, so don't update the
722- // symlink.
723- None
724- }
725- ResolutionKind :: Blessed => {
726- // latest_generated is blessed, and has a
727- // different version from latest_local. In this
728- // case, we want to update the symlink to the
729- // blessed version matching latest_generated
730- // (not latest_generated, in case it's different
731- // from the blessed version in a wire-compatible
732- // way!)
733- let api_blessed =
734- api_blessed. unwrap_or_else ( || {
735- panic ! (
736- "for {}, Blessed means \
737- api_blessed exists",
738- api. ident( )
739- )
740- } ) ;
741- let blessed = api_blessed
742- . versions ( )
743- . get ( generated_version)
744- . unwrap_or_else ( || {
745- panic ! (
746- "for {} v{}, Blessed means \
747- generated_version exists",
748- api. ident( ) ,
749- generated_version
750- ) ;
751- } ) ;
752- Some ( Problem :: LatestLinkStale {
753- api_ident : api. ident ( ) . clone ( ) ,
754- link : blessed. spec_file_name ( ) ,
755- found : latest_local,
756- } )
757- }
758- ResolutionKind :: NewLocally => {
759- // latest_generated is not blessed, so update
760- // the symlink.
761- Some ( Problem :: LatestLinkStale {
762- api_ident : api. ident ( ) . clone ( ) ,
763- link : latest_generated,
764- found : latest_local,
765- } )
766- }
722+ match resolution. kind ( ) {
723+ ResolutionKind :: Lockstep => {
724+ unreachable ! ( "this is a versioned API" ) ;
725+ }
726+ // Case 1 and 2 above.
727+ ResolutionKind :: Blessed
728+ if generated_version == local_version =>
729+ {
730+ // latest_generated is blessed and the same
731+ // version as latest_local, so don't update the
732+ // symlink.
733+ None
734+ }
735+ ResolutionKind :: Blessed => {
736+ // latest_generated is blessed, and has a
737+ // different version from latest_local. In this
738+ // case, we want to update the symlink to the
739+ // blessed version matching latest_generated
740+ // (not latest_generated, in case it's different
741+ // from the blessed version in a wire-compatible
742+ // way!)
743+ let api_blessed =
744+ api_blessed. unwrap_or_else ( || {
745+ panic ! (
746+ "for {}, Blessed means \
747+ api_blessed exists",
748+ api. ident( )
749+ )
750+ } ) ;
751+ let blessed = api_blessed
752+ . versions ( )
753+ . get ( generated_version)
754+ . unwrap_or_else ( || {
755+ panic ! (
756+ "for {} v{}, Blessed means \
757+ generated_version exists",
758+ api. ident( ) ,
759+ generated_version
760+ ) ;
761+ } ) ;
762+ Some ( Problem :: LatestLinkStale {
763+ api_ident : api. ident ( ) . clone ( ) ,
764+ link : blessed. spec_file_name ( ) ,
765+ found : latest_local,
766+ } )
767+ }
768+ ResolutionKind :: NewLocally => {
769+ // latest_generated is not blessed, so update
770+ // the symlink.
771+ Some ( Problem :: LatestLinkStale {
772+ api_ident : api. ident ( ) . clone ( ) ,
773+ link : latest_generated,
774+ found : latest_local,
775+ } )
767776 }
768- } else {
769- unreachable ! (
770- "by_version map should have a version \
771- corresponding to latest_generated ({})",
772- latest_generated
773- )
774777 }
775778 }
776779 }
777- None => Some ( Problem :: LatestLinkMissing {
778- api_ident : api. ident ( ) . clone ( ) ,
779- link : latest_generated,
780- } ) ,
780+ None => {
781+ // As in case 3 above, if the resolution is blessed, we want to
782+ // update the symlink to the *blessed() hash corresponding to
783+ // the latest generated version.
784+ match resolution. kind ( ) {
785+ ResolutionKind :: Lockstep => {
786+ unreachable ! ( "this is a versioned API" ) ;
787+ }
788+ ResolutionKind :: Blessed => {
789+ let api_blessed = api_blessed. unwrap_or_else ( || {
790+ panic ! (
791+ "for {}, Blessed means api_blessed exists" ,
792+ api. ident( )
793+ )
794+ } ) ;
795+ let blessed = api_blessed
796+ . versions ( )
797+ . get ( generated_version)
798+ . unwrap_or_else ( || {
799+ panic ! (
800+ "for {} v{}, Blessed means \
801+ generated_version exists",
802+ api. ident( ) ,
803+ generated_version
804+ ) ;
805+ } ) ;
806+ Some ( Problem :: LatestLinkMissing {
807+ api_ident : api. ident ( ) . clone ( ) ,
808+ link : blessed. spec_file_name ( ) ,
809+ } )
810+ }
811+ ResolutionKind :: NewLocally => {
812+ // latest_generated is not blessed, so update
813+ // the symlink to the generated version.
814+ Some ( Problem :: LatestLinkMissing {
815+ api_ident : api. ident ( ) . clone ( ) ,
816+ link : latest_generated,
817+ } )
818+ }
819+ }
820+ }
781821 } ;
782822
783823 ( by_version, symlink)
0 commit comments