| 1308 | #------------------------------------------------------------------------------ |
| 1309 | # Macros to automatically take sources from SCM rather than from archives |
| 1310 | |
| 1311 | %__scm_pre_pack\ |
| 1312 | [ -f RPMBUILD_SOURCE ] && mv RPMBUILD_SOURCE RPMBUILD_SOURCE.orig\ |
| 1313 | echo "SCM: %{__source_scm}\ |
| 1314 | URL: %{__source_url}\ |
| 1315 | Rev: %{__source_rev}" >RPMBUILD_SOURCE\ |
| 1316 | %{nil} |
| 1317 | |
| 1318 | # SVN |
| 1319 | |
| 1320 | %__scm_source_svn\ |
| 1321 | Source: %{?main_name}%{!?main_name:%{name}}-svn%{?__source_rev:-r%{__source_rev}}.zip\ |
| 1322 | BuildRequires: subversion zip\ |
| 1323 | %{nil} |
| 1324 | |
| 1325 | %__scm_setup_svn\ |
| 1326 | %if %{?__source_rev:%(sh -c 'if test -f "%SOURCE0" ; then echo 1 ; else echo 0 ; fi')}%{!?__source_rev:0}\ |
| 1327 | %setup -q\ |
| 1328 | %else\ |
| 1329 | %setup -n "%__source_dir" -Tc\ |
| 1330 | svn export %{?__source_rev:-r %{__source_rev}} %{__source_url} . --force\ |
| 1331 | %__scm_pre_pack\ |
| 1332 | %if %{defined __source_rev}\ |
| 1333 | (rm -f "%SOURCE0" && cd .. && zip %{-A:%{-A*}}%{!-A:-rX9} "%SOURCE0" "%__source_dir")\ |
| 1334 | %endif\ |
| 1335 | %endif\ |
| 1336 | %{nil} |
| 1337 | |
| 1338 | # Git |
| 1339 | |
| 1340 | %__scm_source_git\ |
| 1341 | Source: %{?main_name}%{!?main_name:%{name}}-git%{?__source_rev:-%{__source_rev}}.zip\ |
| 1342 | BuildRequires: git zip unzip\ |
| 1343 | %{nil} |
| 1344 | |
| 1345 | %__scm_setup_git\ |
| 1346 | %if %{?__source_rev:%(sh -c 'if test -f "%SOURCE0" ; then echo 1 ; else echo 0 ; fi')}%{!?__source_rev:0}\ |
| 1347 | %setup -q\ |
| 1348 | %else\ |
| 1349 | %setup -n "%__source_dir" -Tc\ |
| 1350 | rm -f "%SOURCE0"\ |
| 1351 | git archive --format zip --output "%SOURCE0" --prefix "%__source_dir/" --remote "%{__source_url}" "%{?__source_rev}"\ |
| 1352 | unzip -qq "%SOURCE0" "%__source_dir"/RPMBUILD_SOURCE -d .. 2>/dev/null || :\ |
| 1353 | %__scm_pre_pack\ |
| 1354 | (cd .. && zip -mX "%SOURCE0" "%__source_dir"/RPMBUILD_SOURCE*)\ |
| 1355 | unzip -qq "%SOURCE0" -d ..\ |
| 1356 | %if %{undefined __source_rev}\ |
| 1357 | rm -f "%SOURCE0"\ |
| 1358 | %endif\ |
| 1359 | %endif |
| 1360 | |
| 1361 | # GitHub |
| 1362 | |
| 1363 | %__scm_source_github\ |
| 1364 | Source: %{?main_name}%{!?main_name:%{name}}-github%{?__source_rev:-%{__source_rev}}.zip\ |
| 1365 | BuildRequires: wget zip unzip\ |
| 1366 | %{nil} |
| 1367 | |
| 1368 | %__scm_setup_github\ |
| 1369 | %{!?__source_rev:%{error:%0: Revision is required for GitHub}}\ |
| 1370 | %global __source_url_github_name %(sh -c 'URL="%{__source_url}" ; echo ${URL##*/}')\ |
| 1371 | %global __source_dir_github %{__source_url_github_name}-%{__source_rev}\ |
| 1372 | %if %{?__source_rev:%(sh -c 'if test -f "%SOURCE0" ; then echo 1 ; else echo 0 ; fi')}%{!?__source_rev:0}\ |
| 1373 | %setup -n "%__source_dir_github" -q\ |
| 1374 | %else\ |
| 1375 | %setup -n "%__source_dir_github" -Tc\ |
| 1376 | rm -f "%SOURCE0"\ |
| 1377 | wget -nv "%{__source_url}/archive/%{__source_rev}.zip" -O "%SOURCE0"\ |
| 1378 | unzip -qq "%SOURCE0" "%__source_dir_github"/RPMBUILD_SOURCE -d .. 2>/dev/null || :\ |
| 1379 | %__scm_pre_pack\ |
| 1380 | (cd .. && zip -mX "%SOURCE0" "%__source_dir_github"/RPMBUILD_SOURCE*)\ |
| 1381 | unzip -qq "%SOURCE0" -d ..\ |
| 1382 | %endif |
| 1383 | |
| 1384 | # User-level macros |
| 1385 | |
| 1386 | %scm_source()\ |
| 1387 | %{?SOURCE0:%{error:%0: Source tag is already set to '%SOURCE0'}}\ |
| 1388 | %{?1:%global __source_scm %1}\ |
| 1389 | %{?2:%global __source_url %2}\ |
| 1390 | %{?3:%global __source_rev %3}\ |
| 1391 | %global __source_dir %{?main_name}%{!?main_name:%{name}}-%{?main_version}%{!?main_version:%{version}}\ |
| 1392 | %{expand:%%{!?__scm_source_%1:%%{error:%0: SCM type '%{?1}' is invalid}}}\ |
| 1393 | %{expand:%%{?__scm_source_%1}}\ |
| 1394 | %{!?__source_url:%{error:%0: URL is required}}\ |
| 1395 | %{nil} |
| 1396 | |
| 1397 | %scm_setup(A:)\ |
| 1398 | %{!?__source_scm:%{error:%0: %%scm_source is required}}\ |
| 1399 | %{expand:%%{?__scm_setup_%{__source_scm}}}\ |
| 1400 | %{nil} |
| 1401 | |