Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Src/DLR
Submodule DLR updated 112 files
17 changes: 7 additions & 10 deletions Src/IronPython/Runtime/ClrModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ public static void CompileModules(CodeContext/*!*/ context, string/*!*/ assembly
List<SavableScriptCode> code = new List<SavableScriptCode>();
foreach (string filename in filenames) {
if (!pc.DomainManager.Platform.FileExists(filename)) {
throw PythonOps.IOError("Couldn't find file for compilation: {0}", filename);
throw PythonOps.IOError($"Couldn't find file for compilation: {filename}");
}

ScriptCode sc;
Expand All @@ -868,11 +868,10 @@ public static void CompileModules(CodeContext/*!*/ context, string/*!*/ assembly
} else {
modName = Path.GetFileNameWithoutExtension(filename);
}

// see if we have a parent package, if so incorporate it into
// our name
string parentPackage;
if (packageMap.TryGetValue(dname, out parentPackage)) {
if (packageMap.TryGetValue(dname, out string parentPackage)) {
modName = parentPackage + "." + modName;
}

Expand All @@ -893,20 +892,18 @@ public static void CompileModules(CodeContext/*!*/ context, string/*!*/ assembly
code.Add((SavableScriptCode)sc);
}

object mainModule;
if (kwArgs != null && kwArgs.TryGetValue("mainModule", out mainModule)) {
string strModule = mainModule as string;
if (strModule != null) {
if (kwArgs != null && kwArgs.TryGetValue("mainModule", out object mainModule)) {
if (mainModule is string strModule) {
if (!pc.DomainManager.Platform.FileExists(strModule)) {
throw PythonOps.IOError("Couldn't find main file for compilation: {0}", strModule);
}

SourceUnit su = pc.CreateFileUnit(strModule, pc.DefaultEncoding, SourceCodeKind.File);
code.Add((SavableScriptCode)context.LanguageContext.GetScriptCode(su, "__main__", ModuleOptions.Initialize, Compiler.CompilationMode.ToDisk));
}
}

SavableScriptCode.SaveToAssembly(assemblyName, code.ToArray());
SavableScriptCode.SaveToAssembly(assemblyName, kwArgs, code.ToArray());
}
#endif

Expand Down
104 changes: 82 additions & 22 deletions Src/IronPythonCompiler/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,29 @@ public Config() {
Embed = false;
Files = new List<string>();
Platform = IKVM.Reflection.PortableExecutableKinds.ILOnly;
Machine = IKVM.Reflection.ImageFileMachine.I386;
Machine = IKVM.Reflection.ImageFileMachine.AMD64;
Standalone = false;
Target = PEFileKinds.Dll;
UseMta = false;
MainName = Main = string.Empty;
Output = string.Empty;
OutputPath = string.Empty;
Win32Icon = string.Empty;
Version = string.Empty;
FileVersion = string.Empty;
ProductName = string.Empty;
Copyright = string.Empty;
ProductVersion = string.Empty;
ErrorMessageFormat = "Error occurred: {0}";
PythonOptions = new Dictionary<string, object>();
DLLs = new List<string>();
}

public string ErrorMessageFormat {
get;
private set;
}

public string Version {
public string FileVersion {
get;
private set;
}
Expand All @@ -44,11 +49,31 @@ public string Win32Icon {
private set;
}

public string ProductName {
get;
private set;
}

public string Copyright {
get;
private set;
}

public string ProductVersion {
get;
private set;
}

public string Output {
get;
private set;
}

public string OutputPath {
get;
private set;
}

public string Main {
get;
private set;
Expand Down Expand Up @@ -79,6 +104,11 @@ public List<string> Files {
private set;
}

public List<string> DLLs {
get;
private set;
}

public IDictionary<string, object> PythonOptions {
get;
private set;
Expand Down Expand Up @@ -142,13 +172,19 @@ public void ParseArgs(IEnumerable<string> args, List<string> respFiles = null) {
break;
default:
Platform = IKVM.Reflection.PortableExecutableKinds.ILOnly;
Machine = IKVM.Reflection.ImageFileMachine.I386;
Machine = IKVM.Reflection.ImageFileMachine.AMD64;
break;
}
} else if (arg.StartsWith("/win32icon:")) {
Win32Icon = arg.Substring(11).Trim('"');
} else if (arg.StartsWith("/version:")) {
Version = arg.Substring(9).Trim('"');
} else if (arg.StartsWith("/fileversion:")) {
FileVersion = arg.Substring(13).Trim('"');
} else if (arg.StartsWith("/productversion:")) {
ProductVersion = arg.Substring(16).Trim('"');
} else if(arg.StartsWith("/productname:")) {
ProductName = arg.Substring(13).Trim('"');
} else if(arg.StartsWith("/copyright:")) {
Copyright = arg.Substring(11).Trim('"');
} else if (arg.StartsWith("/errfmt:")) {
ErrorMessageFormat = arg.Substring(8);
} else if (arg.StartsWith("/embed")) {
Expand All @@ -157,6 +193,14 @@ public void ParseArgs(IEnumerable<string> args, List<string> respFiles = null) {
Standalone = true;
} else if (arg.StartsWith("/mta")) {
UseMta = true;
} else if(arg.StartsWith("/recurse:")) {
string pattern = arg.Substring(9);
if(string.IsNullOrWhiteSpace(pattern)) {
ConsoleOps.Error(true, "Missing pattern for /recurse option");
}
foreach(var f in Directory.EnumerateFiles(Environment.CurrentDirectory, pattern)) {
Files.Add(Path.GetFullPath(f));
}
} else if (Array.IndexOf(helpStrings, arg) >= 0) {
ConsoleOps.Usage(true);
} else if(arg.StartsWith("/py:")) {
Expand All @@ -177,7 +221,7 @@ public void ParseArgs(IEnumerable<string> args, List<string> respFiles = null) {
case "-X:GCStress":
int gcStress;
if (!int.TryParse(pyargs[1], out gcStress) || (gcStress < 0 || gcStress > GC.MaxGeneration)) {
ConsoleOps.Error(true, "The argument for the {0} option must be between 0 and {1}.", pyargs[1], GC.MaxGeneration);
ConsoleOps.Error(true, $"The argument for the {pyargs[1]} option must be between 0 and {GC.MaxGeneration}.");
}

PythonOptions["GCStress"] = gcStress;
Expand All @@ -187,7 +231,7 @@ public void ParseArgs(IEnumerable<string> args, List<string> respFiles = null) {
// we need about 6 frames for starting up, so 10 is a nice round number.
int limit;
if (!int.TryParse(pyargs[1], out limit) || limit < 10) {
ConsoleOps.Error(true, "The argument for the {0} option must be an integer >= 10.", pyargs[1]);
ConsoleOps.Error(true, $"The argument for the {pyargs[1]} option must be an integer >= 10.");
}

PythonOptions["RecursionLimit"] = limit;
Expand Down Expand Up @@ -216,20 +260,28 @@ public void ParseArgs(IEnumerable<string> args, List<string> respFiles = null) {
respFiles.Add(respFile);
ParseArgs(File.ReadAllLines(respFile), respFiles);
} else {
ConsoleOps.Warning("Already parsed response file '{0}'", arg.Substring(1));
ConsoleOps.Warning($"Already parsed response file '{arg.Substring(1)}'");
}
} else {
Files.Add(arg);
if (arg.ToLower().EndsWith(".dll")) {
DLLs.Add(arg);
} else {
Files.Add(arg);
}
}
}
}
}

public bool Validate() {
if (Files.Count == 1 && string.IsNullOrEmpty(MainName)) {
if (Files.Count == 1 && string.IsNullOrWhiteSpace(MainName)) {
MainName = Files[0];
}

if(Files.Count == 0 && !string.IsNullOrWhiteSpace(MainName)) {
Files.Add(MainName);
}

if (Files == null || Files.Count == 0 || string.IsNullOrEmpty(MainName)) {
ConsoleOps.Error("No files or main defined");
return false;
Expand All @@ -240,17 +292,24 @@ public bool Validate() {
return false;
}

if (string.IsNullOrEmpty(Output) && !string.IsNullOrEmpty(MainName)) {
if(DLLs.Count > 0 && !Standalone) {
ConsoleOps.Error("DLLs can only be used in standalone mode");
return false;
}

if (string.IsNullOrWhiteSpace(Output) && !string.IsNullOrWhiteSpace(MainName)) {
Output = Path.GetFileNameWithoutExtension(MainName);
} else if (string.IsNullOrEmpty(Output) && Files != null && Files.Count > 0) {
OutputPath = Path.GetDirectoryName(MainName);
} else if (string.IsNullOrWhiteSpace(Output) && Files != null && Files.Count > 0) {
Output = Path.GetFileNameWithoutExtension(Files[0]);
OutputPath = Path.GetDirectoryName(Files[0]);
}

if (!string.IsNullOrEmpty(Win32Icon) && Target == PEFileKinds.Dll) {
if (!string.IsNullOrWhiteSpace(Win32Icon) && Target == PEFileKinds.Dll) {
ConsoleOps.Error("DLLs may not have a win32icon");
return false;
} else if (!string.IsNullOrEmpty(Win32Icon) && !File.Exists(Win32Icon)) {
ConsoleOps.Error("win32icon '{0}' does not exist", Win32Icon);
} else if (!string.IsNullOrWhiteSpace(Win32Icon) && !File.Exists(Win32Icon)) {
ConsoleOps.Error($"win32icon '{Win32Icon}' does not exist");
return false;
}

Expand All @@ -260,12 +319,13 @@ public bool Validate() {
public override string ToString() {
StringBuilder res = new StringBuilder("Input Files:\n");
foreach (var file in Files) {
res.AppendFormat("\t{0}\n", file);
res.AppendLine($"\t{file}");
}

res.AppendFormat("Output:\n\t{0}\n", Output);
res.AppendFormat("Target:\n\t{0}\n", Target);
res.AppendFormat("Platform:\n\t{0}\n", Machine);
res.AppendLine($"Output:\n\t{Output}");
res.AppendLine($"OutputPath:\n\t{OutputPath}");
res.AppendLine($"Target:\n\t{Target}");
res.AppendLine($"Platform:\n\t{Machine}");
if (Target == PEFileKinds.WindowApplication) {
res.AppendLine("Threading:");
if (UseMta) {
Expand All @@ -276,9 +336,9 @@ public override string ToString() {
}

if (PythonOptions.Count > 0) {
res.AppendFormat("\nIronPython Context Options:\n");
res.AppendLine("\nIronPython Context Options:");
foreach(var option in PythonOptions) {
res.AppendFormat("\t{0} = {1}\n", option.Key, option.Value);
res.AppendLine($"\t{option.Key} = {option.Value}");
}
}

Expand Down
Loading