I am attempting to write a reusable package in Go. I'm using a structure similar to that described here but slightly different:
/src/bitbucket.org/EXTERNAL_PROJECT_NAME/EXTERNAL_PACKAGE_NAME/...
/src/INTERNAL_PROJECT_NAME/INTERNAL_PACKAGE_NAME/...
Or should the second line be:
/src/bitbucket.org/INTERNAL_PROJECT_NAME/INTERNAL_PACKAGE_NAME/...
Everything works until I need to access a non-go file that exists in the external package. For example, I have some built in templates that I would like to be available without having to include them in my internal projects templates directory.
To that end, I have a "templates" directory in the external project where I want to house some built-in templates and a "templates" directory in my internal project where custom templates will go. But when I attempt to parse templates from the external project template directory, it can't find them.
So how would I go about indicating that I want to get the templates from the external package directory instead of the internal one? I could adjust the path to something like the following:
../../bitbucket.org/EXTERNAL_PROJECT_NAME/EXTERNAL_PACKAGE_NAME/templates/file.html
but this is obviously very clumsy and depends on individual setup, so that's not going to work. In general, if I want to reference a file in an external package instead of my internal project directory, how would I do this gracefully?
Thanks!
Turns out there is a pretty simple solution. Looks something like the following:
package main
import (
"bitbucket.org/EXTERNAL_PROJECT/EXTERNAL_PACKAGE"
"go/build"
)
func main() {
SrcRoot := "/src"
PackageDir := "/bitbucket.org/EXTERNAL_PROJECT/EXTERNAL_PACKAGE"
InternalTemplateDir := build.Default.GOPATH + SrcRoot + PackageDir + "/templates/"
}
GOROOT here provides us with the path to the directory containing all our go code. From there, I want to reference the templates directory in the package source. With InternalTemplateDir, I now have the base path from which to reference templates within the external package.
For ease of use, I will probably build a template loader that checks for a file on an internal file path first and then checks for the same file in the external package, so that any given template can be overridden by including it internally, but essential templates will all have built in versions as well.
If it's not a Go package (aka bitbucket.org/EXTERNAL_PROJECT_NAME/EXTERNAL_PACKAGE_NAME/file.go) it's not gonna work, your best bet us something like https://github.com/jteeuwen/go-bindata.
But I really think you should rethink your problem and use a different approach to it.
Related
I am using Visual Studio (2017) and I need the following.
I have a folder where a code generator puts the .h and .c files obtained from a formal model. This folder is not controlled by me, e.g. I cannot write in it, but it is updated by another team member.
By using the /I compiler options (or Additional include directories in the project properties) I managed to import all the generated header files in my VS project. What I am supposed to do is to integrate this generated code into a specific platform, this means that I have to compile both the generated code and the integration code on the target platform. The problem is, the compiler is not able to resolve the generated function definitions of the generated code as it only sees the .h files. What I got is a linking error (external symbol not resolved)
To solve the problem, I added the existing .c files manually, one by one. The obvious problems that comes with this solution are
manual boring work
when new files are generated, I need to manually import the new files
Question is: is there an option that can be set in order to specify the path of the source files without passing them one by one?
note: just copying and pasting the generated code in the VS project folder is not an acceptable solution.
Thanks
If you look at https://learn.microsoft.com/en-us/cpp/ide/working-with-project-properties?view=vs-2017 then you see there is a Source Directories property that has $(VC_SourcePath) as a default but (I think) to which you can add additional paths. The documentation is unclear whether that means all source files in such a path will be included for compilation.
At the bottom of the documentation it explains how to override certain project properties by providing an external properties file. It seems you can override the targets/sources using such a file. You can generate the file using a small tool that reads the filenames in those directories and adds them to the file.
You could also analyze the .vcproj file and build a small tool that wil re-write the part with your generated source directories, reading the filenames in those directories and adding them to the section in the .vcproj file.
I've been attempting to modify my project's .csproj file, that will include one of two different resource(resx) files that will depend on what the build configuration is at the current time.
I've tried to use conditionals to differentiate the inclusion, something like:
Then proceeded to add the files that were located in different directories. However, when building I've either gotten errors or the build just ignored the conditionals and added the default resx files.
I was hoping someone might know how to conditionally add resx files depending on the current build configuration?
Thank you!
I am currently trying to create a plugin-like library for my company.
I need to check if four directories exist within the project structure. As java.io.File is not available, I am pretty confused on how to check for existance of a file that needs to exist within the project structure?
The concrete use-case.
There will be four directories:
/entities
/converter
/attributes
/caches
Now if the developer uses this library and wants to access all, lets say "Person"-Entities from the server, he should be able to call
RestGet.getAll("Person");
and the library looks in the source directory of the project if there are these Files:
/entities/PersonEntity.java //<-- Stores the actual data
/converter/PersonConverter.java //<-- Converts the JSON answer of the server to the Object
/attributes/PersonAttributes.java //<-- An enum that is used to set the attributes of the object
/caches/PersonCache.java //<-- A simple Cache
How can I do this? I tried with FileSystemStorage, but it only tell me that I should use getAppHome()...
I don't quite understand the usage of the source directory which obviously won't exist on the device where your application is running.
You can get access to files in the root of your SRC directory which get packaged into the JAR using Display.getInstance().getResourceAsStream(...).
The replacement to java.io.File is FileSystemStorage which is covered in the developer guide.
I need to use tcl.h in my C project (VS 2012) for registering function in SQLite. I have downloaded Tcl for windows and installed it. But my project still doesn't recognize when I write #include . What should I do to get access to this header?
Thanks in advance.
Open the project properties and do :
Right click on your project, go to properties, go to C/C++ session. On the field Additional Include Directories, add the path to the header you want, and use the header with "".
After that, you should go to the Linker session. On General, go to the Additional Library directories and add the path to the libs you need to add. Then go to Input and add the lib.
Sometimes you will need to copy a dll to the same folder of your executable. You can do that on Custom Build Step - Post Build Events.
You need to do it for each configuration and platform you want to build - one tip to make it easier is to use those variables $(Configuration) and $(Platform) when you are specifying the paths, and select on the dropdown list of the top of the properties window All configurations and All platforms, so you don't need to do it several times per project.
I have a straight C project that builds several different inter-related modules into a single image using a single top-level makefile and recursive calls to the modules. This all works fine, although I know it's not using the best structure. I now need to restructure it because of some changes to the project, and I'd like to do it "right". In addition, I've found that I'm using some common code in the modules that right now is just copied into each one, so I'd like to fix that too.
The further complication is that I'm using Subversion and the common code that's being used is stored in a separate repo from the project, so I can't just import each file that's used.
Here is the structure I think I'd like to use, but I'm not completely sure how to write the makefiles to actually work with it (but I can handle that in another question if needed).
build
+ common
| + lib1
| + lib2
+ module1
| + obj
+ module2
| + obj
+ module3
| + obj
+ output
Common would be an external to a folder in the other repo that has the common source files, and the makefile in each module would build intermediate object files locally (this is required as each module compiles differently, so the common files are not common binaries) and then put its final binary in the shared output directory for the top level makefile to combine into the single final image.
Is this a reasonable structure to use for make to deal with?
Module 1 uses a third-party library that may be switched out later. Should it be a sub-directory of module1, or should it be in common (hard to do with subversion, unless I mix it into the folder on the other repo), or should it be added as another directory under build?
Module 2 compiles to a static library for Module 3 to use. Should Module 3's makefile explicitly know about Module 2 or should the header file be in the common directory (the library will be in the output directory already)?
There are other common definitions that this project needs to set up for all the modules, which would ordinarily be in a header file in the common directory, but since that directory is coming from a subversion external, what are my other options for doing this?
First, some of these design questions are matters of taste and habit, and arguments about them can verge on religious war.
Second, your common directory is poorly named, since it serves specifically as a store of the code from the other repository (a good thing to have), and not as a place for all sources shared by multiple modules (a different good thing to have). So I suggest you add another directory such as build/headers/, for headers that are common to more than one module, but are stored in your own repository.
Yes, once you add headers/.
A subdir of module1/ is a good place for it; if the other modules don't use it, there's no reason for them to be able to see it.
headers/ is literally made for this. Put the header there. Module 3 has no business knowing more about Module 2's implementation than that.
Again, headers/ is the place for them.