Skip to content

Commit

Permalink
New way for arguments passing into main core. And fully updated compr…
Browse files Browse the repository at this point in the history
…ession together with .packer for more lightweight distribution, like for DllExport or hMSBuild project.

// TODO: code review and fully new structure! this is just a working draft version of the .packer and its compressors. But now it's really complex pre/post-processing than before o_o
  • Loading branch information
3F committed Dec 8, 2018
1 parent 6e66acf commit a200982
Show file tree
Hide file tree
Showing 4 changed files with 441 additions and 74 deletions.
38 changes: 25 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Initially this was developed for providing tools to service projects, libraries,

* [Conari](https://github.com/3F/Conari)
* [DllExport](https://github.com/3F/DllExport)
* [MvsSln](https://github.com/3F/MvsSln)
* [vsSolutionBuildEvent](https://github.com/3F/vsSolutionBuildEvent)
* [LunaRoad](https://github.com/3F/LunaRoad)
* [vsCommandEvent](https://github.com/3F/vsCommandEvent)
Expand Down Expand Up @@ -115,13 +116,24 @@ gnt /p:ngpackages="Conari" /p:proxycfg="guest:1234@10.0.2.15:7428"

#### Format of packages list

Attribute | Description
```
id[/version][:output]|id2[/version][:output]|...
```

Attribute | Description | Example
----------|---------------------------------------------|------------------------------
id | Identifier of package. | [Conari](https://www.nuget.org/packages/Conari)
version | **(Optional)** Version of package. | `1.3.0` or `1.3-beta2` or `1.3-RC` etc
output | **(Optional)** Path to write package data. | `../tests/ConariForTest`

Multiple packages:

Delimiter | Description
----------|-------------
id | Identifier of package.
version | Version of package.
output | Optional path for getting package.
`;` | `id1;id2;id3` Optional, starting from 1.7+. Means usage as an delimiter **only when** the `|` is not found.
`|` | `id1:dir;name|id2` Package **id1** into directory **dir;name** and package **id2** in `ngpath` path.

Property:
To use via arguments:

```bash
/p:ngpackages="id[/version][:output]"
Expand All @@ -131,7 +143,7 @@ Property:
/p:ngpackages="id[/version][:output];id2[/version][:output];..."
```

packages.config:
To use via packages.config:

```xml

Expand All @@ -148,10 +160,10 @@ packages.config:
/p:ngconfig=".nuget/packages.config"
```

multiple:
Multiple config files via delimiters:

* `;` - v1.6+
* `|` - v1.0+ (*obsolete and can be removed in new versions*)
* `;` - v1.6+ (Optional, starting from 1.7+. Means usage as an delimiter **only when** the `|` is not found.)
* `|` - v1.0+

```bash
/p:ngconfig="debug.config;release.config;..."
Expand Down Expand Up @@ -253,7 +265,7 @@ Now, you can use it simply:

### Additional arguments

key | Description | Sample
----------------|---------------------------------------------------------|----------------
`-unpack` | To generate minified version from executable. `v1.6+` | `gnt -unpack`
`-msbuild` path | To use specific msbuild if needed. `v1.6+` | `gnt -msbuild "D:\MSBuild\bin\amd64\msbuild" /p:ngpackages="Conari"`
First key to gnt | Description | Sample
------------------|---------------------------------------------------------|----------------
`-unpack` | To generate minified version from executable. `v1.6+` | `gnt -unpack`
`-msbuild` path | To use specific msbuild if needed. `v1.6+` | `gnt -msbuild "D:\MSBuild\bin\amd64\msbuild" /p:ngpackages="Conari"`
170 changes: 156 additions & 14 deletions embedded/.packer
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PropertyGroup>
<core Condition="'$(core)' == ''">..\logic.targets</core>
<output Condition="'$(output)' == ''">gnt.bat</output>
<maxline Condition="'$(maxline)' == ''">1777</maxline> <!-- length of line / max 2047 or 8191 characters https://support.microsoft.com/en-us/kb/830473 -->
<maxline Condition="'$(maxline)' == ''">1820</maxline> <!-- length of line / max 2047 or 8191 characters https://support.microsoft.com/en-us/kb/830473 -->
</PropertyGroup>

<!-- Entry point -->
Expand Down Expand Up @@ -90,6 +90,60 @@
return false;
};
Func<char[], int, Func<int, bool>, string[]> gencomb = (char[] _dict, int _size, Func<int, bool> _rule0) =>
{
var combination = new char[_size];
var set = new List<string>((int)Math.Pow(_dict.Length, _size));
int pos = 0;
Action generator = null;
generator = () =>
{
for(int i = 0, lim = _size - 1; i < _dict.Length; ++i)
{
if(pos == 0 && !_rule0(i)) {
continue;
}
if(pos < lim) {
combination[pos] = _dict[i];
++pos;
generator();
--pos;
}
else {
combination[pos] = _dict[i];
set.Add(new String(combination.ToArray()));
}
}
};
generator();
return set.ToArray();
};
var variables = new Dictionary<string, string>();
var cdict = new[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '_' };
var vdict = gencomb(cdict, 1, (int i) => { return char.IsLetter(cdict[i]) || cdict[i] == '_'; });
// to skip processing for:
var exword = new[] { "" };
int skipFirst = 110;
const string rlexemes = @"(?:
(?'wrd'
Console\s*\.\s*WriteLine
)
|
(?'ld'%%?0[aA])?
(?'cls'[a-z0-9A-Z_\-]+)
)";
using(StreamReader reader = new StreamReader(core, System.Text.Encoding.UTF8, true))
{
var content = reader.ReadToEnd();
Expand All @@ -109,16 +163,103 @@
//content = content.Replace("!", "^^!");
// Protecting data outside strings only:
content = Regex.Replace(content, @"\|", (Match m) => isInsideString(m.Index, scalc(content)) ? m.Value : "^" + m.Value);
content = Regex.Replace(content, @"\|", (m) => isInsideString(m.Index, scalc(content)) ? m.Value : "^" + m.Value);
// lexemes via vars
var lstat = new Dictionary<string, int>();
foreach(Match m in Regex.Matches(content, rlexemes, RegexOptions.IgnorePatternWhitespace))
{
var wrd = m.Groups["wrd"];
var cls = m.Groups["cls"];
var vname = wrd.Success ? wrd.Value : cls.Value;
if(vname.Length < 4) { // minimal is 3: %a%
continue;
}
// Secondly, keep in mind where placed all strings.
// We will work without double quotes, so we should correctly define all pairs of "..." per line
if(exword.Contains(vname)) {
continue;
}
if(!lstat.ContainsKey(vname)) {
lstat[vname] = -1 * (vname.Length + 7); //for init: set a= + length + &
}
lstat[vname] += (vname.Length - 3); //for use: %a%
}
uint uniqVars = 0;
variables.Clear();
var prio = lstat.Where(x => x.Value > 0).OrderByDescending(x => x.Value).Take(vdict.Length);
var defv = "";
content = Regex.Replace(content, rlexemes, (m) =>
{
if(m.Index < skipFirst) {
return m.Value;
}
var wrd = m.Groups["wrd"];
var cls = m.Groups["cls"];
var ld = m.Groups["ld"].Value;
var vname = wrd.Success ? wrd.Value : cls.Value;
if(prio.All(x => x.Key != vname)) {
return m.Value;
}
if(variables.ContainsKey(vname)) {
return ld + variables[vname];
}
if(uniqVars + 1 > vdict.Length) {
throw new OverflowException("vdict does not contain data for new vars");
}
var nv = vdict[uniqVars++];
variables[vname] = String.Format("%{0}%", nv);
defv += String.Format("set {0}={1}&", nv, vname);
return ld + variables[vname];
},
RegexOptions.IgnorePatternWhitespace);
// We'll work without double quotes, so we should define all pairs of "..." per line
var strings = scalc(content);
// Now, we should split long strings
var lines = new List<string>();
// Protecting from some symbols in zero position via moving to the end of the previous line
Action<int, int> safeAdd = delegate(int idx, int l)
{
int lofs = idx;
while( (content[lofs] == ' ' || content[lofs] == ')' || content[lofs] == '=')
||
//TODO: lexemes via vars %a%, %ab%, ... + escaped %%data
(content[lofs] == '%' || content[Math.Min(lofs + 1, content.Length - 1)] == '%')
)
{
++lofs;
}
int ofsdelta = lofs - idx;
if(ofsdelta > 0)
{
lines[lines.Count - 1] += content.Substring(idx, ofsdelta);
lines.Add(content.Substring(lofs, l - ofsdelta));
return;
}
lines.Add(content.Substring(idx, l));
};
for(int i = 0, len = maxline; i < content.Length; i += len)
{
int rlen = Math.Min(content.Length - i, len);
Expand All @@ -132,7 +273,7 @@
{
int repos = ((ifq.Key + ifq.Value) - rpos);
lines.Add(content.Substring(i, rlen + repos));
safeAdd(i, rlen + repos);
i += repos;
added = true;
Expand All @@ -144,20 +285,17 @@
continue;
}
// we don't see strings, but we also have escape chars as ^ + char above
// Protecting from escaped chars as ^ + char above
int esc = rpos - 1; // the end of the previous line that should be checked on `^` char
int lchar = Math.Min(rpos, content.Length - 1);
if(content.Length > esc && (content.ElementAt(esc) == '^' || content.ElementAt(lchar) == ' ')) {
int esc = rpos - 1; // the end of the previous line that should be checked on `^` char
if(content.Length > esc && content[esc] == '^') {
rlen += 1;
lines.Add(content.Substring(i, rlen));
safeAdd(i, rlen);
i += 1;
continue;
}
// TODO: the line cannot be started with: ` `(space), `=`, `"`
lines.Add(content.Substring(i, rlen)); // simply add new line without processing
safeAdd(i, rlen);
}
// Now we can define, how it should be written into external file
Expand All @@ -180,6 +318,10 @@
content += ldata;
}
// definition of lexemes
content = defv.Substring(0, defv.Length - 1) + "\r\n" + content;
// Finally, format script to work with gnt.core
using(StreamReader tplreader = new StreamReader("exec.tpl", System.Text.Encoding.UTF8, true)) {
Expand Down
Loading

0 comments on commit a200982

Please sign in to comment.