Merge: Extend nitpm (formerly picnit) to support package versions and dependencies
authorJean Privat <jean@pryen.org>
Fri, 6 Apr 2018 02:01:35 +0000 (22:01 -0400)
committerJean Privat <jean@pryen.org>
Fri, 6 Apr 2018 02:01:35 +0000 (22:01 -0400)
Rename picnit to nitpm and intro 4 main new features.

### Install package versions

Install specific versions of a package using the following command:

~~~
nitpm install gamnit=0.5
~~~

The version string (the `0.5` in the above example) must be a Git branch or tag, it will be used when cloning the package locally. The package will be downloaded to `~/.local/lib/nit/gamnit=0.5/`, allowing multiple versions of the same package to be installed concurrently.

### Dependencies in package.ini

Packages should now declare dependencies to other nitpm packages in the `package.ini` at the `import` key:

~~~
[package]
name=my_package
import=hello_nitpm, gamnit=0.5
~~~

The dependencies can then be installed automatically with `nitpm install` from the root of the package.

Nit tools read the local `package.ini` to redirect imports of `gamnit` inside this package to this specific version. So for `my_package` described above, all references to `gamnit` will use the implementation `gamnit=0.5`.

### Recursive installation

nitpm installs dependencies recursively, so if `gamnit` requires `glesv2`, after an explicit command to install `gamnit` nitpm will also install `glesv2`. This implementation is minimal, it could be improved by precalculating all dependencies and asking for confirmation.

### Customizable install directory

You can now use the env var `NITPM_PATH` to set the path where libraries are installed. This will override the default path at `~/.local/lib/nit/`.

### Others

* `nitpm uninstall` can uninstall many packages at once, it is safer and it accepts the -f option to skip the confirmation.
* `nitpm list` lists packages in alphabetical order.

Pull-Request: #2622
Reviewed-by: Romain Chanoir <romain.chanoir@viacesi.fr>
Reviewed-by: Jean Privat <jean@pryen.org>

lib/curl/curl.nit
lib/curl/native_curl.nit
share/android-bdwgc/setup.sh
src/compiler/abstract_compiler.nit
tests/sav/test_catch_multi_threaded.res [new file with mode: 0644]
tests/test_catch_multi_threaded.nit [new file with mode: 0644]

index 57a2423..64fbff2 100644 (file)
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Data transfer with URL syntax
+# Data transfer powered by the native curl library
 #
 # Download or upload over HTTP with `CurlHTTPRequest` and send emails with `CurlMail`.
 module curl
@@ -116,6 +116,12 @@ class CurlHTTPRequest
        # Set the user agent for all following HTTP requests
        var user_agent: nullable String is writable
 
+       # Set the Unix domain socket path to use
+       #
+       # When not null, enables using a Unix domain socket
+       # instead of a TCP connection and DNS hostname resolution.
+       var unix_socket_path: nullable String is writable
+
        # Execute HTTP request
        #
        # By default, the response body is returned in an instance of `CurlResponse`.
@@ -142,6 +148,12 @@ class CurlHTTPRequest
                        if not err.is_ok then return answer_failure(err.to_i, err.to_s)
                end
 
+               var unix_socket_path = unix_socket_path
+               if unix_socket_path != null then
+                       err = self.curl.native.easy_setopt(new CURLOption.unix_socket_path, unix_socket_path)
+                       if not err.is_ok then return answer_failure(err.to_i, err.to_s)
+               end
+
                # Callbacks
                err = self.curl.native.register_callback_header(callback_receiver)
                if not err.is_ok then return answer_failure(err.to_i, err.to_s)
index 1f5cd11..d3ed43a 100644 (file)
@@ -89,7 +89,7 @@ extern class NativeCurl `{ CURL * `}
                if obj isa Int then return native_setopt_int(opt, obj)
                if obj == true then return native_setopt_int(opt, 1)
                if obj == false then return native_setopt_int(opt, 0)
-               if obj isa String then return native_setopt_string(opt, obj)
+               if obj isa String then return native_setopt_string(opt, obj.to_cstring)
                if obj isa FileWriter then return native_setopt_file(opt, obj._file.as(not null))
                if obj isa CURLSList then return native_setopt_slist(opt, obj)
                return once new CURLCode.unknown_option
@@ -107,9 +107,8 @@ extern class NativeCurl `{ CURL * `}
        private fun native_setopt_slist(opt: CURLOption, list: CURLSList): CURLCode `{ return curl_easy_setopt( self, opt, list); `}
 
        # Internal method to set options to CURL using String parameter.
-       private fun native_setopt_string(opt: CURLOption, str: String): CURLCode import String.to_cstring `{
-               char *rStr = String_to_cstring(str);
-               return curl_easy_setopt( self, opt, rStr);
+       private fun native_setopt_string(opt: CURLOption, str: CString): CURLCode `{
+               return curl_easy_setopt( self, opt, str);
        `}
 
        # Request Chars internal information from the CURL session
@@ -121,7 +120,7 @@ extern class NativeCurl `{ CURL * `}
                 return answ.item.to_s
        end
 
-       # Internal method used to get String object information initially knowns as C Chars type
+       # Internal method used to get String object information initially known as C Chars type
        private fun native_getinfo_chars(opt: CURLInfoChars, res: Ref[CString]): CURLCode
        import Ref[CString].item= `{
                char *r;
@@ -753,6 +752,10 @@ extern class CURLOption `{ CURLoption `}
 #      new     `{ return CURLOPT_SSH_KEYFUNCTION; `}
 #      new     `{ return CURLOPT_SSH_KEYDATA; `}
 
+       # TELNET Options
+
+#      new     `{ return CURLOPT_TELNETOPTIONS; `}
+
        # Other Options
 
 #      new     `{ return CURLOPT_PRIVATE; `}
@@ -760,7 +763,6 @@ extern class CURLOption `{ CURLoption `}
 #      new     `{ return CURLOPT_NEW_FILE_PERMS; `}
 #      new     `{ return CURLOPT_NEW_DIRECTORY_PERMS; `}
 
-       # TELNET Options
-
-#      new     `{ return CURLOPT_TELNETOPTIONS; `}
+       # Set the Unix domain socket
+       new unix_socket_path `{ return CURLOPT_UNIX_SOCKET_PATH; `}
 end
index fcfbab3..7ea0c27 100755 (executable)
@@ -20,9 +20,9 @@ cd "`dirname "${BASH_SOURCE[0]}"`"
 
 # Download or redownload
 rm -rf bdwgc
-git clone -b android https://github.com/xymus/bdwgc.git || exit 1
+git clone --depth=1 -b android https://github.com/xymus/bdwgc.git || exit 1
 
 # Setup libatomic_ops too
 cd bdwgc || exit 1
 git submodule init || exit 1
-git submodule update || exit 1
+git submodule update --depth=1 || exit 1
index d93eba1..11e4790 100644 (file)
@@ -767,9 +767,10 @@ abstract class AbstractCompiler
                self.header.add_decl """
 struct catch_stack_t {
        int cursor;
-       jmp_buf envs[100];
+       int currentSize;
+       jmp_buf *envs;
 };
-extern struct catch_stack_t catchStack;
+extern __thread struct catch_stack_t catchStack;
 """
        end
 
@@ -870,7 +871,7 @@ extern void nitni_global_ref_decr( struct nitni_ref *ref );
                v.add_decl("int glob_argc;")
                v.add_decl("char **glob_argv;")
                v.add_decl("val *glob_sys;")
-               v.add_decl("struct catch_stack_t catchStack;")
+               v.add_decl("__thread struct catch_stack_t catchStack = \{-1, 0, NULL\};")
 
                if self.modelbuilder.toolcontext.opt_typing_test_metrics.value then
                        for tag in count_type_test_tags do
@@ -971,7 +972,6 @@ extern void nitni_global_ref_decr( struct nitni_ref *ref );
                v.add "#endif"
 
                v.add("glob_argc = argc; glob_argv = argv;")
-               v.add("catchStack.cursor = -1;")
                v.add("initialize_gc_option();")
 
                v.add "initialize_nitni_global_refs();"
@@ -3504,6 +3504,14 @@ redef class ADoExpr
        redef fun stmt(v)
        do
                if self.n_catch != null then
+                       v.add("if(catchStack.currentSize == 0) \{")
+                       v.add("         catchStack.cursor = -1;")
+                       v.add("         catchStack.currentSize = 100;")
+                       v.add("         catchStack.envs = malloc(sizeof(jmp_buf)*100);")
+                       v.add("\} else if(catchStack.cursor == catchStack.currentSize - 1) \{")
+                       v.add("         catchStack.currentSize *= 2;")
+                       v.add("         catchStack.envs = realloc(catchStack.envs, sizeof(jmp_buf)*catchStack.currentSize);")
+                       v.add("\}")
                        v.add("catchStack.cursor += 1;")
                        v.add("if(!setjmp(catchStack.envs[catchStack.cursor]))\{")
                        v.stmt(self.n_block)
diff --git a/tests/sav/test_catch_multi_threaded.res b/tests/sav/test_catch_multi_threaded.res
new file mode 100644 (file)
index 0000000..04f734e
--- /dev/null
@@ -0,0 +1,10 @@
+caught 100000 aborts
+caught 100000 aborts
+caught 100000 aborts
+caught 100000 aborts
+caught 100000 aborts
+caught 100000 aborts
+caught 100000 aborts
+caught 100000 aborts
+caught 100000 aborts
+caught 100000 aborts
diff --git a/tests/test_catch_multi_threaded.nit b/tests/test_catch_multi_threaded.nit
new file mode 100644 (file)
index 0000000..42795f4
--- /dev/null
@@ -0,0 +1,56 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Test the multi-threaded dynamic `do catch` mechanism
+import pthreads
+
+# A Thread that does a lot of `do catch`
+class CatchThread
+       super Thread
+
+       var x = 100000
+       var caught = 0
+
+       redef fun main do
+               do
+                       rec_do_catch
+               catch
+               end
+               print "caught {caught} aborts"
+               return null
+       end
+
+       fun rec_do_catch do
+               do
+                       x -= 1
+                       if x > 0 then
+                               rec_do_catch
+                       else
+                               abort
+                       end
+               catch
+                       self.caught += 1
+                       abort
+               end
+       end
+end
+
+var ts = new Array[CatchThread]
+var nb_threads = 10
+for i in [0..nb_threads[ do
+       var t = new CatchThread
+       ts.add(t)
+       t.start
+end
+for t in ts do t.join