Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 40c5652

Browse files
stevehartergkhanna79
authored andcommitted
Remove global location lookup support using PATH in non Windows (#2644)
1 parent 90d3297 commit 40c5652

File tree

4 files changed

+33
-80
lines changed

4 files changed

+33
-80
lines changed

src/corehost/common/pal.unix.cpp

+2-49
Original file line numberDiff line numberDiff line change
@@ -182,57 +182,10 @@ bool is_executable(const pal::string_t& file_path)
182182
return ((st.st_mode & S_IEXEC) != 0);
183183
}
184184

185-
static
186-
bool locate_dotnet_on_path(std::vector<pal::string_t>* dotnet_exes)
187-
{
188-
pal::string_t path;
189-
if (!pal::getenv(_X("PATH"), &path))
190-
{
191-
return false;
192-
}
193-
194-
pal::string_t tok;
195-
pal::stringstream_t ss(path);
196-
while (std::getline(ss, tok, PATH_SEPARATOR))
197-
{
198-
size_t start_pos = tok.find_first_not_of(_X(" \t"));
199-
if (start_pos == pal::string_t::npos)
200-
{
201-
continue;
202-
}
203-
204-
append_path(&tok, _X("dotnet"));
205-
if (pal::realpath(&tok) && is_executable(tok))
206-
{
207-
dotnet_exes->push_back(tok);
208-
}
209-
tok.clear();
210-
}
211-
212-
if (dotnet_exes->empty())
213-
{
214-
return false;
215-
}
216-
217-
return true;
218-
}
219-
220185
bool pal::get_global_dotnet_dirs(std::vector<pal::string_t>* recv)
221186
{
222-
223-
std::vector<pal::string_t> dotnet_exes;
224-
if (!locate_dotnet_on_path(&dotnet_exes))
225-
{
226-
return false;
227-
}
228-
229-
for (pal::string_t path : dotnet_exes)
230-
{
231-
pal::string_t dir = get_directory(path);
232-
recv->push_back(dir);
233-
}
234-
235-
return true;
187+
// No support for global directories in Unix.
188+
return false;
236189
}
237190

238191
pal::string_t trim_quotes(pal::string_t stringToCleanup)

src/test/HostActivationTests/GivenThatICareAboutMultilevelSharedFxLookup.cs

+27-2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ public void SharedFxLookup_Must_Roll_Forward_Before_Looking_Into_Another_Folder(
169169
{
170170
return;
171171
}
172+
else
173+
{
174+
// Currently no support for global locations on Linux; remaining test code below is preserved for now.
175+
return;
176+
}
172177

173178
var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
174179
.Copy();
@@ -415,6 +420,11 @@ public void Roll_Forward_On_No_Candidate_Fx_Must_Look_Into_All_Lookup_Folders()
415420
{
416421
return;
417422
}
423+
else
424+
{
425+
// Currently no support for global locations on Linux; remaining test code below is preserved for now.
426+
return;
427+
}
418428

419429
var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
420430
.Copy();
@@ -481,6 +491,11 @@ public void Roll_Forward_On_No_Candidate_Fx_May_Be_Enabled_Through_Runtimeconfig
481491
{
482492
return;
483493
}
494+
else
495+
{
496+
// Currently no support for global locations on Linux; remaining test code below is preserved for now.
497+
return;
498+
}
484499

485500
var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
486501
.Copy();
@@ -529,7 +544,12 @@ public void Roll_Forward_On_No_Candidate_Fx_May_Be_Enabled_Through_Argument()
529544
{
530545
return;
531546
}
532-
547+
else
548+
{
549+
// Currently no support for global locations on Linux; remaining test code below is preserved for now.
550+
return;
551+
}
552+
533553
var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
534554
.Copy();
535555

@@ -595,7 +615,12 @@ public void Ensure_On_NonWindows_Multiple_Global_Locations_Are_Probed()
595615
{
596616
return;
597617
}
598-
618+
else
619+
{
620+
// Currently no support for global locations on Linux; remaining test code below is preserved for now.
621+
return;
622+
}
623+
599624
var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
600625
.Copy();
601626

src/test/TestUtils/Command.cs

+3-27
Original file line numberDiff line numberDiff line change
@@ -238,41 +238,17 @@ public Command WithUserProfile(string userprofile)
238238
_process.StartInfo.Environment[userDir] = userprofile;
239239
return this;
240240
}
241-
public Command SanitizeGlobalLocation()
242-
{
243-
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
244-
{
245-
var current_path = _process.StartInfo.Environment["PATH"];
246-
var new_path = new System.Text.StringBuilder();
247-
//Remove any global dotnet that has been set
248-
foreach (var sub_path in current_path.Split(Path.PathSeparator))
249-
{
250-
var candidate = Path.Combine(sub_path, "dotnet");
251-
if (!File.Exists(candidate))
252-
{
253-
new_path.Append(sub_path);
254-
new_path.Append(Path.PathSeparator);
255-
}
256-
}
257-
_process.StartInfo.Environment["PATH"] = new_path.ToString();
258-
}
259-
return this;
260-
}
241+
261242
public Command WithGlobalLocation(string global)
262243
{
263-
264244
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
265245
{
266-
throw new NotImplementedException("Global location override needs work ");
246+
throw new NotImplementedException("Global location override needs test improvements for Windows");
267247
}
268248
else
269249
{
270-
var current_path = _process.StartInfo.Environment["PATH"];
271-
_process.StartInfo.Environment["PATH"] = current_path + Path.PathSeparator + global;
250+
throw new NotSupportedException("Global location override not supported for Linux");
272251
}
273-
274-
275-
return this;
276252
}
277253

278254
public Command EnvironmentVariable(string name, string value)

src/test/TestUtils/DotNetCli.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ public Command Exec(string command, params string[] args)
3131
}
3232

3333
return Command.Create(Path.Combine(BinPath, $"dotnet{Constants.ExeSuffix}"), newArgs)
34-
.EnvironmentVariable("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "1")
35-
.SanitizeGlobalLocation();
34+
.EnvironmentVariable("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "1");
3635
}
3736

3837
public Command Restore(params string[] args) => Exec("restore", args);

0 commit comments

Comments
 (0)