Skip to content

Commit

Permalink
dotnet: rework CLR_KEYFILE management
Browse files Browse the repository at this point in the history
- Move tools/netstandard to tools/dotnet
- Create Strong Name Keyfile using dotnet.
- Protect against space in DOTNET_BIN
  • Loading branch information
Mizux committed Jul 13, 2018
1 parent 13b8633 commit 6cd212b
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 60 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ cache/
**/.vscode/*
.DS_Store

tools/netstandard/CreateSigningKey/bin
tools/netstandard/CreateSigningKey/obj

**/.vs/*
**/dotnet-test/*

Expand All @@ -100,4 +97,8 @@ examples/dotnet/**/obj
ortools/dotnet/**/bin
ortools/dotnet/**/obj
ortools/dotnet/**/packages

tools/dotnet/CreateSigningKey/bin
tools/dotnet/CreateSigningKey/obj

*.userprefs
12 changes: 2 additions & 10 deletions makefiles/Makefile.csharp.mk
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ endif
netstandardortools: ortoolslibs $(BIN_DIR)/$(NETSTANDARD_ORTOOLS_DLL_NAME)$D $(BIN_DIR)/$(CLR_PROTOBUF_DLL_NAME)$D

$(NETSTANDARD_OBJ_DIR)/AssemblyInfo.cs: \
netstandard_keyfile \
$(CLR_KEYFILE) \
$(GEN_DIR)/dotnet/ortools/properties/CommonAssemblyInfo.cs
$(COPY) tools$Scsharp$SAssemblyInfo.cs $(NETSTANDARD_OBJ_DIR)$SAssemblyInfo.cs
ifdef CLR_KEYFILE
Expand Down Expand Up @@ -337,16 +337,8 @@ $(GEN_DIR)/dotnet/ortools/sat/SatParameters.pb.cs: $(SRC_DIR)/ortools/sat/sat_pa
$(PROTOC) --proto_path=$(SRC_DIR) --csharp_out=$(GEN_PATH)$Sdotnet$Sortools$Ssat --csharp_opt=file_extension=.pb.cs $(SRC_DIR)$Sortools$Ssat$Ssat_parameters.proto

# Main DLL

$(CLR_KEYFILE): | $(BIN_DIR)
ifdef CLR_KEYFILE
sn -k $(CLR_KEYFILE)
endif

netstandard_keyfile:
ifdef CLR_KEYFILE
$(PATH_TO_DOTNET_EXE) run --project tools$Snetstandard$SCreateSigningKey$SCreateSigningKey.csproj $(CLR_KEYFILE)
endif
$(PATH_TO_DOTNET_EXE) run --project tools$Sdotnet$SCreateSigningKey$SCreateSigningKey.csproj $(CLR_KEYFILE)

$(BIN_DIR)/$(CLR_ORTOOLS_DLL_NAME)$D: \
$(GEN_DIR)/dotnet/ortools/properties/AssemblyInfo.cs \
Expand Down
33 changes: 18 additions & 15 deletions makefiles/Makefile.dotnet.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ CLR_ORTOOLS_TEST_DLL_NAME := Google.$(ORTOOLS_TEST_DLL_NAME)
CLR_ORTOOLS_FSHARP_DLL_NAME := Google.$(ORTOOLS_FSHARP_DLL_NAME)
CLR_ORTOOLS_FSHARP_TEST_DLL_NAME := Google.$(ORTOOLS_FSHARP_TEST_DLL_NAME)
CLR_ORTOOLS_IMPORT_DLL_NAME := $(CLR_ORTOOLS_DLL_NAME).import
CLR_KEYFILE = $(BIN_DIR)/or-tools.snk
CLR_KEYFILE_PATH = $(subst /,$S,$(CLR_KEYFILE))

# relative to the project root folder
TEMP_DOTNET_TEST_DIR=temp_dotnet_test
Expand Down Expand Up @@ -59,8 +61,8 @@ $(GEN_DIR)/ortools/properties/GitVersion$(OR_TOOLS_VERSION).txt: \
@echo $(OR_TOOLS_VERSION) > $(GEN_PATH)$Sortools$Sproperties$SGitVersion$(OR_TOOLS_VERSION).txt

# Auto-generated code
$(BIN_DIR)/$(CLR_PROTOBUF_DLL_NAME)$D: tools/$(CLR_PROTOBUF_DLL_NAME)$D | $(BIN_DIR)
$(COPY) tools$S$(CLR_PROTOBUF_DLL_NAME)$D $(BIN_DIR)
$(BIN_DIR)/$(CLR_PROTOBUF_DLL_NAME)$D: tools/dotnet/$(CLR_PROTOBUF_DLL_NAME)$D | $(BIN_DIR)
$(COPY) tools$Sdotnet$S$(CLR_PROTOBUF_DLL_NAME)$D $(BIN_DIR)

$(GEN_DIR)/ortools/linear_solver/linear_solver_csharp_wrap.cc: \
$(SRC_DIR)/ortools/linear_solver/csharp/linear_solver.i \
Expand Down Expand Up @@ -247,9 +249,7 @@ $(GEN_DIR)/ortools/sat/SatParameters.pb.cs: \
$(SRC_DIR)$Sortools$Ssat$Ssat_parameters.proto

$(CLR_KEYFILE): | $(BIN_DIR)
ifdef CLR_KEYFILE
sn -k $(CLR_KEYFILE)
endif
"$(DOTNET_BIN)" run --project tools$Sdotnet$SCreateSigningKey$SCreateSigningKey.csproj $S$(CLR_KEYFILE_PATH)

# Main DLL
$(BIN_DIR)/$(CLR_ORTOOLS_DLL_NAME)$D: \
Expand Down Expand Up @@ -316,6 +316,18 @@ endif

.PHONY: clean_dotnet # Clean files
clean_dotnet:
-$(DELREC) tools$Sdotnet$SCreateSigningKey$Sbin
-$(DELREC) tools$Sdotnet$SCreateSigningKey$Sobj
-$(DEL) $(CLR_KEYFILE_PATH)
-$(DELREC) ortools$Sdotnet$S$(ORTOOLS_DLL_NAME)$Sbin
-$(DELREC) ortools$Sdotnet$S$(ORTOOLS_DLL_NAME)$Sobj
-$(DELREC) ortools$Sdotnet$S$(ORTOOLS_TEST_DLL_NAME)$Sbin
-$(DELREC) ortools$Sdotnet$S$(ORTOOLS_TEST_DLL_NAME)$Sobj
-$(DELREC) ortools$Sdotnet$S$(ORTOOLS_FSHARP_DLL_NAME)$Sbin
-$(DELREC) ortools$Sdotnet$S$(ORTOOLS_FSHARP_DLL_NAME)$Sobj
-$(DELREC) ortools$Sdotnet$S$(ORTOOLS_FSHARP_TEST_DLL_NAME)$Sbin
-$(DELREC) ortools$Sdotnet$S$(ORTOOLS_FSHARP_TEST_DLL_NAME)$Sobj
-$(DELREC) ortools$Sdotnet$Spackages
-$(DEL) $(GEN_PATH)$Sortools$Salgorithms$S*.cs
-$(DEL) $(GEN_PATH)$Sortools$Salgorithms$S*csharp_wrap*
-$(DEL) $(GEN_PATH)$Sortools$Sgraph$S*.cs
Expand All @@ -326,21 +338,11 @@ clean_dotnet:
-$(DEL) $(GEN_PATH)$Sortools$Slinear_solver$S*csharp_wrap*
-$(DEL) $(GEN_PATH)$Sortools$Ssat$S*.cs
-$(DEL) $(GEN_PATH)$Sortools$Ssat$S*csharp_wrap*
-$(DELREC) ortools$Sdotnet$S$(ORTOOLS_DLL_NAME)$Sbin
-$(DELREC) ortools$Sdotnet$S$(ORTOOLS_DLL_NAME)$Sobj
-$(DELREC) ortools$Sdotnet$S$(ORTOOLS_TEST_DLL_NAME)$Sbin
-$(DELREC) ortools$Sdotnet$S$(ORTOOLS_TEST_DLL_NAME)$Sobj
-$(DELREC) ortools$Sdotnet$S$(ORTOOLS_FSHARP_DLL_NAME)$Sbin
-$(DELREC) ortools$Sdotnet$S$(ORTOOLS_FSHARP_DLL_NAME)$Sobj
-$(DELREC) ortools$Sdotnet$S$(ORTOOLS_FSHARP_TEST_DLL_NAME)$Sbin
-$(DELREC) ortools$Sdotnet$S$(ORTOOLS_FSHARP_TEST_DLL_NAME)$Sobj
-$(DELREC) ortools$Sdotnet$Spackage
-$(DEL) $(OBJ_DIR)$Sswig$S*_csharp_wrap.$O
-$(DEL) $(BIN_DIR)$S$(CLR_ORTOOLS_IMPORT_DLL_NAME).*
-$(DEL) $(BIN_DIR)$S$(CLR_PROTOBUF_DLL_NAME).*
-$(DEL) $(BIN_DIR)$S$(CLR_ORTOOLS_DLL_NAME).*
-$(DEL) $(BIN_DIR)$S$(CLR_ORTOOLS_FSHARP_DLL_NAME).*
-$(DEL) $(CLR_KEYFILE)
-$(DELREC) $(TEMP_DOTNET_DIR)
-$(DELREC) $(TEMP_DOTNET_TEST_DIR)

Expand Down Expand Up @@ -402,6 +404,7 @@ detect_dotnet:
@echo Relevant info for the dotnet build:
@echo PROTOC = $(PROTOC)
@echo DOTNET_BIN = $(DOTNET_BIN)
@echo CLR_KEYFILE = $(CLR_KEYFILE)
@echo NUGET_BIN = $(NUGET_BIN)
@echo SWIG_PYTHON_LIB_SUFFIX = $(SWIG_PYTHON_LIB_SUFFIX)
@echo CLR_PROTOBUF_DLL_NAME = $(CLR_PROTOBUF_DLL_NAME)
Expand Down
1 change: 0 additions & 1 deletion makefiles/Makefile.third_party.unix.mk
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,6 @@ Makefile.local: makefiles/Makefile.third_party.unix.mk
@echo UNIX_PYTHON_VER = $(DETECTED_PYTHON_VERSION)>> Makefile.local
@echo PATH_TO_CSHARP_COMPILER = $(DETECTED_MCS_BINARY)>> Makefile.local
@echo PATH_TO_DOTNET_COMPILER = $(DETECTED_DOTNET_BINARY)>> Makefile.local
@echo CLR_KEYFILE = bin/or-tools.snk>> Makefile.local
@echo >> Makefile.local
@echo "## OPTIONAL DEPENDENCIES ##" >> Makefile.local
@echo "# Define UNIX_CPLEX_DIR to use CPLEX" >> Makefile.local
Expand Down
1 change: 0 additions & 1 deletion makefiles/Makefile.third_party.win.mk
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ Makefile.local: makefiles/Makefile.third_party.$(SYSTEM).mk
@echo # i.e.: path\\scip-4.0.0 >> Makefile.local
@echo # See instructions here: >> Makefile.local
@echo # http://or-tools.blogspot.com/2017/03/changing-way-we-link-with-scip.html >> Makefile.local
@echo CLR_KEYFILE = bin\\or-tools.snk >> Makefile.local
@echo # Define WINDOWS_GUROBI_DIR and GUROBI_LIB_VERSION to use Gurobi >> Makefile.local
@echo # >> Makefile.local
@echo # Define WINDOWS_ZLIB_DIR, WINDOWS_ZLIB_NAME, WINDOWS_GFLAGS_DIR, >> Makefile.local
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

</Project>
24 changes: 24 additions & 0 deletions tools/dotnet/CreateSigningKey/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.IO;
using System.Security.Cryptography;

namespace CreateSigningKey {
class Program {
static void Main(string[] args) {
if (args == null || args.Length == 0) {
Console.WriteLine("Key filename not specified.");
return;
}
string path = Directory.GetCurrentDirectory() + args[0];
Console.WriteLine("Key filename:" + path);
if (Console.Out!=null) Console.Out.Flush();
File.WriteAllBytes(path, GenerateStrongNameKeyPair());
}

public static byte[] GenerateStrongNameKeyPair() {
using (var provider = new RSACryptoServiceProvider(1024)) {
return provider.ExportCspBlob(!provider.PublicOnly);
}
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 0 additions & 28 deletions tools/netstandard/CreateSigningKey/Program.cs

This file was deleted.

0 comments on commit 6cd212b

Please sign in to comment.