RejectedSoftware Forums

Sign up

Need help to understand how to make dub package

There is small HTML parsing lib https://github.com/Bystroushaak/DHTMLParser
I am trying to understand how to use this lib with my code (just simple App for test).

  1. Do I need to create package.json and and mark code as library?
  2. How I can set that for both files from package should be passed to compiler (like dmd findlinks.d dhtmlparser.d quoteescaper.d)?

Re: Need help to understand how to make dub package

Am 27.10.2014 07:38, schrieb Suliman:

There is small HTML parsing lib https://github.com/Bystroushaak/DHTMLParser
I am trying to understand how to use this lib with my code (just simple App for test).

  1. Do I need to create package.json and and mark code as library?
  2. How I can set that for both files from package should be passed to compiler (like dmd findlinks.d dhtmlparser.d quoteescaper.d)?

The following (untested) should be sufficient for a dub.json
("package.json" as a name will get deprecated at some point). Target
type "library" will be inferred because there is no recognized main
source file.

{
	"name": "d-html-parser",
	"sourceFiles": ["dhtmlparser.d", "quote_escaper.d"],
	"importPaths": ["."]
}

Ideally, the two source files would be moved to a "source" or "src"
folder. That would avoid possible import conflicts and would mean than
only the name needs to be put into dub.json - the rest gets inferred then.

Re: Need help to understand how to make dub package

{
	"name": "d-html-parser",
	"sourceFiles": ["dhtmlparser.d", "quote_escaper.d"],
	"importPaths": ["."]
}

Ideally, the two source files would be moved to a "source" or "src"
folder. That would avoid possible import conflicts and would mean than
only the name needs to be put into dub.json - the rest gets inferred then.

"library"? Whu not "sourceLibrary"?

ok, I moved this 2 files at src folder.

Am I right understand that I do not need to specify their names, bacause all of files from src would be imported?

I do not need to specify importPaths because it will do search all files in current folder?

I wrote next dyb.json file:

{
	"name": "DHTMLParser",
	"description": "A minimal D application.",
	"copyright": "Copyright © 2014, Suliman",
	"targetType": "sourceLibrary",
	"authors": ["Suliman"],
	"dependencies": {
	}
}

but I am getting error:
"Error executing command run: Main package must have a binary target type, not sourceLibrary. Cannot build."

with:
"targetType": "library",

error:

Building dhtmlparser ~master configuration "library", build type debug.
Running dmd...
source\dhtmlparser.d(382): Warning: else is dangling, add { } after condition at
 source\dhtmlparser.d(379)
source\dhtmlparser.d(390): Warning: else is dangling, add { } after condition at
 source\dhtmlparser.d(386)
source\dhtmlparser.d(884): Warning: else is dangling, add { } after condition at
 source\dhtmlparser.d(881)
FAIL .dub\build\library-debug-windows-x86-dmd_2066-CA3B61C3E83E5D50F59F152BAC903
747\ dhtmlparser staticLibrary
Error executing command run: dmd failed with exit code 1.

Re: Need help to understand how to make dub package

Am 30.10.2014 11:03, schrieb Suliman:

{
	"name": "d-html-parser",
	"sourceFiles": ["dhtmlparser.d", "quote_escaper.d"],
	"importPaths": ["."]
}

Ideally, the two source files would be moved to a "source" or "src"
folder. That would avoid possible import conflicts and would mean than
only the name needs to be put into dub.json - the rest gets inferred then.

"library"? Whu not "sourceLibrary"?

"library" is usually the recommended choice. It gives the user control
over how the library is built (as a static library by default, or as a
source library using the --combined switch). Later it could also be
made possible for a package to configure how a dependency is built.

"sourceLibrary" mainly makes sense for libraries where you always want
to avoid that they produce a binary during the build process (header
only C bindings are the prime example).

ok, I moved this 2 files at src folder.

Am I right understand that I do not need to specify their names, bacause all of files from src would be imported?

I do not need to specify importPaths because it will do search all files in current folder?

Exactly. All .d files are recursively added and the "src" folder itself
is added as an import path.

I wrote next dyb.json file:

{
	"name": "DHTMLParser",
	"description": "A minimal D application.",
	"copyright": "Copyright © 2014, Suliman",
	"targetType": "sourceLibrary",
	"authors": ["Suliman"],
	"dependencies": {
	}
}

but I am getting error:
"Error executing command run: Main package must have a binary target type, not sourceLibrary. Cannot build."

This is because "sourceLibrary" specifically means "include the
sources in build command for the parent package and do not produce a
separate binary". You can still use it as a dependency, though, just not
perform a stand-alone build.

with:
"targetType": "library",

error:

Building dhtmlparser ~master configuration "library", build type debug.
Running dmd...
source\dhtmlparser.d(382): Warning: else is dangling, add { } after condition at
  source\dhtmlparser.d(379)
source\dhtmlparser.d(390): Warning: else is dangling, add { } after condition at
  source\dhtmlparser.d(386)
source\dhtmlparser.d(884): Warning: else is dangling, add { } after condition at
  source\dhtmlparser.d(881)
FAIL .dub\build\library-debug-windows-x86-dmd_2066-CA3B61C3E83E5D50F59F152BAC903
747\ dhtmlparser staticLibrary
Error executing command run: dmd failed with exit code 1.

By default, warnings are treated as errors by DUB. You could add
"buildRequirements": ["allowWarnings"] or "silenceWarnings" to
ignore them instead. But of course I'd recommend to fix the warnings
instead by adding additional braces around the code, because DMD's
warnings are usually pretty helpful in avoiding some classes of bugs.

Re: Need help to understand how to make dub package

But I do not get such errors when I am trying to compile all with dmd:
dmd findlinks.d dhtmlparser.d quoteescaper.d

it's produce proper exe file.

If suggest, that I created proper dub.json file, how I can use it.

Now I have small app named find_links.d I put it in new dub project. And what next? How to link it's with DHTMLParser?

Re: Need help to understand how to make dub package

On Thu, 30 Oct 2014 10:59:13 GMT, Suliman wrote:

But I do not get such errors when I am trying to compile all with dmd:
dmd findlinks.d dhtmlparser.d quoteescaper.d

it's produce proper exe file.

If suggest, that I created proper dub.json file, how I can use it.

Now I have small app named find_links.d I put it in new dub project. And what next? How to link it's with DHTMLParser?

If you want to produce an executable file, use "targetType": "executable". You can also create multiple configurations, one to build a stand-alone application and one to build as a library. The easiest way is to put the main() function in a separate "source/app.d" file and then not specify a "targetType" at all. DUB will then automatically infer an "application" and a "library" configuration (where "application" is the default when building separately).

If you want to create a library together with a set of little utility applications, the cleanest way would be to use "subPackages" for the utilities.

Re: Need help to understand how to make dub package

F:.
|
+---CoreApp
| | .gitignore
| | dub.json
| | dub.selections.json
| |
| +---.dub
| | | dub.json
| | |
| | ---build
| ---source
| app.d
|
---DHTMLParser

|   .gitignore
|   dub.json
|   
+---.dub
|   |   dub.json
|   |   
|   \---build

\---source
        dhtmlparser.d
        quote_escaper.d
        


CoreApp is my main app. I App.d is requery for compiling dhtmlparser.d and quote_escaper.d

json for app.d:

{
	"name": "coreapp",
	"description": "A minimal D application.",
	"copyright": "Copyright © 2014, Suliman",
	"authors": ["Suliman"],
	"dependencies": {
	}
	"subPackages": "../DHTMLParser"
}

error:

F:\Dima\1\CoreApp>dub
Error at line: 7
Error at line: 7
Error executing command run: Failed to load package at F:\Dima\1\CoreApp\: Expected '}' or ',' - got '"'.

Re: Need help to understand how to make dub package

I moved DHTMLParser to core App folder.
I missed "," after "dependencies":

{
	"name": "coreapp",
	"description": "A minimal D application.",
	"copyright": "Copyright © 2014, Suliman",
	"authors": ["Suliman"],
	"dependencies": {
	},
	"subPackages": "./DHTMLParser"
}

and now I have got error:

F:\Dima\1\CoreApp>dub
Building coreapp ~master configuration "application", build type debug.
Compiling using dmd...
source\app.d(6): Error: module dhtmlparser is in file 'dhtmlparser.d' which cann
ot be read
import path[0] = source
import path[1] = C:\D\dmd2\windows\bin\..\..\src\phobos
import path[2] = C:\D\dmd2\windows\bin\..\..\src\druntime\import
FAIL .dub\build\application-debug-windows-x86-dmd_2066-F6963A6398E4BF11AA7988E6B
7890DD9\ coreapp executable
Error executing command run: dmd failed with exit code 1.