Skip to content

Commit

Permalink
[2.0] Updates (#574)
Browse files Browse the repository at this point in the history
* [PSym] Update importing foreign functions

Updates how files containing foreign functions are imported with the new P 2.0 paths

* [PSym] Update examples with foreign functions

* [PCompiler] Completely eliminate nuget dependency on PCSharpRuntime/PCheckerCore for p check command

Remove all runtime dependencies on PCSharpRuntime or PCheckerCore nuget packages. Instead, import from local .dll files already installed when installing P
  • Loading branch information
aman-goel committed Apr 7, 2023
1 parent d982e5b commit 4d13b53
Show file tree
Hide file tree
Showing 29 changed files with 138 additions and 55 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,3 @@ jobs:
- name: Push generated package to Nuget
run: |
dotnet nuget push ./Bld/Drops/Release/Binaries/P.${VERSION}.nupkg -k ${{ secrets.NUGET_SECRET }} -s https://api.nuget.org/v3/index.json --no-symbols --skip-duplicate
dotnet nuget push ./Bld/Drops/Release/Binaries/PCSharpRuntime.${VERSION}.nupkg -k ${{ secrets.NUGET_SECRET }} -s https://api.nuget.org/v3/index.json --no-symbols --skip-duplicate
dotnet nuget push ./Bld/Drops/Release/Binaries/PCheckerCore.${VERSION}.nupkg -k ${{ secrets.NUGET_SECRET }} -s https://api.nuget.org/v3/index.json --no-symbols --skip-duplicate
10 changes: 3 additions & 7 deletions Src/PCompiler/CompilerCore/Backend/CSharp/CSharpCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Plang.Compiler.Backend.ASTExt;
using Plang.Compiler.TypeChecker;
using Plang.Compiler.TypeChecker.AST;
Expand Down Expand Up @@ -48,13 +49,8 @@ public void Compile(ICompilerConfiguration job)
}
csprojTemplate = csprojTemplate.Replace("-foreign-include-", foreignInclude);

string versionString = "2.*";
var version = typeof(CSharpCodeGenerator).Assembly.GetName().Version;
if (version is not null && version.Major > 1)
{
versionString = version.ToString();
}
csprojTemplate = csprojTemplate.Replace("-version-", versionString);
string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
csprojTemplate = csprojTemplate.Replace("-assembly-path-", assemblyPath);

File.WriteAllText(csprojPath, csprojTemplate);
}
Expand Down
7 changes: 6 additions & 1 deletion Src/PCompiler/CompilerCore/Backend/CSharp/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ internal class Constants
</PropertyGroup>
-foreign-include-
<ItemGroup>
<PackageReference Include=""PCSharpRuntime"" Version=""-version-""/>
<Reference Include=""PCSharpRuntime"">
<HintPath>-assembly-path-/PCSharpRuntime.dll</HintPath>
</Reference>
<Reference Include=""PCheckerCore"">
<HintPath>-assembly-path-/PCheckerCore.dll</HintPath>
</Reference>
</ItemGroup>
</Project>";

Expand Down
29 changes: 26 additions & 3 deletions Src/PCompiler/CompilerCore/Backend/Symbolic/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ internal class Constants
<modelVersion>4.0.0</modelVersion>
<groupId>psym.model</groupId>
<artifactId>projectName</artifactId>
<artifactId>-project-name-</artifactId>
<version>1.0</version>
<build>
<sourceDirectory>.</sourceDirectory>
<plugins>
-foreign-include-
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
Expand All @@ -42,7 +43,7 @@ internal class Constants
</execution>
</executions>
<configuration>
<finalName>projectName</finalName>
<finalName>-project-name-</finalName>
<archive>
<manifest>
<addClasspath>true</addClasspath>
Expand All @@ -61,7 +62,7 @@ internal class Constants
<dependency>
<groupId>io.github.p-org</groupId>
<artifactId>psym</artifactId>
<version>[0.5.6,)</version>
<version>[1.0.0,)</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
Expand All @@ -80,6 +81,28 @@ internal class Constants
<java.version>16</java.version>
</properties>
</project>
";

internal static readonly string pomForeignTemplate =
@"
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
-foreign-source-include- </sources>
</configuration>
</execution>
</executions>
</plugin>
";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,33 @@ public void Compile(ICompilerConfiguration job)
// if the file does not exist then create the file
if (!File.Exists(pomPath))
{
var pomTemplate = Constants.pomTemplate.Replace("projectName",job.ProjectName);
var pomTemplate = Constants.pomTemplate;
pomTemplate = pomTemplate.Replace("-project-name-",job.ProjectName);

string foreignInclude = "";
var foreignFiles = job.InputForeignFiles.Where(x => x.EndsWith(".java"));
if (foreignFiles.Any())
{
foreignInclude = Constants.pomForeignTemplate;
string foreignSourceInclude = "";
SortedSet<string> foreignFolders = new SortedSet<string>();

foreach (var fileName in foreignFiles)
{
var folderName = Path.GetDirectoryName(fileName);
if (folderName is not null)
{
foreignFolders.Add(folderName);
}
}
foreach (var folderName in foreignFolders)
{
foreignSourceInclude += $" <source>{folderName}</source>\n";
}
foreignInclude = foreignInclude.Replace("-foreign-source-include-", foreignSourceInclude);
}
pomTemplate = pomTemplate.Replace("-foreign-include-", foreignInclude);

File.WriteAllText(pomPath, pomTemplate);
}

Expand Down
1 change: 1 addition & 0 deletions Src/PCompiler/PCommandLine/PCommandLine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\PChecker\CheckerCore\CheckerCore.csproj" />
<ProjectReference Include="..\..\PRuntimes\PCSharpRuntime\CSharpRuntime.csproj" />
<ProjectReference Include="..\CompilerCore\CompilerCore.csproj" />
<None Include="../../../Icon/icon.png" Pack="true" PackagePath="" />
<None Include="../../../README.md" Pack="true" PackagePath="" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project>
<ProjectName>pingPongForeign1</ProjectName>
<InputFiles>
<PFile>./</PFile>
<PFile>./PSrc/</PFile>
<PFile>./PForeign/</PFile>
</InputFiles>
<Target>Symbolic</Target>
</Project>
<OutputDir>./PGenerated/</OutputDir>
</Project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package psym.model;

import lombok.Getter;
import psym.runtime.values.*;

public class CustomInt {
@Getter
private int value;

CustomInt(int val) {
this.value = (int) val;
}

CustomInt(Object val) {
if (val instanceof CustomInt)
this.value = ((CustomInt) val).getValue();
else
this.value = (int) val;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project>
<ProjectName>pingPongForeign2</ProjectName>
<InputFiles>
<PFile>./</PFile>
<PFile>./PSrc/</PFile>
<PFile>./PForeign/</PFile>
</InputFiles>
<Target>Symbolic</Target>
</Project>
<OutputDir>./PGenerated/</OutputDir>
</Project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package psym.model;

import lombok.Getter;
import psym.runtime.values.*;

public class CustomInt {
@Getter
private int value;

CustomInt(int val) {
this.value = (int) val;
}

CustomInt(Object val) {
if (val instanceof CustomInt)
this.value = ((CustomInt) val).getValue();
else
this.value = (int) val;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<Project>
<ProjectName>pingPongForeign3</ProjectName>
<InputFiles>
<PFile>./</PFile>
<PFile>./PSrc/</PFile>
<PFile>./PTst/</PFile>
<PFile>./PForeign/</PFile>
</InputFiles>
<Target>Symbolic</Target>
<OutputDir>./PGenerated/</OutputDir>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project>
<ProjectName>pingPongForeign1</ProjectName>
<InputFiles>
<PFile>./</PFile>
<PFile>./PSrc/</PFile>
<PFile>./PForeign/</PFile>
</InputFiles>
<Target>Symbolic</Target>
<OutputDir>./PGenerated/</OutputDir>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public PBool(boolean val)

public PBool(Object val)
{
value = (boolean) val;
if (val instanceof PBool)
value = ((PBool) val).value;
else
value = (boolean) val;
}

public PBool(PBool val)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public PFloat(double val)

public PFloat(Object val)
{
value = (double) val;
if (val instanceof PFloat)
value = ((PFloat) val).value;
else
value = (double) val;
}

public PFloat(PFloat val)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ public PInt(int val)

public PInt(Object val)
{
value = (int) val;
if (val instanceof PInt)
value = ((PInt) val).value;
else
value = (int) val;
}

public PInt(PInt val)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public PMachineValue(Machine val)

public PMachineValue(Object val)
{
value = (Machine) val;
if (val instanceof PMachineValue)
value = ((PMachineValue) val).value;
else
value = (Machine) val;
}

public PMachineValue(PMachineValue val)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ public PString(String val)

public PString(Object val)
{
value = (String) val;
if (val instanceof PString)
value = ((PString) val).value;
else
value = (String) val;
}

public PString(PString val)
Expand Down

0 comments on commit 4d13b53

Please sign in to comment.