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

Commit

Permalink
Remove global location lookup support using PATH in non Windows (#2644)
Browse files Browse the repository at this point in the history
  • Loading branch information
steveharter authored and gkhanna79 committed Jun 7, 2017
1 parent 90d3297 commit 40c5652
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 80 deletions.
51 changes: 2 additions & 49 deletions src/corehost/common/pal.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,57 +182,10 @@ bool is_executable(const pal::string_t& file_path)
return ((st.st_mode & S_IEXEC) != 0);
}

static
bool locate_dotnet_on_path(std::vector<pal::string_t>* dotnet_exes)
{
pal::string_t path;
if (!pal::getenv(_X("PATH"), &path))
{
return false;
}

pal::string_t tok;
pal::stringstream_t ss(path);
while (std::getline(ss, tok, PATH_SEPARATOR))
{
size_t start_pos = tok.find_first_not_of(_X(" \t"));
if (start_pos == pal::string_t::npos)
{
continue;
}

append_path(&tok, _X("dotnet"));
if (pal::realpath(&tok) && is_executable(tok))
{
dotnet_exes->push_back(tok);
}
tok.clear();
}

if (dotnet_exes->empty())
{
return false;
}

return true;
}

bool pal::get_global_dotnet_dirs(std::vector<pal::string_t>* recv)
{

std::vector<pal::string_t> dotnet_exes;
if (!locate_dotnet_on_path(&dotnet_exes))
{
return false;
}

for (pal::string_t path : dotnet_exes)
{
pal::string_t dir = get_directory(path);
recv->push_back(dir);
}

return true;
// No support for global directories in Unix.
return false;
}

pal::string_t trim_quotes(pal::string_t stringToCleanup)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ public void SharedFxLookup_Must_Roll_Forward_Before_Looking_Into_Another_Folder(
{
return;
}
else
{
// Currently no support for global locations on Linux; remaining test code below is preserved for now.
return;
}

var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
.Copy();
Expand Down Expand Up @@ -415,6 +420,11 @@ public void Roll_Forward_On_No_Candidate_Fx_Must_Look_Into_All_Lookup_Folders()
{
return;
}
else
{
// Currently no support for global locations on Linux; remaining test code below is preserved for now.
return;
}

var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
.Copy();
Expand Down Expand Up @@ -481,6 +491,11 @@ public void Roll_Forward_On_No_Candidate_Fx_May_Be_Enabled_Through_Runtimeconfig
{
return;
}
else
{
// Currently no support for global locations on Linux; remaining test code below is preserved for now.
return;
}

var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
.Copy();
Expand Down Expand Up @@ -529,7 +544,12 @@ public void Roll_Forward_On_No_Candidate_Fx_May_Be_Enabled_Through_Argument()
{
return;
}

else
{
// Currently no support for global locations on Linux; remaining test code below is preserved for now.
return;
}

var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
.Copy();

Expand Down Expand Up @@ -595,7 +615,12 @@ public void Ensure_On_NonWindows_Multiple_Global_Locations_Are_Probed()
{
return;
}

else
{
// Currently no support for global locations on Linux; remaining test code below is preserved for now.
return;
}

var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
.Copy();

Expand Down
30 changes: 3 additions & 27 deletions src/test/TestUtils/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,41 +238,17 @@ public Command WithUserProfile(string userprofile)
_process.StartInfo.Environment[userDir] = userprofile;
return this;
}
public Command SanitizeGlobalLocation()
{
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
{
var current_path = _process.StartInfo.Environment["PATH"];
var new_path = new System.Text.StringBuilder();
//Remove any global dotnet that has been set
foreach (var sub_path in current_path.Split(Path.PathSeparator))
{
var candidate = Path.Combine(sub_path, "dotnet");
if (!File.Exists(candidate))
{
new_path.Append(sub_path);
new_path.Append(Path.PathSeparator);
}
}
_process.StartInfo.Environment["PATH"] = new_path.ToString();
}
return this;
}

public Command WithGlobalLocation(string global)
{

if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
{
throw new NotImplementedException("Global location override needs work ");
throw new NotImplementedException("Global location override needs test improvements for Windows");
}
else
{
var current_path = _process.StartInfo.Environment["PATH"];
_process.StartInfo.Environment["PATH"] = current_path + Path.PathSeparator + global;
throw new NotSupportedException("Global location override not supported for Linux");
}


return this;
}

public Command EnvironmentVariable(string name, string value)
Expand Down
3 changes: 1 addition & 2 deletions src/test/TestUtils/DotNetCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public Command Exec(string command, params string[] args)
}

return Command.Create(Path.Combine(BinPath, $"dotnet{Constants.ExeSuffix}"), newArgs)
.EnvironmentVariable("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "1")
.SanitizeGlobalLocation();
.EnvironmentVariable("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "1");
}

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

0 comments on commit 40c5652

Please sign in to comment.