Would somebody give me hints (or the entire solution!) to this question:
In a Clojurescript project, how can I automatically hardcode the compilation date/time in a symbol for it to be displayed when the app is used?
Thanks.
There are multiple solutions:
Use lein-git-version plugin
Add lein-git-version plugin to your project. It will generate a namespace containing vars with information like project version, git revision and timestamp. You can refer to them from other namespaces.
Use a macro
You can define a macro in a .clj or .cljc file:
(defmacro generate-build-timestamp []
(System/currentTimeMillis))
And use it in your ClojureScript code:
(def build-timestamp (generate-build-timestamp))
As the macro code will be executed during compilation, the value produced by the macro will be filled in the the compiled JavaScript code.
Related
I am hacking around a problem we've created for ourselves. What I would like to do is log a warning in our TFS builds for any code that is instantiating a specific class. I don't want a run time warning (I've got one in place already), I want a build time warning that ProjectX is using BadClass.cs. The idea being it will give us an additional place to see things that need to be fixed once our hack is no longer needed.
So something like this:
public class BadClass
{}
public class OkClass
{}
public class MyBadService
{
var a = new BadClass(); <-- Logs a warning to the build output
}
public class MyOkService
{
var a = new OkClass(); <-- Does not log a warning
}
Edit:
I do not like the idea of using Obsolete; its a misnomer. We've already got code with Obsolete attributes and this would get lost in the noise. I don't want a generic warning that I can't control the message for. I want bright neon signs with klaxons firing and a thousand exclamation points in the message. Basically everything I can do short of failing the build. I'm using the #warning precompiler directive right now and its mostly doing what I want but it requires a human to remember to add the warning. I'm looking for something more automagic. I've seen third party libraries do stuff like this so I know its possible.
Why not just use the Obsolete attribute? It can generate a build warning for you:
https://learn.microsoft.com/en-us/dotnet/api/system.obsoleteattribute?view=netframework-4.8
You can even make it emit an error too if you want.
The answer could be negative I think.
It seems that you use or call msbuild.exe to build your C# projects. But as far as I know, MSBuild in fact calls csc.exe to build C# projects in build time.
So actually what you want is logging a warning when the compiler compile the C# code if it recognize somewhere in your code uses the BadClass in build time.
If you have the source code of BadClass in the same solution, add a project reference format to the xx.csproj which contains BadClass, and set a #warning in the BadClass it may generate the warning in build time.
But I think the scenario you're in is something like: You developed one Assembly and distribute it to your user, so you want it generates a warning when the user calls one BadClass in your assembly and builds his own project to remind him of taking care when using this bad class. If so, this is impossible for msbuild AFAIK. If I misunderstand anything, feel free to know me know :)
Update:
As Daniel and Johnson said, ObsoleteAttribute is enough to do this. Though no valid way to generate warnings from msbuild aspect directly, but msbuild will call C# compiler during build process, so generates a compiler warning can output to build output window.
I am writing an simple phoneme forced alignment demo. I just copied some initialization code in the unit test file.
However, there are some functions causing LNK2019 error. Here is the list:
bin_mdef_free
dict_init
dict_free
dict2pid_build
dict2pid_free
ps_alignment_init
ps_alignment_free
I manually listed the symbols in pocketsphinx.lib, and I found many bin_mdef functions are listed, but except bin_mdef_free. (using DUMPBIN /ALL) All alignment functions are missed.
What should I do to include them in my lib file?
This is just because pocketsphinx did not export these functions. One should add POCKETSPHINX_EXPORT macro to these functions and recompile the source code to lib file.
I'm trying to implement my template matching (with drawing) in AOT form and when I was testing whether the different methods work by including separate static libraries that are compiled from another project, I got build errors like:
Severity Code Description Project File Line Suppression State
Error LNK2005 _ZN6Halide7Runtime8Internal13custom_mallocE already defined in template_matching_ccorr.lib(template_matching_ccorr.lib.obj) Halide Template Matching v2 AOT Run c:\Users\Admin\documents\visual studio 2015\Projects\Halide Template Matchign v2 AOT Run\Halide Template Matchign v2 AOT Run\template_matching_sqdiff.lib(template_matching_sqdiff.lib.obj) 1
Is there a way to be able to include multiple libraries and be able to run different functions?
Also is there a similar function as realize that can be used in a AOT compilation code or would that require me to make two different AOT functions (assuming I can call multiple functions to begin with)
EDIT: a quick fix seems to be adding /FORCE:MULTIPLE to linker's command line
EDIT2: managed to get it to compile with adding
Target target = get_host_target();
target.set_feature(Target::NoRuntime, true);
to most of the pipelines except one which solves the multiple definitions. Now I'm wondering why I have to have one pipeline with the runtime even though I could just include HalideRuntime.h but it doesn't really work.
/FORCE:MULTIPLE works. So does judicious use of the no_runtime target feature. See http://halide-lang.org/tutorials/tutorial_lesson_15_generators_usage.html for details.
You can compile each pipeline without a runtime, and then link them together with a standalone runtime. Or you can just compile one of your pipelines with a runtime.
I've got an Ektron 8.2 site, and I was trying to integrate Quartz.NET into it, in order to run some scheduling. Quartz.NET requires a library Common.Logging. This library introduces a conflict and breaks the Ektron code in App_Code/VBCode.
E.g. the following code from Utilities.vb
Case Is = Common.EkEnumeration.FolderType.Community
imageURL &= "images/ui/icons/folderCommunity.png"
Case Common.EkEnumeration.FolderType.Catalog
imageURL &= "images/ui/icons/folderGreen.png"
now gives a compile time error-
App_Code\VBCode\Utilities.vb(703,0): error BC30456: 'EkEnumeration' is not a member of 'Common'.
It appears that Common.Logging is conflicting with Ektron.Cms.Common (the Ektron files have a Imports Ektron.Cms statement). Is it possible to specify the priority on libraries? Or namespace an imported library?
Update
The Utilities.vb code is written by Ektron. I'd like to either make no changes to this code, or minimal changes, as any changes would need to be re-done upon Ektron upgrades. This is really a clash between 2 libraries - Ektron and Quartz.Net. Can I resolve this clash without changing the code of either library? Is there a configuration setting for aliasing libraries?
A simple solution is to use the full namespace, Ektron.Cms.Common.EkEnumeration, rather than relying on the include to sort things out automatically.
I.e.
Case Is = Ektron.Cms.Common.EkEnumeration...
Not elegant, but should get you working again.
Another alternative is to use a namespace alias:
using EkCommon = Ektron.Cms.Common;
So your code would instead look like:
EkCommon.EkEnumeration.FolderType.Community
I am getting LNK2001 errors when trying to use Crypto++. The official advice for this is:
There are two ways you can deal with this, either change Crypto++ to export those classes, by using the CRYPTOPP_DLL macro, or link with both the DLL export library and a static library that contains the non-DLL classes and functions. The latter can be built by using the "DLL-Import" configuration of the cryptlib project.
It would be preferable to use the first option, and given that I am not experienced in using Visual Studio, I cannot find the location and execution method of the macro.
In short: Where do I find the macro and how do I execute it?
Cheers.
In short: Where do I find the macro and how do I execute it?
The macro is CRYPTOPP_IMPORTS. You use it when performing dynamic linking on Windows (i.e., the Crypto++ DLL).
You can 'execute' it in one of two ways. First, you can add #include <cryptopp/dll.h> to your stdafx.h. dll.h. defines it, and dll.h must be included before any other Crypto++ defines. Second, add it to your project's preprocessor macros. In either case, CRYPTOPP_IMPORTS will be defined.
I suspect you have a different error, though. You're probably not including the Crypto++ library (for static linking) or Crypto++ import lib (for dynamic linking) in your project.