Skip to content
This repository was archived by the owner on Sep 30, 2023. It is now read-only.

Commit f917f83

Browse files
13xforevermadetara
authored andcommitted
feat: добавил unmanaged-deps в module.yaml
Добавил возможность пометить конфигурацию модуля чтобы не править зависимости Конфигурация пропускается при вызове ref fix если есть флаг unmanaged-deps Пример: ```yaml my-config: unmanaged-deps: true deps: - dep1 - dep2 ```
1 parent 76ce995 commit f917f83

File tree

5 files changed

+216
-143
lines changed

5 files changed

+216
-143
lines changed

docs/README-module.yaml.md

+156-141
Original file line numberDiff line numberDiff line change
@@ -9,169 +9,184 @@ Each configuration may include the following sections:
99
- build
1010
- install/artifacts
1111

12-
Configurations may be inherited in order to avoid repeating of dependencies information.
12+
Configurations may be inherited to avoid repeating of dependencies information.
1313

1414
A module shall contain configuration `full-build`, including all the others, if possible. It will be used while execution of the following commands `cm get` and `cm build`.
1515

1616
Optional configuration `default` can contain default build and deps sections.
1717

1818
Example:
19-
20-
# configuration description section client
21-
client:
22-
# list of dependencies of client configuration
23-
# dependencies are listed in the following form: <moduleName>[@branchName][/configName]
24-
# kanso – reference to kanso module
25-
# kanso/client – reference to kanso in client configuration
26-
# kanso@develop/client - kanso from develop branch in client configuration
27-
# '@' and '/' marks in branch name should be shielded by '\'
28-
deps:
29-
- core
30-
- log4net
31-
- nunit
32-
- logging
33-
- http
34-
- http.rp
35-
- topology
36-
# to prefer current branch in deps
37-
- force: $CURRENT_BRANCH
38-
# or use <moduleName>@$CURRENT_BRANCH to prefer current branch in some module;
39-
# you can also choose any specific branch name in deps:
40-
# - force: mybestbranch
41-
# or provide a comma-separated list of preferred branches:
42-
# - force: mybestbranch,notsogoodbranch,leastfavoritebranch
43-
# master branch is always the default option if all forced branches are missing
44-
45-
# information on build of the present module in the present configuration
46-
build:
47-
# build solution Kontur.Drive.sln in Client configuration
48-
target: Kontur.Drive.sln
49-
configuration: Client
50-
51-
# Information on results of the present configuration build
52-
install:
53-
- bin/Kontur.Drive.Client.dll
54-
- bin/Kontur.Drive.ServiceModel.dll
55-
# For operation of Kontur.Drive.Client.dll you need a reference on logging module build
56-
- module logging
57-
# Or a reference on nuget bundle
58-
- nuget Newtonsoft.Json/6.0.8
59-
60-
# Configuration sdk "expands" configuration client (> client)
61-
# and is a configuration at default (*default) (it is used at referencing on this module)
62-
sdk > client *default:
63-
# in order to avoid repetition of dependencies lists
64-
# deps from client are inherited here and you have no need to state them once again
65-
deps:
66-
- auth
67-
- libfront
68-
- zebra
69-
- kanso
70-
- upload-service
71-
- access-control
72-
- zebra-utils
73-
- config
74-
- zookeeper
75-
76-
# Section build is NOT inherited
77-
build:
78-
target: Kontur.Drive.sln
79-
configuration: Sdk
80-
81-
# Section install is inherited, so you need to add only missing binaries
82-
install:
83-
- Kontur.Drive.TestHost/bin/Release/Kontur.Drive.TestHost.exe
84-
- Kontur.Drive.TestHost/bin/Release/ServiceStack.Interfaces.dll
85-
# DLL files that can be used by other modules,
86-
# but are ignored while running cm ref add
87-
artifacts:
88-
- Kontur.Drive.TestHost/bin/Release/SomeOther.dll
89-
90-
91-
# Configuration full-build expands client and sdk
92-
full-build > client, sdk:
93-
deps:
94-
# So you state diff on deps (in configuration full-build kanso/full-build is used.
95-
# At first, we “delete” kanso from dependencies, then add kanso/full-build)
96-
- -kanso
97-
- kanso/full-build
98-
99-
build:
100-
target: Kontur.Drive.sln
101-
configuration: Release
102-
19+
```yaml
20+
# configuration description section client
21+
client:
22+
# list of dependencies of client configuration
23+
# dependencies are listed in the following form: <moduleName>[@branchName][/configName]
24+
# kanso – reference to kanso module
25+
# kanso/client – reference to kanso in client configuration
26+
# kanso@develop/client - kanso from develop branch in client configuration
27+
# '@' and '/' marks in branch name should be shielded by '\'
28+
deps:
29+
- core
30+
- log4net
31+
- nunit
32+
- logging
33+
- http
34+
- http.rp
35+
- topology
36+
# to prefer current branch in deps
37+
- force: $CURRENT_BRANCH
38+
# or use <moduleName>@$CURRENT_BRANCH to prefer current branch in some module;
39+
# you can also choose any specific branch name in deps:
40+
# - force: mybestbranch
41+
# or provide a comma-separated list of preferred branches:
42+
# - force: mybestbranch,notsogoodbranch,leastfavoritebranch
43+
# master branch is always the default option if all forced branches are missing
44+
45+
# information on build of the present module in the present configuration
46+
build:
47+
# build solution Kontur.Drive.sln in Client configuration
48+
target: Kontur.Drive.sln
49+
configuration: Client
50+
51+
# Information on results of the present configuration build
52+
install:
53+
- bin/Kontur.Drive.Client.dll
54+
- bin/Kontur.Drive.ServiceModel.dll
55+
# For operation of Kontur.Drive.Client.dll you need a reference on logging module build
56+
- module logging
57+
# Or a reference on nuget bundle
58+
- nuget Newtonsoft.Json/6.0.8
59+
60+
# Configuration sdk "expands" configuration client (> client)
61+
# and is a configuration at default (*default) (it is used at referencing on this module)
62+
sdk > client *default:
63+
# in order to avoid repetition of dependencies lists
64+
# deps from client are inherited here and you have no need to state them once again
65+
deps:
66+
- auth
67+
- libfront
68+
- zebra
69+
- kanso
70+
- upload-service
71+
- access-control
72+
- zebra-utils
73+
- config
74+
- zookeeper
75+
76+
# Section build is NOT inherited
77+
build:
78+
target: Kontur.Drive.sln
79+
configuration: Sdk
80+
81+
# Section install is inherited, so you need to add only missing binaries
82+
install:
83+
- Kontur.Drive.TestHost/bin/Release/Kontur.Drive.TestHost.exe
84+
- Kontur.Drive.TestHost/bin/Release/ServiceStack.Interfaces.dll
85+
# DLL files that can be used by other modules,
86+
# but are ignored while running cm ref add
87+
artifacts:
88+
- Kontur.Drive.TestHost/bin/Release/SomeOther.dll
89+
90+
91+
# Configuration full-build expands client and sdk
92+
full-build > client, sdk:
93+
deps:
94+
# So, you state diff on deps (in configuration full-build kanso/full-build is used.
95+
# At first, we “delete” kanso from dependencies, then add kanso/full-build)
96+
- -kanso
97+
- kanso/full-build
98+
99+
build:
100+
target: Kontur.Drive.sln
101+
configuration: Release
102+
```
103103
104104
# build section
105105
106106
#### For a module which does not need to be built:
107-
108-
build:
109-
target: None
110-
configuration: None
107+
```yaml
108+
build:
109+
target: None
110+
configuration: None
111+
```
111112
112113
#### If it is necessary to state additional parameters:
113-
114-
build:
115-
# A statement of build target
116-
target: Solution.sln
117-
tool:
118-
# An assembling tool. msbuild - for MSBuild.exe at Windows and xbuild at *nix. dotnet - for new .NET Core
119-
name: msbuild
120-
# msbuild version, the latest at default
121-
version: "14.0"
122-
# set VS150COMNTOOLS=D:\Program Files\Microsoft Visual Studio\2017\Professional\Common7\Tools\
123-
# Solution configuration
124-
configuration: Release
125-
# You can state your parameters here. Default parameters are not used.
126-
# Quotation marks in parameters are shielded by '\'.
127-
# Default parameters for msbuild:
128-
# /t:Rebuild /nodeReuse:false /maxcpucount /v:m /p:WarningLevel=0 /p:VisualStudioVersion=14.0 (if not stated)
129-
parameters: "/p:WarningLevel=0"
114+
```yaml
115+
build:
116+
# A statement of build target
117+
target: Solution.sln
118+
tool:
119+
# An assembling tool. msbuild - for MSBuild.exe at Windows and xbuild at *nix. dotnet - for new .NET Core
120+
name: msbuild
121+
# msbuild version, the latest at default
122+
version: "14.0"
123+
# set VS150COMNTOOLS=D:\Program Files\Microsoft Visual Studio\2017\Professional\Common7\Tools\
124+
# Solution configuration
125+
configuration: Release
126+
# You can state your parameters here. Default parameters are not used.
127+
# Quotation marks in parameters are shielded by '\'.
128+
# Default parameters for msbuild:
129+
# /t:Rebuild /nodeReuse:false /maxcpucount /v:m /p:WarningLevel=0 /p:VisualStudioVersion=14.0 (if not stated)
130+
parameters: "/p:WarningLevel=0"
131+
```
130132
131133
#### If there are several solutions in a module
132-
133-
build:
134-
- name: a.release # You shall name each part
135-
target: a.sln
136-
configuration: release
137-
- name: b.debug
138-
target: b.sln
139-
configuration: debug
134+
```yaml
135+
build:
136+
- name: a.release # You shall name each part
137+
target: a.sln
138+
configuration: release
139+
- name: b.debug
140+
target: b.sln
141+
configuration: debug
142+
```
140143
141144
#### Build with custom script:
142-
143145
build.xproj:
144-
145-
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
146-
<Target Name="Rebuild">
147-
<Exec Command="ping google.com > 1.txt" />
148-
</Target>
149-
</Project>
146+
```xml
147+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
148+
<Target Name="Rebuild">
149+
<Exec Command="ping google.com > 1.txt" />
150+
</Target>
151+
</Project>
152+
```
150153

151154
module.yaml:
152-
153-
full-build:
154-
deps:
155-
build:
156-
target: build.xproj
157-
configuration: Release
155+
```yaml
156+
full-build:
157+
deps:
158+
build:
159+
target: build.xproj
160+
configuration: Release
161+
```
158162
159163
# Git hooks
164+
```yaml
165+
default: # Description in a default configuration
166+
hooks:
167+
- myhooks/pre-push # A way to a hook in a repository
168+
# will be copied to <module_name>/.git/hooks
169+
# A hook inbuilt into pre-commit will check that files containing non-ASCII symbols have UTF-8 with BOM coding
170+
- pre-commit.cement
160171

161-
default: # Description in a default configuration
162-
hooks:
163-
- myhooks/pre-push # A way to a hook in a repository
164-
# will be copied to <module_name>/.git/hooks
165-
# A hook inbuilt into pre-commit will check that files containing non-ASCII symbols have UTF-8 with BOM coding
166-
- pre-commit.cement
167-
168-
full-build *default: # Other module configurations
169-
172+
full-build *default: # Other module configurations
173+
```
170174
171175
If there is a hook in a present branch, then it is not deleted when you switch to another branch.
172176
If you want to use your hook with pre-commit.cement, just add its call-out into your hook
173-
174-
.git/hooks/pre-commit.cement
175-
if [ $? -ne 0 ]; then
176-
exit 1
177-
fi
177+
```sh
178+
.git/hooks/pre-commit.cement
179+
if [ $? -ne 0 ]; then
180+
exit 1
181+
fi
182+
```
183+
184+
# Advanced configuration
185+
#### Excluding specific config from dependency management
186+
In case it is undesirable to have specific configuration being automatically updated with `cm ref add`/`cm ref fix` commands, it is possible to mark such a section with `unmanaged-deps` flag
187+
```yaml
188+
special:
189+
unmanaged-deps: true
190+
deps:
191+
- mylib
192+
```

src/Cement.Cli.Commands/RefFixCommand.cs

+13-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,19 @@ private void Fix(bool fixExternal)
7171

7272
var modules = Helper.GetModules();
7373

74-
var configs = Yaml.ConfigurationParser(rootModuleName).GetConfigurations();
75-
var buildsInfo = configs.SelectMany(config => Yaml.BuildParser(rootModuleName).Get(config));
74+
var configYamlParser = Yaml.ConfigurationParser(rootModuleName);
75+
var configs = configYamlParser.GetConfigurations();
76+
var buildsInfo = new List<BuildData>();
77+
foreach (var config in configs)
78+
{
79+
var props = configYamlParser.GetConfigurationDescription(config);
80+
if (props is {Count: > 0}
81+
&& props.TryGetValue(DepsPatcherProject.SkipConfigurationFlagName, out var v)
82+
&& v is true)
83+
continue;
84+
85+
buildsInfo.AddRange(Yaml.BuildParser(rootModuleName).Get(config));
86+
}
7687
var processedFiles = new HashSet<string>();
7788

7889
foreach (var buildInfo in buildsInfo)

src/Cement.Cli.Common/DepsPatcherProject.cs

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public sealed class DepsPatcherProject
1818
private readonly ConsoleWriter consoleWriter;
1919
private readonly IDepsValidatorFactory depsValidatorFactory;
2020

21+
public const string SkipConfigurationFlagName = "unmanaged-deps";
22+
2123
public DepsPatcherProject(ILogger<DepsPatcherProject> logger, ConsoleWriter consoleWriter,
2224
IDepsValidatorFactory depsValidatorFactory)
2325
{
@@ -122,11 +124,18 @@ private static List<string> GetUsedCementConfigsForProject(string modulePath, st
122124
if (!File.Exists(moduleYaml))
123125
return new List<string>();
124126

127+
var configYamlParser = new ConfigurationYamlParser(new FileInfo(modulePath));
125128
var configurations = new ConfigurationParser(new FileInfo(modulePath)).GetConfigurations();
126129
var result = new HashSet<string>();
127130

128131
foreach (var config in configurations)
129132
{
133+
var props = configYamlParser.GetConfigurationDescription(config);
134+
if (props is {Count: > 0}
135+
&& props.TryGetValue(SkipConfigurationFlagName, out var v)
136+
&& v is true)
137+
continue;
138+
130139
var buildData = new BuildYamlParser(new FileInfo(modulePath)).Get(config);
131140
foreach (var data in buildData)
132141
{

src/Cement.Cli.Common/YamlParsers/ConfigurationYamlParser.cs

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ public IList<string> GetConfigurations()
3535
.ToList();
3636
}
3737

38+
public Dictionary<string, object> GetConfigurationDescription(string configName)
39+
{
40+
return configurationsDescription.TryGetValue(configName, out var result)
41+
? (result as Dictionary<object, object>)?.ToDictionary(k =>(string)k.Key, v => v.Value)
42+
: null;
43+
}
44+
3845
public bool ConfigurationExists(string configName)
3946
{
4047
return configurationsDescription.Keys.Select(GetRealConfigurationName).Contains(configName);

0 commit comments

Comments
 (0)