I am developing some server-side code in Swift on my Mac, but for eventual deployment on Linux. I have created my project structure using the Swift Package Manager. I've created a couple of XCTestCase unit tests for classes. I've noticed, however, that if I set my target product to .executable, when I run swift test I get output similar to:
Compile Swift Module 'MyProjUtilTests' (3 sources) Linking
./.build/x86_64-apple-macosx10.10/debug/MyProjUtilPackageTests.xctest/Contents/MacOS/MyProjUtilPackageTests
Undefined symbols for architecture x86_64:
"__T012MyProjUtil16PropertyListUtilCMa", referenced from:
__T017MyProjUtilTests20PropertyListUtilTestC16testReadFromFileyyF in PropertyListUtilTest.swift.o "__T012MyProjUtil3FooCMa", referenced
from:
__T017MyProjUtilTests03FooC0C07testRunD0yyFSSyKXKfu_ in FooTests.swift.o "__T012MyProjUtilAAVABycfC", referenced from:
__T017MyProjUtilTestsAAC11testExampleyyFSSyKXKfu_ in MyProjUtilTests.swift.o ld: symbol(s) not found for architecture
x86_64 :0: error: link command failed with exit code 1 (use
-v to see invocation) error: terminated(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool
-f /Volumes/Untitled/SwiftDev/MyProj/MyProjUtil/.build/debug.yaml test
However, if I change my target product to .library, and run swift test it executes my tests and exits without an error. Is this a bug in the Swift Package Manager? Do I need to do something else in order to include unit tests in my executable product? Or is this the expected behavior? Can anyone shed some light on what I'm seeing here and why? Thanks!!
Yes, this is expected behavior.
You could make three targets in your Package.swift. "MyAppLibTests", "MyAppLib" and a "MyAppExec".
"MyAppLibTests" depends on "MyAppLib". "MyAppExec" also depends on "MyAppLib". And "MyAppLib" depends on whatever external dependencies you might have.
Your directory structure could look like:
+-- Package.swift
|
+-- Sources/
| |
| +-- MyAppLib/
| | ...files...
| |
| +-- MyAppLibExec/
| |
| +-- main.swift
|
+-- Tests/
|
+-- MyAppLibTests/
|
+-- MyTestCase.swift
And then in your main.swift, you would import MyAppLib; import Foundation and then perhaps parse the commandline arguments and environment variables. Pass the options into your library's main entry point. Something like MyAppMain().run(option: parsedValue, option2: parsedValue2)
Bonus: to get a commandline argument, they are in an array of Strings: Commandline.arguments. To get Environment variables, they are in a Dictionary of Strings to Strings: ProcessInfo.processInfo.environment["SOME_ENV_VAR"]
Related
I'm familiar with writing custom PowerShell modules using the following folder structure:
Modules
| +-- WebUtils
| | +-- WebUtils.psm1
| +-- BuildUtils
| | +-- BuildUtils.psm1
Where you might import the webutils module by doing something like using module WebUtils.
I have a large ongoing project that reuses a lot of the same functionality. Right now I have a hundred or so loosely related functions in a module. The problem is that I usually only need to use 10 - 20 of them depending on the project. I would like to split up the modules in a way similar to this:
Modules
| +-- Utils
| | +-- Web
| | | +-- Web.psm1
| | +-- Build
| | | +-- Build.psm1
| | +-- Utils.psm1
Where I could call them like using module Utils.Web or something similar.
How do I go about doing this? I haven't been able to find any good examples yet. Is this a good way of organizing things?
Large modules geenrally split out into seperate modules which perform a set of related functions. A good example of this Azure or - as below - VMware PowerCLI
If you Import-Module VMware.PowerCLI it will import all the modules. But you can import an individual module and it will only import those functions/commands and any module dependencies via them being named in the .psd1 e.g if you only want VMware.VimAutomation.Core it pulls in VMware.VimAutomation.Cis.Core too
So no, not subfolders of the one module but additional related modules which can be loaded.
Ive been having the "No such file or directory" issue for quite some time in PlatformIO extension with VScode when its never been an issue in Visual Studio. (not VScode)
My project setup is as follows:
MyProject
|--include
| |--config.h
|--lib
| |--LibraryA
| | |--libraryA.h
| | |--libraryA.cpp
| |--LibraryB
| | |--libraryB.h
| | |--libraryB.cpp
|--src
| |--main.cpp
Now, if I include config.h in main.cpp all is well. But if I include config.cpp in LibraryA/B.h or LibraryA/B.cpp I get the "No such file or directory" compiling error.
Why is this? If I right click #include "config.h" and select "Go to References" it takes me to the config file, or I can "Tab" autocomplete when typing in config.h it does so successfully too. So it knows the header file exists. Why can the linker not find it?
Any help would be greatly appreciated.
Thank you
I finally found the solution. All files in src and include folders are not global. The linker cannot know of the existence of these files, even if intellisense (which is not the same as the linker - which is not the same to the compiler) knows its reference.
To solve this problem add the following line to the platform.ini file.
build_flags = -I include
This will make the content of the include folder visible
EDIT: Answered, below.
Also: If you are reading this you are probably new to web dev and you should consider using webpack for this instead of babel alone
I have what seems like a very simple problem but I can't solve it.
I have a directory structure
Project
|
+-- scripts
|
|
+-- src / src.js
|
|
+-- compiled / compiled.js
And I have been trying to get the following command to work when my terminal is located in the scripts folder.
C:\Users\me\JavaScriptProjects\survey\scripts>npx babel ./src/src.js --out-file ./compiled/compiled.js presets=env,react --watch
But it simply keeps returning:
C:\Users\me\JavaScriptProjects\survey\scripts>npx babel ./src/src.js --out-file ./compiled/compiled.js presets=env,react --watch
presets=env,react doesn't exist
I have tried permutations of removing the ./, replacing it with only /, going into src dir and replacing src/src.js with src.js and then doing ../compiled/compiled.js and many other permutations, but it just keeps saying it doesn't exist.
Even if I add both files to the same directory it's giving the same error.
Most annoying part is it was working fine yesterday.
Thanks in advance.
Solved.
The following has worked from within the src dir after trying for around an hour. I don't know what I've done differently, would love it if someone can point it out.
Thanks.
C:\Users\me\JavaScriptProjects\survey\scripts\src>npx babel src.js --out-file=../compiled/compiled.js --presets=env,react --watch
It could be that you have a babel.config.json file in the \scripts\src folder and that if you move to the \scripts folder to run npx, then it can't see the config file and so doesn't see react.
Project
|
+-- scripts
|
+-- src / src.js
+-- src / babel.config.json
|
+-- compiled / compiled.js
I am trying to build the java projects with gradle and my project structure something like below:
Root
|
|----Child
| |
| Child1 (build.gradle)
|
|
|----Child12
| |
| Child111
| |
| Child222(build.gradle)
|
settings.gradle
As you can see, the project structure, here I am doing the gradle eclipse build for all the projects (Child1, Child222) in a single attempt by modifying settings.gradle and including the child projects something like below:
include 'Child/Child1'
include 'Child12/Child111/Child222'
Build is fine with that.
Whereas, while importing the projects(Child1, Child222) into eclipse, I am getting the following error:
Creation Problems
Path for project must have only one segment.
Because, in the Child1 .project file
<projectDescription>
<name>Root/Child1</name>
<projectDescription>
project name appearing as Root/Child1, instead of Child1.
Is there anyway, with that I can import the projects into the eclipse?
I got it, I changed settings.gradle file like below:
include 'Child:Child1'
include 'Child12:Child111:Child222'
It's working fine for me.
We’re trying to implement the MVP pattern using a custom Vaadin widget. In order to avoid duplicating interfaces, our first approach was making the Vaadin server-side component to implement the view interface.
But when I compile the widgetset, I got the following error:
Widgetset does not contain implementation for com.enterprise.designer.vaadin.widget.workflow.Workflow. Check its #ClientWidget mapping, widgetsets GWT module description file and re-compile your widgetset. In case you have downloaded a vaadin add-on package, you might want to refer to add-on instructions. Unrendered UIDL:
com.enterprise.designer.vaadin.widget.workflow.Workflow(NO CLIENT IMPLEMENTATION FOUND) id=PID2 caption=Editorongo actionCount=1 workflowAction_0_id=1 workflowAction_0_name=addStartNode workflowAction_0_y=75.0 workflowAction_0_x=50.0
If I comment the interface (and the imports) it works ok, even if I uncomment them after building the widgetset. The code (with import/implements commented) looks like the following:
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
//import com.enterprise.designer.workflow.presenter.WorkflowDrawArea;
//import com.enterprise.platform.i18n.api.Language;
//import com.enterprise.platform.mvp.api.ViewEventNotifier;
//import com.enterprise.platform.r13n.api.Region;
//import com.enterprise.vaadin.mvp.VaadinView;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.Resource;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.Component;
#com.vaadin.ui.ClientWidget(com.enterprise.designer.vaadin.widget.workflow.client.ui.VWorkflow.class)
public class Workflow extends AbstractComponent
//implements WorkflowDrawArea.Display, VaadinView
{
. . .
The log doesn’t show any error (except for sources for validation api, but the same errors are shown when I comment the interface and it works ok). I tried both compiling form Eclipse plugin and from command line.
Any idea? Thanks in advance.
Crosspost: https://vaadin.com/forum/-/message_boards/view_message/817539
I found a workaround. If I create an intermediate class for the widget, it compiles OK. And creating a sub class of that widget and using it form Vaadin application works ok, so I can make such subclass implementing the interface from an external project:
________________________________
|com.vaadin.ui.AbstractComponent |
|________________________________|
^
/|\
|
|
____________________________________________
|com.enterprise.designer.vaadin.widget.Dummy |
|--------------------------------------------|
| <#com.vaadin.ui.ClientWidget > |
|____________________________________________|
^
/|\ ______________________________________
| | com.enterprise.vaadin.mvp.VaadinView |
| |______________________________________|
| ^
| /|\
| | implements
| |
_________________________________________________________
| com.enterprise.designer.vaadin.widget.workflow.Workflow |
|_________________________________________________________|
|
| ________________________
| | com.vaadin.Application |
|uses |________________________|
| ^
| /|\
| |
| |
_____________________________________________________
| com.enterprise.designer.vaadin.widget.MyApplication |
|_____________________________________________________|
In this diagram, Dummy is the Vaadin widget (which implements the paintContent method) and Workflow is the subclass implementing the interface form other project (VaadinView). The Vaadin application (MyApplication) uses Worflow class directly.
However, it would be nice solving the problem without this workaround :)
If you get some think like "NO CLIENT IMPLEMENTATION FOUND", it mean during widgetset compilations were some errors. I have same problem, complication was OK, but no effect for application. After debugging I found problem, in my app was used drools library and inside this lib was compiler with same name as in gwt-dev libraries and during widgetset compilation compiler takes wrong class to compile widgetset and as result widgetset compile with errors. Drools library in app should be included all time and only way to solve this problem was compile widgetset manually. If you use Eclipse you should add in module new "Java application" with:
Project: {your project}
Main class: com.google.gwt.dev.Compiler
Program arguments: -gen {your project location (like C:\workspace**)}\target.generated -logLevel INFO -style OBF -war {your project location}\src\main\webapp\VAADIN\widgetsets -localWorkers 4 {your project custom widgetset location in java packages(like com.***.widgetset.CustomWidgetset)}
After this in project class path in "Libraries" add external jar gwt-dev-2.3.0.jar(or other version) on top of all libraries, this needed only to be sure that compiler take right java class and in "Source" change for all available folder field "Included:*/.java" to "Included:(All)"
It should help solve your problem.