@@ -10,6 +10,7 @@ internal static class SourceDependenciesHelper
1010 internal static bool RestoreSourceDependencies ( BuildContext context )
1111 {
1212 var product = context . Product ;
13+ var console = context . Console ;
1314
1415 if ( product . SourceDependencies . Length == 0 )
1516 {
@@ -25,7 +26,7 @@ internal static bool RestoreSourceDependencies( BuildContext context )
2526
2627 foreach ( var dependency in product . SourceDependencies )
2728 {
28- context . Console . WriteMessage ( $ "Restoring '{ dependency . Name } ' source dependency." ) ;
29+ console . WriteMessage ( $ "Restoring '{ dependency . Name } ' source dependency." ) ;
2930
3031 var localDirectory = Path . Combine ( context . RepoDirectory , ".." , dependency . Name ) ;
3132
@@ -35,28 +36,43 @@ internal static bool RestoreSourceDependencies( BuildContext context )
3536 {
3637 if ( ! Directory . Exists ( targetDirectory ) )
3738 {
38- context . Console . WriteMessage ( $ "Creating symbolic link to '{ localDirectory } ' in '{ targetDirectory } '." ) ;
39+ if ( context . IsContinuousIntegrationBuild )
40+ {
41+ console . WriteError ( "Cannot restore source dependencies in a Docker container. Prepare the build in the host first." ) ;
42+
43+ return false ;
44+ }
45+
46+ console . WriteMessage ( $ "Creating symbolic link to '{ localDirectory } ' in '{ targetDirectory } '." ) ;
3947 Directory . CreateSymbolicLink ( targetDirectory , localDirectory ) ;
4048
4149 if ( ! Directory . Exists ( targetDirectory ) )
4250 {
43- context . Console . WriteError ( $ "Symbolic link was not created for '{ targetDirectory } '." ) ;
51+ console . WriteError ( $ "Symbolic link was not created for '{ targetDirectory } '." ) ;
4452
4553 return false ;
4654 }
4755 }
4856 else
4957 {
50- context . Console . WriteMessage ( $ "Directory '{ targetDirectory } ' already exists." ) ;
58+ console . WriteMessage ( $ "Directory '{ targetDirectory } ' already exists." ) ;
5159 }
5260 }
5361 else
5462 {
5563 if ( ! Directory . Exists ( targetDirectory ) )
5664 {
65+ if ( context . IsContinuousIntegrationBuild )
66+ {
67+ // Avoid creating a mess in the host.
68+ console . WriteError ( "Cannot restore source dependencies in a Docker container. Prepare the build in the host first." ) ;
69+
70+ return false ;
71+ }
72+
5773 // If the target directory doesn't exist, we clone it to the source-dependencies directory with depth of 1 to mitigate the impact of cloning the whole history.
5874 if ( ! ToolInvocationHelper . InvokeTool (
59- context . Console ,
75+ console ,
6076 "git" ,
6177 $ "clone { dependency . VcsRepository . DeveloperMachineRemoteUrl } --branch { dependency . Branch } --depth 1",
6278 sourceDependenciesDirectory ) )
@@ -66,7 +82,7 @@ internal static bool RestoreSourceDependencies( BuildContext context )
6682 }
6783 else
6884 {
69- context . Console . WriteMessage ( $ "Directory '{ targetDirectory } ' already exists." ) ;
85+ console . WriteMessage ( $ "Directory '{ targetDirectory } ' already exists." ) ;
7086 }
7187 }
7288 }
0 commit comments